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