Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
7264 anupam.sin 1
package in.shop2020.recharge.controllers;
2
 
3
import in.shop2020.thrift.clients.HelperClient;
4
import in.shop2020.utils.HelperServiceException;
5
import in.shop2020.utils.ReportUser;
6
 
7
public class AdminController extends BaseController {
8
    private static final long serialVersionUID = 1L;
9
 
10
    private String password; 
11
    private String username;
12
    private String message = "";
13
    private String hash;
14
 
15
    public String index()
16
    {
17
        String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
7370 anupam.sin 18
        String role = (String) request.getSession().getAttribute("ROLE");
19
        if(loginStatus != null && role != null && loginStatus.equals("TRUE") && role.equals("ADMIN")){
7264 anupam.sin 20
            return "show";
21
        }
22
        return INDEX;
23
    }
24
 
25
    public String create()
26
    {
27
        log.info("Logging in!");
28
        password = request.getParameter("password");
29
        username = request.getParameter("username");
30
        if(username == null || username.isEmpty()){
31
            setMessage("Username/Password cannot be empty.");
32
            return "index";
33
        }
34
 
35
        if(password == null || password.isEmpty()){
36
            setMessage("Username/Password cannot be empty.");
37
            return "index";
38
        }
39
 
40
        try {
41
            HelperClient hcl = new HelperClient(); 
42
            ReportUser user = hcl.getClient().authenticateReportUser(username, password);
43
            if (user.getRole() == -1) {
44
                request.getSession().setAttribute("LOGGED_IN", "TRUE");
7370 anupam.sin 45
                request.getSession().setAttribute("ROLE", "ADMIN");
7264 anupam.sin 46
            } else {
47
                message = "Invalid Username/Password. Please try again";
48
                return "index";
49
            }
50
        } catch (HelperServiceException e) {
51
            log.error("Invalid user", e);
52
            message = "Invalid Username/Password. Please try again";
53
            return "index";
54
        } catch (Exception e) {
55
            log.error("Problem in helper service", e);
56
            message = "Internal error. Please try again or contact Engineering team";
57
            return "index";
58
        }
59
        return "show";
60
    }
61
 
62
    public String doLogout()
63
    {
64
        log.info("Logging out!");
65
        request.getSession().setAttribute("LOGGED_IN", null);
66
        try {
67
            request.getSession().invalidate();
68
        } catch(IllegalStateException e) {
69
            log.error("Session is already invalidated", e);
70
        }
71
        return "index";
72
    }
73
 
74
    public String getPassword() {
75
        return password;
76
    }
77
 
78
    public void setPassword(String password) {
79
        this.password = password;
80
    }
81
 
82
    public void setMessage(String message) {
83
        this.message = message;
84
    }
85
 
86
    public String getMessage() {
87
        return message;
88
    }
89
 
90
    public void setHash(String hash) {
91
        this.hash = hash;
92
    }
93
 
94
    public String getHash() {
95
        return hash;
96
    }
97
}