| Line 11... |
Line 11... |
| 11 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
11 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
| 12 |
import org.apache.struts2.rest.HttpHeaders;
|
12 |
import org.apache.struts2.rest.HttpHeaders;
|
| 13 |
import org.apache.thrift.TException;
|
13 |
import org.apache.thrift.TException;
|
| 14 |
|
14 |
|
| 15 |
import in.shop2020.model.v1.user.AuthenticationException;
|
15 |
import in.shop2020.model.v1.user.AuthenticationException;
|
| - |
|
16 |
import in.shop2020.model.v1.user.User;
|
| 16 |
import in.shop2020.model.v1.user.UserContextException;
|
17 |
import in.shop2020.model.v1.user.UserContextException;
|
| 17 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
18 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
| 18 |
import in.shop2020.serving.utils.Utils;
|
19 |
import in.shop2020.serving.utils.Utils;
|
| 19 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
20 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
| 20 |
|
21 |
|
| Line 57... |
Line 58... |
| 57 |
|
58 |
|
| 58 |
// POST /auth
|
59 |
// POST /auth
|
| 59 |
public HttpHeaders create(){
|
60 |
public HttpHeaders create(){
|
| 60 |
log.info(auth);
|
61 |
log.info(auth);
|
| 61 |
Client c = client.getClient();
|
62 |
Client c = client.getClient();
|
| - |
|
63 |
String userEmail = auth.getUserName();
|
| - |
|
64 |
String password = auth.getPassword();
|
| 62 |
try {
|
65 |
try {
|
| 63 |
if (c.authenticateUser(auth.getUserName(), auth.getPassword(), true)){
|
66 |
User user = c.authenticateUser(userEmail, password);
|
| - |
|
67 |
if (user != null){
|
| 64 |
long userId = c.getContext(auth.getUserName(), auth.getPassword()).getId();
|
68 |
long userId = user.getUserId();
|
| 65 |
c.setUserAsLoggedIn(userId, (new Date()).getTime());
|
69 |
c.setUserAsLoggedIn(userId, (new Date()).getTime());
|
| 66 |
|
70 |
|
| 67 |
userinfo.setUserId(userId);
|
71 |
userinfo.setUserId(userId);
|
| 68 |
userinfo.setLoggedIn(true);
|
72 |
userinfo.setLoggedIn(true);
|
| 69 |
userinfo.setEmail(auth.getUserName());
|
73 |
userinfo.setEmail(userEmail);
|
| 70 |
userinfo.setNameOfUser(Utils.getNameOfUser(userId));
|
74 |
userinfo.setNameOfUser(user.getName());
|
| 71 |
this.nameOfUser = Utils.getNameOfUser(userId);
|
75 |
this.nameOfUser = user.getName();
|
| 72 |
if(userinfo.getCartId() == -1){
|
- |
|
| 73 |
userinfo.setCartId(Utils.getCartId(userId));
|
- |
|
| 74 |
userinfo.setTotalItems(Utils.getNumberOfItemsInCart(userinfo.getCartId()));
|
- |
|
| 75 |
}else{
|
- |
|
| 76 |
Utils.mergeCarts(userinfo.getCartId(), Utils.getCartId(userId));
|
76 |
c.mergeCart(userinfo.getCartId(), user.getActiveCartId());
|
| 77 |
userinfo.setCartId(Utils.getCartId(userId));
|
77 |
userinfo.setCartId(user.getActiveCartId());
|
| 78 |
userinfo.setTotalItems(Utils.getNumberOfItemsInCart(userinfo.getCartId()));
|
78 |
userinfo.setTotalItems(Utils.getNumberOfItemsInCart(userinfo.getCartId()));
|
| 79 |
}
|
79 |
|
| 80 |
this.session.setAttribute("userinfo", userinfo);
|
80 |
this.session.setAttribute("userinfo", userinfo);
|
| 81 |
|
81 |
|
| 82 |
Cookie cookie1 = new Cookie("userid", userId+"");
|
82 |
Cookie cookie1 = new Cookie("userid", userId+"");
|
| 83 |
this.response.addCookie(cookie1);
|
83 |
this.response.addCookie(cookie1);
|
| 84 |
return new DefaultHttpHeaders("lsuccess");
|
84 |
return new DefaultHttpHeaders("lsuccess");
|
| 85 |
}
|
85 |
}
|
| 86 |
} catch (AuthenticationException e) {
|
86 |
} catch (AuthenticationException e) {
|
| 87 |
|
87 |
|
| 88 |
errorCode = e.getErrorCode();
|
88 |
errorCode = e.getErrorCode();
|