Subversion Repositories SmartDukaan

Rev

Rev 1081 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1051 rajveer 1
/**
2
 * 
3
 */
4
package in.shop2020.creation.controllers;
7286 amit.gupta 5
import in.shop2020.content.security.Role;
1051 rajveer 6
import in.shop2020.content.security.UserManager;
7286 amit.gupta 7
 
1051 rajveer 8
import java.io.IOException;
7286 amit.gupta 9
import java.util.ArrayList;
10
import java.util.Arrays;
1051 rajveer 11
 
12
import org.apache.struts2.convention.annotation.Result;
13
 
14
/**
15
 * 
16
 * @author rajveer
17
 * 
18
 */
19
 
7286 amit.gupta 20
@Result(name="success", type="redirectAction", params = {"actionName" , "${url}"})
1051 rajveer 21
 
22
 
23
public class LoginController extends BaseController {
24
 
25
	/**
26
	 * 
27
	 */
28
	private static final long serialVersionUID = 5390035354379263121L;
7286 amit.gupta 29
	private String url = "";
1051 rajveer 30
 
31
 
32
 
33
	public String index() throws SecurityException, IOException {
34
		return "index";
35
	}
36
 
37
	public String create() throws SecurityException, Exception {
38
		if (loginUser()) {
7286 amit.gupta 39
			Role r = UserManager.getUserManager().getUserRole(getUsername());
40
			if(new ArrayList<Role>(Arrays.asList(Role.ADMIN,Role.DEVELOPER, Role.EDITOR)).contains(r)) {
41
				this.url = "entity";
42
			}else {
43
				this.url = "expert-review";
44
			}
1051 rajveer 45
			return "success";
46
		} else {
47
			addActionError("Wrong username or password.");
48
			return "index";
49
		}
50
	}
51
 
52
	private boolean loginUser() {
53
		try{
54
			String username = this.reqparams.get("username")[0];
55
			String password = this.reqparams.get("password")[0];
56
			if(UserManager.getUserManager().authenticateUser(username, password)){
57
				setUserAsLogin(username);
58
				return true;
59
			}
60
		}catch(Exception exp){
61
 
62
		}
63
		return false;
64
	}
7286 amit.gupta 65
 
66
	public String getUrl(){
67
		return this.url;
68
	}
1051 rajveer 69
 
70
}