Subversion Repositories SmartDukaan

Rev

Rev 7068 | Rev 7113 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7068 anupam.sin 1
/**
2
 * 
3
 */
4
package in.shop2020.recharge.controllers;
5
 
7096 anupam.sin 6
import in.shop2020.model.v1.order.HotspotStore;
7
import in.shop2020.thrift.clients.TransactionClient;
7068 anupam.sin 8
 
7096 anupam.sin 9
import org.apache.struts2.convention.annotation.Action;
7068 anupam.sin 10
import org.apache.struts2.convention.annotation.Result;
7096 anupam.sin 11
import org.apache.struts2.convention.annotation.Results;
7068 anupam.sin 12
import org.apache.thrift.TException;
7096 anupam.sin 13
import org.apache.thrift.transport.TTransportException;
7068 anupam.sin 14
 
7096 anupam.sin 15
@Results({
16
    @Result(name = "redirect", location = "${redirectUrl}", type = "redirect")
17
})
18
 
7068 anupam.sin 19
public class LoginController extends BaseController {
20
    private static final long serialVersionUID = 1L;
21
 
7096 anupam.sin 22
    private String storeIdString;
23
    private Long storeId;
24
    private String redirectUrl;
7068 anupam.sin 25
    private String password; 
7096 anupam.sin 26
    private String message = "";
27
    private String hash;
7068 anupam.sin 28
 
7096 anupam.sin 29
    private long circleId;
30
 
31
    @Action("/")
32
    public String index()
7068 anupam.sin 33
    {
7096 anupam.sin 34
        String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
35
        if(loginStatus != null && loginStatus.equals("TRUE")){
36
            redirectUrl = "/home";
37
            return "redirect";
38
        }
39
        storeIdString = (String) request.getSession().getAttribute("STORE_ID");
40
        if(storeIdString == null || storeIdString.isEmpty()){
41
            storeIdString = request.getParameter("storeid");
42
            if(storeIdString == null){
43
                return "authfail";
44
            }else{
45
                try {
46
                    TransactionClient tcl = new TransactionClient(); 
47
                    HotspotStore hotSpotStore = tcl.getClient().getHotspotStore(0, storeIdString);
48
                    if(!request.getParameter("hash").equals(hotSpotStore.getSalt())) {
49
                        return "authfail";
50
                    }
51
                    storeId = hotSpotStore.getId();
52
                    setHash(hotSpotStore.getSalt());
53
                    circleId = hotSpotStore.getCircleId();
54
                } catch (TTransportException e) {
55
                    e.printStackTrace();
56
                    return "authfail";
57
                } catch (TException e) {
58
                    e.printStackTrace();
59
                    return "authfail";
60
                }
61
                request.getSession().setAttribute("STORE_ID", "" + storeId);
62
                request.getSession().setAttribute("HASH", hash);
63
                request.getSession().setAttribute("CIRCLE_ID", "" + circleId);
64
            }
65
        } else {
66
            storeId = Long.parseLong(storeIdString);
67
        }
7068 anupam.sin 68
 
69
        return INDEX;
70
    }
71
 
7096 anupam.sin 72
    public String doLogin()
7068 anupam.sin 73
    {
7096 anupam.sin 74
        log.info("Logging in!");
75
        password = request.getParameter("password");
76
        storeIdString = (String) request.getSession().getAttribute("STORE_ID");
77
        if(storeIdString == null || storeIdString.isEmpty()){
78
            return "authfail";
79
        }
80
        try {
81
            TransactionClient tcl = new TransactionClient(); 
82
            HotspotStore hotSpotStore = tcl.getClient().getHotspotStore(Long.parseLong(storeIdString), "");
83
            hash = (String) request.getSession().getAttribute("HASH");
84
            if(hash == null || !hash.equals(hotSpotStore.getSalt())) {
85
                return "authfail";
86
            }
87
            if(!hotSpotStore.getPassword().equals(password)){
88
                setMessage("Wrong Password. Try Again.");
89
                return INDEX;    
90
            }
91
        } catch (TTransportException e) {
92
            e.printStackTrace();
93
            return "authfail";
94
        } catch (TException e) {
95
            e.printStackTrace();
96
            return "authfail";
97
        }
98
        request.getSession().setAttribute("LOGGED_IN", "TRUE");
99
        redirectUrl = "/home";
100
        return "redirect";
101
    }
102
 
103
    public String doLogout()
104
    {
7068 anupam.sin 105
        log.info("Logging out!");
7096 anupam.sin 106
        request.getSession().setAttribute("LOGGED_IN", null);
107
        return INDEX;
7068 anupam.sin 108
    }
109
 
110
    public String getPassword() {
111
        return password;
112
    }
113
 
114
    public void setPassword(String password) {
115
        this.password = password;
116
    }
117
 
7096 anupam.sin 118
    public void setRedirectUrl(String redirectUrl) {
119
        this.redirectUrl = redirectUrl;
7068 anupam.sin 120
    }
7096 anupam.sin 121
 
122
    public String getRedirectUrl() {
123
        return redirectUrl;
124
    }
125
 
126
    public void setMessage(String message) {
127
        this.message = message;
128
    }
129
 
130
    public String getMessage() {
131
        return message;
132
    }
133
 
134
    public void setHash(String hash) {
135
        this.hash = hash;
136
    }
137
 
138
    public String getHash() {
139
        return hash;
140
    }
7068 anupam.sin 141
}