| 167 |
ashish |
1 |
package in.shop2020.hotspot.dashbaord.server.handler;
|
|
|
2 |
|
| 493 |
rajveer |
3 |
import org.apache.thrift.TException;
|
|
|
4 |
|
| 167 |
ashish |
5 |
import in.shop2020.hotspot.dashbaord.shared.actions.AuthRequest;
|
|
|
6 |
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse;
|
| 345 |
ashish |
7 |
import in.shop2020.hotspot.dashbaord.shared.actions.AuthResponse.NEXT;
|
| 493 |
rajveer |
8 |
import in.shop2020.thrift.clients.HelperServiceClient;
|
|
|
9 |
import in.shop2020.utils.HelperService.Client;
|
|
|
10 |
import in.shop2020.utils.HelperServiceException;
|
| 167 |
ashish |
11 |
import net.customware.gwt.dispatch.server.ActionHandler;
|
|
|
12 |
import net.customware.gwt.dispatch.server.ExecutionContext;
|
|
|
13 |
import net.customware.gwt.dispatch.shared.ActionException;
|
|
|
14 |
|
|
|
15 |
public class AuthHandler implements ActionHandler<AuthRequest, AuthResponse>{
|
|
|
16 |
|
|
|
17 |
@Override
|
|
|
18 |
public AuthResponse execute(AuthRequest request, ExecutionContext response)
|
|
|
19 |
throws ActionException {
|
|
|
20 |
String userName = request.getUsername();
|
| 493 |
rajveer |
21 |
String password = request.getPassword();
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
HelperServiceClient hsc = null;
|
|
|
26 |
Client client = null;
|
|
|
27 |
|
|
|
28 |
try {
|
|
|
29 |
hsc = new HelperServiceClient();
|
|
|
30 |
client = hsc.getClient();
|
|
|
31 |
// client.addUser(userName, password, 1);
|
|
|
32 |
} catch (Exception e) {
|
|
|
33 |
e.printStackTrace();
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
try {
|
|
|
37 |
long warehouseId = client.authenticateUser(userName, password);
|
|
|
38 |
if(warehouseId != -1){
|
|
|
39 |
return new AuthResponse(userName, true, " You are charming, loving and affectionate", NEXT.INBOX, warehouseId);
|
|
|
40 |
}
|
|
|
41 |
} catch (HelperServiceException e) {
|
|
|
42 |
// TODO Auto-generated catch block
|
|
|
43 |
e.printStackTrace();
|
|
|
44 |
} catch (TException e) {
|
|
|
45 |
// TODO Auto-generated catch block
|
|
|
46 |
e.printStackTrace();
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/*
|
| 167 |
ashish |
50 |
if (userName.trim().toUpperCase().equals("SHOP2020")){
|
| 493 |
rajveer |
51 |
return new AuthResponse(userName, true, " You are charming, loving and affectionate", NEXT.INBOX, 1);
|
| 167 |
ashish |
52 |
}
|
| 345 |
ashish |
53 |
|
| 493 |
rajveer |
54 |
if(getThreadLocalRequest().getSession(true) == null){
|
|
|
55 |
getThreadLocalRequest().getSession(true);
|
|
|
56 |
}
|
|
|
57 |
HttpSession httpSession = getThreadLocalRequest().getSession(true);
|
|
|
58 |
httpSession.setAttribute("userName", userName);
|
|
|
59 |
httpSession.setAttribute("warehouseId", "1");
|
|
|
60 |
|
|
|
61 |
HttpSession session = getThreadLocalRequest().getSession(true);
|
|
|
62 |
String warehouseId = null;
|
|
|
63 |
if(session.getAttribute("warehouseId") !=null){
|
|
|
64 |
warehouseId = session.getAttribute("warehouseId").toString();
|
|
|
65 |
}
|
|
|
66 |
else{
|
|
|
67 |
warehouseId = "Default";
|
|
|
68 |
}
|
|
|
69 |
*/
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
| 345 |
ashish |
75 |
if (userName.trim().toUpperCase().equals("ADMIN")){
|
| 493 |
rajveer |
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
return new AuthResponse(userName, true, " You are charming, loving and affectionate", NEXT.ADMIN, -1);
|
| 345 |
ashish |
81 |
}
|
| 167 |
ashish |
82 |
else
|
| 493 |
rajveer |
83 |
return new AuthResponse(userName, false, "None", NEXT.INBOX, -1);
|
| 167 |
ashish |
84 |
}
|
|
|
85 |
|
|
|
86 |
@Override
|
|
|
87 |
public Class<AuthRequest> getActionType() {
|
|
|
88 |
|
|
|
89 |
return AuthRequest.class;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
@Override
|
|
|
93 |
public void rollback(AuthRequest arg0, AuthResponse arg1,
|
|
|
94 |
ExecutionContext arg2) throws ActionException {
|
|
|
95 |
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
}
|