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