| 507 |
rajveer |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
| 555 |
chandransh |
6 |
import in.shop2020.model.v1.user.User;
|
| 507 |
rajveer |
7 |
import in.shop2020.serving.utils.Utils;
|
|
|
8 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
9 |
|
|
|
10 |
import java.io.UnsupportedEncodingException;
|
|
|
11 |
import java.util.HashMap;
|
|
|
12 |
import java.util.Map;
|
|
|
13 |
|
|
|
14 |
import org.apache.juli.logging.Log;
|
|
|
15 |
import org.apache.juli.logging.LogFactory;
|
|
|
16 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
17 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* @author rajveer
|
|
|
21 |
*
|
|
|
22 |
*/
|
|
|
23 |
|
| 595 |
rajveer |
24 |
@Results({
|
|
|
25 |
@Result(name="success", type="redirectAction",
|
| 650 |
rajveer |
26 |
params = {"actionName" , "personal-details"}),
|
|
|
27 |
@Result(name="redirect", type="redirectAction",
|
|
|
28 |
params = {"actionName" , "login"})
|
|
|
29 |
|
| 595 |
rajveer |
30 |
})
|
| 507 |
rajveer |
31 |
|
| 595 |
rajveer |
32 |
public class PersonalDetailsController extends BaseController {
|
|
|
33 |
|
| 507 |
rajveer |
34 |
|
| 650 |
rajveer |
35 |
private static final long serialVersionUID = 1L;
|
|
|
36 |
|
| 517 |
rajveer |
37 |
private static Log log = LogFactory.getLog(PersonalDetailsController.class);
|
| 507 |
rajveer |
38 |
|
| 595 |
rajveer |
39 |
private Map<String,String> velocityParams = new HashMap<String, String>();
|
| 507 |
rajveer |
40 |
|
| 517 |
rajveer |
41 |
public PersonalDetailsController() {
|
| 507 |
rajveer |
42 |
super();
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
// POST /logindetails
|
|
|
46 |
public String create() {
|
|
|
47 |
log.info("PersonaldetailsController.create");
|
|
|
48 |
|
|
|
49 |
if(this.userinfo.isLoggedIn()){
|
| 595 |
rajveer |
50 |
String name = this.request.getParameter("txtName");
|
| 620 |
rajveer |
51 |
String dateOfBirth = this.request.getParameter("txtDateOfBirth");
|
| 595 |
rajveer |
52 |
String sex = this.request.getParameter("sex");
|
|
|
53 |
String communicationEmail = this.request.getParameter("txtCommEmail");
|
|
|
54 |
String subscribeNewsletter = this.request.getParameter("subscribe");
|
|
|
55 |
String phone = this.request.getParameter("txtPhone");
|
|
|
56 |
|
|
|
57 |
if(Utils.UpdatePersonalDetails(userinfo.getUserId(), name, phone, dateOfBirth, sex,communicationEmail,subscribeNewsletter))
|
|
|
58 |
{
|
|
|
59 |
addActionMessage("Your personal details updated");
|
| 507 |
rajveer |
60 |
return "success";
|
|
|
61 |
}
|
|
|
62 |
}
|
| 595 |
rajveer |
63 |
addActionError("Unable to update your personal details");
|
|
|
64 |
return "success";
|
| 507 |
rajveer |
65 |
}
|
|
|
66 |
|
|
|
67 |
|
| 595 |
rajveer |
68 |
public String index() throws UnsupportedEncodingException {
|
| 507 |
rajveer |
69 |
log.info("this.request=" + this.request);
|
|
|
70 |
|
|
|
71 |
if(this.userinfo.isLoggedIn()){
|
| 595 |
rajveer |
72 |
htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
|
|
|
73 |
htmlSnippets.put("PERSONAL_DETAILS", pageLoader.getPersonalDetailsHtml(userinfo.getUserId()));
|
| 650 |
rajveer |
74 |
return "index";
|
| 507 |
rajveer |
75 |
}else{
|
| 650 |
rajveer |
76 |
return "redirect";
|
| 507 |
rajveer |
77 |
}
|
|
|
78 |
|
|
|
79 |
}
|
|
|
80 |
|
| 595 |
rajveer |
81 |
|
|
|
82 |
public Map<String, String> getVelocityParams(){
|
|
|
83 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
84 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
85 |
try{
|
|
|
86 |
User user = null;
|
|
|
87 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
88 |
userClient = userContextServiceClient.getClient();
|
|
|
89 |
user = userClient.getUserById(userinfo.getUserId());
|
|
|
90 |
|
|
|
91 |
velocityParams.put("email", user.getCommunicationEmail());
|
|
|
92 |
velocityParams.put("sex", user.getSex().getValue()+"");
|
|
|
93 |
velocityParams.put("name", user.getName());
|
|
|
94 |
velocityParams.put("phone", user.getMobileNumber());
|
|
|
95 |
velocityParams.put("dateOfBirth", user.getDateOfBirth());
|
|
|
96 |
}catch (Exception e){
|
|
|
97 |
e.printStackTrace();
|
|
|
98 |
}
|
|
|
99 |
return velocityParams;
|
|
|
100 |
}
|
|
|
101 |
|
| 650 |
rajveer |
102 |
public String getMyaccountHeaderSnippet(){
|
| 507 |
rajveer |
103 |
return htmlSnippets.get("MYACCOUNT_HEADER");
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
public String getPersonalDetailsSnippet(){
|
|
|
107 |
return htmlSnippets.get("PERSONAL_DETAILS");
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
}
|