Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | 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");
18
        if(loginStatus != null && loginStatus.equals("TRUE")){
19
            return "show";
20
        }
21
        return INDEX;
22
    }
23
 
24
    public String create()
25
    {
26
        log.info("Logging in!");
27
        password = request.getParameter("password");
28
        username = request.getParameter("username");
29
        if(username == null || username.isEmpty()){
30
            setMessage("Username/Password cannot be empty.");
31
            return "index";
32
        }
33
 
34
        if(password == null || password.isEmpty()){
35
            setMessage("Username/Password cannot be empty.");
36
            return "index";
37
        }
38
 
39
        try {
40
            HelperClient hcl = new HelperClient(); 
41
            ReportUser user = hcl.getClient().authenticateReportUser(username, password);
42
            if (user.getRole() == -1) {
43
                request.getSession().setAttribute("LOGGED_IN", "TRUE");
44
            } else {
45
                message = "Invalid Username/Password. Please try again";
46
                return "index";
47
            }
48
        } catch (HelperServiceException e) {
49
            log.error("Invalid user", e);
50
            message = "Invalid Username/Password. Please try again";
51
            return "index";
52
        } catch (Exception e) {
53
            log.error("Problem in helper service", e);
54
            message = "Internal error. Please try again or contact Engineering team";
55
            return "index";
56
        }
57
        return "show";
58
    }
59
 
60
    public String doLogout()
61
    {
62
        log.info("Logging out!");
63
        request.getSession().setAttribute("LOGGED_IN", null);
64
        try {
65
            request.getSession().invalidate();
66
        } catch(IllegalStateException e) {
67
            log.error("Session is already invalidated", e);
68
        }
69
        return "index";
70
    }
71
 
72
    public String getPassword() {
73
        return password;
74
    }
75
 
76
    public void setPassword(String password) {
77
        this.password = password;
78
    }
79
 
80
    public void setMessage(String message) {
81
        this.message = message;
82
    }
83
 
84
    public String getMessage() {
85
        return message;
86
    }
87
 
88
    public void setHash(String hash) {
89
        this.hash = hash;
90
    }
91
 
92
    public String getHash() {
93
        return hash;
94
    }
95
}