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