| 507 |
rajveer |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
| 762 |
rajveer |
5 |
import in.shop2020.model.v1.user.UserContextException;
|
| 915 |
chandransh |
6 |
import in.shop2020.serving.utils.DesEncrypter;
|
| 3126 |
rajveer |
7 |
import in.shop2020.thrift.clients.UserClient;
|
| 507 |
rajveer |
8 |
|
|
|
9 |
import java.io.UnsupportedEncodingException;
|
|
|
10 |
|
| 832 |
rajveer |
11 |
import org.apache.log4j.Logger;
|
| 822 |
vikas |
12 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
13 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
| 507 |
rajveer |
14 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
15 |
import org.apache.struts2.convention.annotation.Results;
|
| 762 |
rajveer |
16 |
import org.apache.thrift.TException;
|
| 507 |
rajveer |
17 |
|
|
|
18 |
/**
|
|
|
19 |
* @author rajveer
|
|
|
20 |
*
|
|
|
21 |
*/
|
|
|
22 |
|
| 822 |
vikas |
23 |
@InterceptorRefs({
|
|
|
24 |
@InterceptorRef("myDefault"),
|
|
|
25 |
@InterceptorRef("login")
|
|
|
26 |
})
|
|
|
27 |
|
| 595 |
rajveer |
28 |
@Results({
|
|
|
29 |
@Result(name="success", type="redirectAction",
|
| 822 |
vikas |
30 |
params = {"actionName" , "login-details"})
|
| 595 |
rajveer |
31 |
})
|
| 650 |
rajveer |
32 |
public class LoginDetailsController extends BaseController {
|
| 507 |
rajveer |
33 |
|
| 595 |
rajveer |
34 |
private static final long serialVersionUID = 1L;
|
|
|
35 |
|
| 915 |
chandransh |
36 |
private static Logger log = Logger.getLogger(Class.class);
|
|
|
37 |
private DesEncrypter desEncrypter = new DesEncrypter("saholic");
|
| 507 |
rajveer |
38 |
|
| 517 |
rajveer |
39 |
public LoginDetailsController() {
|
| 507 |
rajveer |
40 |
super();
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
// POST /logindetails
|
|
|
44 |
public String create() {
|
|
|
45 |
log.info("LogindetailsController.create");
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
String email = this.request.getParameter("txtLoginID");
|
|
|
49 |
String oldPassword = this.request.getParameter("txtOldPassword");
|
|
|
50 |
String newPassword = this.request.getParameter("txtNewPassword");
|
|
|
51 |
|
|
|
52 |
if(this.userinfo.isLoggedIn()){
|
| 915 |
chandransh |
53 |
if(changePassword(userinfo.getUserId(), email, desEncrypter.encrypt(oldPassword), desEncrypter.encrypt(newPassword)))
|
| 507 |
rajveer |
54 |
{
|
| 595 |
rajveer |
55 |
addActionMessage("Your password is updated successfully.");
|
| 507 |
rajveer |
56 |
return "success";
|
|
|
57 |
}
|
|
|
58 |
}
|
| 595 |
rajveer |
59 |
addActionError("Unable to update password. Either email or password is not correct.");
|
|
|
60 |
return "success";
|
| 507 |
rajveer |
61 |
}
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
// GET /test
|
| 650 |
rajveer |
65 |
public String index() throws UnsupportedEncodingException {
|
| 507 |
rajveer |
66 |
log.info("this.request=" + this.request);
|
|
|
67 |
|
| 822 |
vikas |
68 |
htmlSnippets.put("MYACCOUNT_HEADER",
|
|
|
69 |
pageLoader.getMyaccountHeaderHtml());
|
|
|
70 |
htmlSnippets.put("LOGIN_DETAILS",
|
|
|
71 |
pageLoader.getLoginDetailsHtml(userinfo.getUserId()));
|
|
|
72 |
return "index";
|
| 507 |
rajveer |
73 |
}
|
|
|
74 |
|
| 762 |
rajveer |
75 |
|
|
|
76 |
public boolean changePassword(long userId, String email, String oldPassword, String newPassword) {
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
try {
|
| 3126 |
rajveer |
80 |
UserClient userContextServiceClient = new UserClient();
|
| 762 |
rajveer |
81 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
82 |
|
|
|
83 |
return userClient.updatePassword(userId,oldPassword, newPassword);
|
|
|
84 |
} catch (UserContextException e) {
|
| 2949 |
chandransh |
85 |
log.error("Unable to update password", e);
|
| 762 |
rajveer |
86 |
} catch (TException e) {
|
| 2949 |
chandransh |
87 |
log.error("Unable to update password", e);
|
| 762 |
rajveer |
88 |
} catch (Exception e) {
|
| 2949 |
chandransh |
89 |
log.error("Unable to update password", e);
|
| 762 |
rajveer |
90 |
}
|
|
|
91 |
return false;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
| 507 |
rajveer |
96 |
public String getMyaccountHeaderSnippet(){
|
|
|
97 |
return htmlSnippets.get("MYACCOUNT_HEADER");
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
public String getLoginDetailsSnippet(){
|
|
|
101 |
return htmlSnippets.get("LOGIN_DETAILS");
|
|
|
102 |
}
|
|
|
103 |
|
| 650 |
rajveer |
104 |
public String getEmail(){
|
| 595 |
rajveer |
105 |
return userinfo.getEmail();
|
| 507 |
rajveer |
106 |
}
|
|
|
107 |
|
|
|
108 |
}
|