Repository navigation
Expand file tree
/
Copy pathHelperControls.java
More file actions
67 lines (51 loc) · 1.83 KB
/
Copy pathHelperControls.java
File metadata and controls
67 lines (51 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.fas.helper;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.web.servlet.ModelAndView;
import com.fas.controller.LoginController;
import com.fas.modal.Users;
import com.fas.service.IUserService;
import com.fas.validator.LoginValidator;
public class HelperControls {
/**************************LOGIN CONTROLLER HELPER METHODS***************************************/
private final Logger LOG = LoggerFactory.getLogger(HelperControls.class);
/**
* authenticate user and show appropriate message where required
*/
public Users validateUser(IUserService userService,Users user, BindingResult result,
ModelAndView modelView, Map<String, String> message) {
LoginValidator validator=new LoginValidator();
validator.validate(user, result);
user=userService.authenticateUser(user);
modelView.setViewName("login");
if (result.hasErrors()) {
message.put("ERR_MESSAGE", "ErrorMessage");
}else if(!user.isValidUser()){
message.put("INVALID_USER_MESSAGE","INVALID_USER_MESSAGE");
}else if(user.isValidUser()){
/*
* this view will only be set if user is been authenticated
*/
modelView.setViewName("home");
}
return user;
}
/**
* Check that has user logged in , if true it will return home page else will redirect to login page
* @param user
* @return
*/
public ModelAndView IsUserRevisited(Users user) {
if(user == null) {user = new Users();}
// LOG.info("helper app ::::::::::::::::::::::::::"+user.getId());
if(user.getId()>0)
{
return new ModelAndView("home");
}else{
return new ModelAndView("login", "users", new Users());
}
}
/**************************EOF LOGIN CONTROLLER HELPER METHODS***************************************/
}