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