| 507 |
rajveer |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
|
|
6 |
|
| 2263 |
vikas |
7 |
import in.shop2020.datalogger.EventType;
|
| 555 |
chandransh |
8 |
import in.shop2020.model.v1.user.Sex;
|
|
|
9 |
import in.shop2020.model.v1.user.User;
|
| 1868 |
vikas |
10 |
import in.shop2020.serving.interceptors.TrackingInterceptor;
|
| 815 |
rajveer |
11 |
import in.shop2020.serving.utils.DesEncrypter;
|
| 3126 |
rajveer |
12 |
import in.shop2020.thrift.clients.UserClient;
|
| 2511 |
vikas |
13 |
import in.shop2020.utils.DataLogger;
|
| 507 |
rajveer |
14 |
|
|
|
15 |
import java.io.IOException;
|
|
|
16 |
import java.util.Date;
|
| 1623 |
rajveer |
17 |
import java.util.List;
|
| 507 |
rajveer |
18 |
|
| 2021 |
vikas |
19 |
import javax.servlet.http.Cookie;
|
|
|
20 |
|
| 832 |
rajveer |
21 |
import org.apache.log4j.Logger;
|
| 507 |
rajveer |
22 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
23 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
*
|
|
|
27 |
* @author rajveer
|
|
|
28 |
*
|
|
|
29 |
*/
|
|
|
30 |
|
| 550 |
rajveer |
31 |
@Results({
|
| 1776 |
varun.gupt |
32 |
@Result(name = "success", type = "redirectAction", params = {"actionName" , "home"}),
|
| 1904 |
varun.gupt |
33 |
@Result(name = "failure", type = "redirectAction", params = {"actionName" , "login"}),
|
|
|
34 |
@Result(name = "redirect-to-login", type = "redirectAction", params = {"actionName" , "login"}),
|
| 1776 |
varun.gupt |
35 |
@Result(name = "redirect", location = "${redirectUrl}", type = "redirect")
|
| 550 |
rajveer |
36 |
})
|
| 507 |
rajveer |
37 |
public class RegisterController extends BaseController{
|
| 1904 |
varun.gupt |
38 |
|
| 650 |
rajveer |
39 |
private static final long serialVersionUID = 1L;
|
| 832 |
rajveer |
40 |
private static Logger log = Logger.getLogger(Class.class);
|
| 815 |
rajveer |
41 |
private DesEncrypter desEncrypter = new DesEncrypter("saholic");
|
| 507 |
rajveer |
42 |
|
| 1776 |
varun.gupt |
43 |
private String redirectUrl = null;
|
|
|
44 |
|
| 507 |
rajveer |
45 |
public RegisterController(){
|
|
|
46 |
super();
|
|
|
47 |
}
|
|
|
48 |
|
| 650 |
rajveer |
49 |
public String index() throws SecurityException, IOException {
|
| 925 |
rajveer |
50 |
if(userinfo.isLoggedIn()){
|
|
|
51 |
return "success";
|
|
|
52 |
}
|
| 1904 |
varun.gupt |
53 |
// htmlSnippets.put("REGISTRATION_HEADER",pageLoader.getRegistrationHeaderHtml());
|
|
|
54 |
// htmlSnippets.put("REGISTRATION_FORM",pageLoader.getRegistrationFormHtml());
|
|
|
55 |
return "redirect-to-login";
|
| 507 |
rajveer |
56 |
}
|
|
|
57 |
|
|
|
58 |
public String create() throws SecurityException, Exception {
|
|
|
59 |
|
|
|
60 |
if(registerUser())
|
| 1776 |
varun.gupt |
61 |
return "redirect";
|
| 507 |
rajveer |
62 |
else
|
|
|
63 |
return "failure";
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public boolean registerUser() throws Exception{
|
| 569 |
rajveer |
67 |
String email, password, userName, mobileNumber, communicationEmail, sex, dateOfBirth;
|
| 741 |
rajveer |
68 |
boolean isValid = true;
|
| 555 |
chandransh |
69 |
userName = this.request.getParameter("nameOfUser");
|
| 507 |
rajveer |
70 |
email = this.request.getParameter("email");
|
| 762 |
rajveer |
71 |
password = this.request.getParameter("txtPassword");
|
| 550 |
rajveer |
72 |
|
|
|
73 |
mobileNumber = this.request.getParameter("mobileNumber");
|
|
|
74 |
communicationEmail = this.request.getParameter("communicationEmail");
|
|
|
75 |
|
| 569 |
rajveer |
76 |
dateOfBirth = this.request.getParameter("dateOfBirth");
|
| 507 |
rajveer |
77 |
sex = this.request.getParameter("sex");
|
| 741 |
rajveer |
78 |
|
|
|
79 |
if(userName == null ){
|
|
|
80 |
addActionError("Please enter name of user.");
|
|
|
81 |
isValid = false;
|
|
|
82 |
}
|
|
|
83 |
if(email == null ){
|
|
|
84 |
addActionError("Please enter valid email.");
|
|
|
85 |
isValid = false;
|
|
|
86 |
}
|
|
|
87 |
if(password == null ){
|
|
|
88 |
addActionError("Please enter password.");
|
|
|
89 |
isValid = false;
|
|
|
90 |
}
|
|
|
91 |
if(communicationEmail == null ){
|
|
|
92 |
addActionError("Please enter Communication email.");
|
|
|
93 |
isValid = false;
|
|
|
94 |
}
|
| 507 |
rajveer |
95 |
|
| 741 |
rajveer |
96 |
if(!isValid){
|
| 3185 |
vikas |
97 |
DataLogger.logData(EventType.REGISTER_DATA_INCOMPLETE, getSessionId(), userinfo.getUserId(), email, userName, communicationEmail);
|
| 741 |
rajveer |
98 |
return isValid;
|
|
|
99 |
}
|
|
|
100 |
|
| 3126 |
rajveer |
101 |
UserClient userContextServiceClient = new UserClient();
|
| 555 |
chandransh |
102 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
| 507 |
rajveer |
103 |
|
|
|
104 |
if(userClient.userExists(email)){
|
| 786 |
rajveer |
105 |
addActionError("User already exists with this email id.");
|
| 3185 |
vikas |
106 |
DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, userName, communicationEmail);
|
| 507 |
rajveer |
107 |
return false;
|
| 555 |
chandransh |
108 |
}
|
|
|
109 |
|
|
|
110 |
User user = new User();
|
|
|
111 |
user.setName(userName);
|
|
|
112 |
user.setEmail(email);
|
| 815 |
rajveer |
113 |
String encryptedPassword = desEncrypter.encrypt(password);
|
|
|
114 |
user.setPassword(encryptedPassword);
|
| 555 |
chandransh |
115 |
user.setCommunicationEmail(communicationEmail);
|
| 569 |
rajveer |
116 |
user.setMobileNumber(mobileNumber);
|
|
|
117 |
user.setDateOfBirth(dateOfBirth);
|
| 2021 |
vikas |
118 |
Cookie sourceCookie = (Cookie) cookiesMap.get(TrackingInterceptor.SRC_COOKIE);
|
|
|
119 |
if (sourceCookie != null) {
|
| 2817 |
vikas |
120 |
DesEncrypter des = new DesEncrypter(TrackingInterceptor.ENCRIPTION_STRING);
|
| 2021 |
vikas |
121 |
String sourceCookieVal = des.decrypt(sourceCookie.getValue());
|
|
|
122 |
user.setSource(sourceCookieVal);
|
|
|
123 |
}
|
| 2817 |
vikas |
124 |
|
|
|
125 |
Cookie sourceTimeCookie = (Cookie) cookiesMap.get(TrackingInterceptor.SRC_TIME_COOKIE);
|
|
|
126 |
long sourceTime = 0;
|
|
|
127 |
if (sourceTimeCookie != null) {
|
|
|
128 |
try {
|
|
|
129 |
sourceTime = Long.parseLong(sourceTimeCookie.getValue());
|
|
|
130 |
}
|
|
|
131 |
catch (Exception e) {
|
|
|
132 |
log.warn("Unable to parse session src time cookie.");
|
|
|
133 |
}
|
|
|
134 |
user.setSourceStartTime(sourceTime);
|
|
|
135 |
}
|
| 555 |
chandransh |
136 |
|
|
|
137 |
user.setSex(Sex.WONT_SAY);
|
|
|
138 |
if (sex != null) {
|
|
|
139 |
try {
|
|
|
140 |
user.setSex(Sex.findByValue(Integer.parseInt(sex)));
|
|
|
141 |
} catch (NumberFormatException nfe) {
|
|
|
142 |
log.error("Unusual value for sex. Leaving it marked as won't say.");
|
| 507 |
rajveer |
143 |
}
|
| 555 |
chandransh |
144 |
}
|
| 507 |
rajveer |
145 |
|
|
|
146 |
|
| 555 |
chandransh |
147 |
user = userClient.createUser(user);
|
|
|
148 |
long userId = user.getUserId();
|
|
|
149 |
userClient.setUserAsLoggedIn(userId, (new Date()).getTime());
|
| 793 |
rajveer |
150 |
String pincode = userClient.getDefaultPincode(user.getUserId());
|
|
|
151 |
|
| 555 |
chandransh |
152 |
// TODO: setTotalItems shouldn't be a method on userinfo. This allows
|
|
|
153 |
// for potentially updating the item count wrongly. The method setCartId
|
|
|
154 |
// should update the item count as well. Also, there can be a method
|
|
|
155 |
// called refreshItemCount() that automatically updates the number of
|
|
|
156 |
// items currently in the cart.
|
| 1625 |
rajveer |
157 |
if(userinfo.getUserId() != -1){
|
| 1623 |
rajveer |
158 |
userClient.mergeCart(userinfo.getCartId(), user.getActiveCartId());
|
|
|
159 |
|
| 2982 |
rajveer |
160 |
List<Long> items = userClient.getBrowseHistoryItems(userinfo.getUserId());
|
|
|
161 |
if(items != null){
|
|
|
162 |
for(Long itemId: items){
|
|
|
163 |
userClient.updateBrowseHistory(user.getUserId(), itemId);
|
| 1623 |
rajveer |
164 |
}
|
|
|
165 |
}
|
| 2982 |
rajveer |
166 |
|
|
|
167 |
items = userClient.getMyResearchItems(userinfo.getUserId());
|
|
|
168 |
if(items != null){
|
|
|
169 |
for(Long itemId: items){
|
|
|
170 |
userClient.updateMyResearch(user.getUserId(), itemId);
|
| 1625 |
rajveer |
171 |
}
|
|
|
172 |
}
|
| 1623 |
rajveer |
173 |
}
|
|
|
174 |
|
| 1625 |
rajveer |
175 |
userinfo.setUserId(userId);
|
|
|
176 |
userinfo.setNameOfUser(userName);
|
|
|
177 |
userinfo.setEmail(email);
|
|
|
178 |
userinfo.setLoggedIn(true);
|
|
|
179 |
userinfo.setPincode(pincode);
|
| 555 |
chandransh |
180 |
userinfo.setCartId(user.getActiveCartId());
|
| 762 |
rajveer |
181 |
int totalItems = userClient.getCart(userinfo.getCartId()).getLinesSize();
|
|
|
182 |
userinfo.setTotalItems(totalItems);
|
| 1999 |
vikas |
183 |
if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
|
|
|
184 |
long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
|
|
|
185 |
userClient.addTrackLog(affId, userId, "new registration", "",email, (new Date()).getTime());
|
| 1868 |
vikas |
186 |
}
|
| 3224 |
vikas |
187 |
DataLogger.logData(EventType.REGISTER_SUCCESS, getSessionId(), userinfo.getUserId(), email, userName, communicationEmail);
|
| 555 |
chandransh |
188 |
|
|
|
189 |
return true;
|
| 507 |
rajveer |
190 |
}
|
|
|
191 |
|
|
|
192 |
public String getRegistrationHeaderSnippet(){
|
|
|
193 |
return htmlSnippets.get("REGISTRATION_HEADER");
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
public String getRegistrationFormSnippet(){
|
|
|
197 |
return htmlSnippets.get("REGISTRATION_FORM");
|
|
|
198 |
}
|
| 1776 |
varun.gupt |
199 |
public String getRedirectUrl() {
|
|
|
200 |
return redirectUrl;
|
|
|
201 |
}
|
| 507 |
rajveer |
202 |
|
| 1776 |
varun.gupt |
203 |
public void setRedirectUrl(String redirectUrl) {
|
|
|
204 |
this.redirectUrl = redirectUrl;
|
|
|
205 |
}
|
|
|
206 |
}
|