| 637 |
rajveer |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
|
|
6 |
import java.io.IOException;
|
|
|
7 |
import java.util.Date;
|
| 1623 |
rajveer |
8 |
import java.util.List;
|
| 637 |
rajveer |
9 |
|
| 7825 |
amar.kumar |
10 |
import javax.servlet.http.Cookie;
|
|
|
11 |
import javax.servlet.http.HttpServletResponse;
|
|
|
12 |
|
|
|
13 |
import org.apache.commons.codec.binary.Base64;
|
|
|
14 |
import org.apache.commons.lang.RandomStringUtils;
|
| 832 |
rajveer |
15 |
import org.apache.log4j.Logger;
|
| 7825 |
amar.kumar |
16 |
import org.apache.struts2.ServletActionContext;
|
| 4222 |
varun.gupt |
17 |
import org.apache.struts2.convention.annotation.Action;
|
|
|
18 |
import org.apache.struts2.convention.annotation.Actions;
|
|
|
19 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
| 637 |
rajveer |
20 |
import org.apache.struts2.convention.annotation.Result;
|
| 925 |
rajveer |
21 |
import org.apache.struts2.convention.annotation.Results;
|
| 7825 |
amar.kumar |
22 |
import org.apache.thrift.TException;
|
|
|
23 |
import org.apache.thrift.transport.TTransportException;
|
|
|
24 |
import org.json.JSONObject;
|
| 637 |
rajveer |
25 |
|
| 20180 |
aman.kumar |
26 |
import in.shop2020.model.v1.user.Cart;
|
|
|
27 |
import in.shop2020.model.v1.user.Sex;
|
|
|
28 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
|
|
29 |
import in.shop2020.model.v1.user.TrackLogType;
|
|
|
30 |
import in.shop2020.model.v1.user.User;
|
|
|
31 |
import in.shop2020.model.v1.user.UserAffiliateException;
|
|
|
32 |
import in.shop2020.model.v1.user.UserContextException;
|
|
|
33 |
import in.shop2020.model.v1.user.WidgetException;
|
|
|
34 |
import in.shop2020.serving.interceptors.TrackingInterceptor;
|
|
|
35 |
import in.shop2020.serving.interceptors.UserInterceptor;
|
|
|
36 |
import in.shop2020.serving.utils.DesEncrypter;
|
|
|
37 |
import in.shop2020.serving.utils.FacebookUtility;
|
|
|
38 |
import in.shop2020.serving.utils.UserMessage;
|
| 20202 |
aman.kumar |
39 |
import in.shop2020.serving.utils.Utils;
|
| 20180 |
aman.kumar |
40 |
import in.shop2020.thrift.clients.UserClient;
|
|
|
41 |
|
| 637 |
rajveer |
42 |
/**
|
|
|
43 |
*
|
|
|
44 |
* @author rajveer
|
| 781 |
vikas |
45 |
*
|
| 637 |
rajveer |
46 |
*/
|
| 925 |
rajveer |
47 |
@Results({
|
|
|
48 |
@Result(name="success", type="redirectAction", params = {"actionName" , "home"}),
|
|
|
49 |
@Result(name = "redirect", location = "${redirectUrl}", type = "redirect")
|
|
|
50 |
})
|
| 637 |
rajveer |
51 |
|
| 781 |
vikas |
52 |
public class LoginController extends BaseController {
|
| 650 |
rajveer |
53 |
|
| 781 |
vikas |
54 |
/**
|
|
|
55 |
*
|
|
|
56 |
*/
|
|
|
57 |
private static final long serialVersionUID = 5390035354379263121L;
|
| 650 |
rajveer |
58 |
|
| 832 |
rajveer |
59 |
private static Logger log = Logger.getLogger(Class.class);
|
| 815 |
rajveer |
60 |
private DesEncrypter desEncrypter = new DesEncrypter("saholic");
|
| 5510 |
rajveer |
61 |
private String loginResult = "0";
|
| 2933 |
vikas |
62 |
private String redirectUrl = "/";
|
| 7825 |
amar.kumar |
63 |
private String signed_request;
|
|
|
64 |
private Long userId = -1L;
|
| 20180 |
aman.kumar |
65 |
private String loginJson = "{}";
|
| 7825 |
amar.kumar |
66 |
|
| 781 |
vikas |
67 |
public LoginController() {
|
| 637 |
rajveer |
68 |
super();
|
|
|
69 |
}
|
| 4222 |
varun.gupt |
70 |
@Actions({
|
|
|
71 |
@Action(value="login", interceptorRefs={@InterceptorRef("myDefault")}),
|
|
|
72 |
@Action(value="login-mini", interceptorRefs={@InterceptorRef("myDefault")})
|
|
|
73 |
})
|
| 781 |
vikas |
74 |
public String index() throws SecurityException, IOException {
|
| 925 |
rajveer |
75 |
if(userinfo.isLoggedIn()){
|
|
|
76 |
return "success";
|
|
|
77 |
}
|
| 650 |
rajveer |
78 |
return "index";
|
| 781 |
vikas |
79 |
}
|
| 637 |
rajveer |
80 |
|
| 781 |
vikas |
81 |
public String create() throws SecurityException, Exception {
|
| 20202 |
aman.kumar |
82 |
loginUser();
|
|
|
83 |
return "login-response";
|
|
|
84 |
// log.info("Will redirect the user to:" + redirectUrl);
|
| 11918 |
amit.gupta |
85 |
/* if(userinfo.isPrivateDealUser()){
|
|
|
86 |
addActionMessage("PrivateDealUser");
|
|
|
87 |
}*/
|
| 20202 |
aman.kumar |
88 |
// return "redirect";
|
|
|
89 |
//} else {
|
|
|
90 |
// log.info("in else of loginuser");
|
|
|
91 |
// addActionError(UserMessage.USER_AUTHENTICATION_FAILURE);
|
| 12616 |
anikendra |
92 |
// DataLogger.logData(EventType.LOGIN_FAILED, getSessionId(), userinfo.getUserId(), this.request.getParameter("email"));
|
| 20202 |
aman.kumar |
93 |
// return "login";
|
|
|
94 |
//}
|
| 781 |
vikas |
95 |
}
|
|
|
96 |
|
| 20180 |
aman.kumar |
97 |
public String verifyFbUser(){
|
|
|
98 |
JSONObject json = new JSONObject();
|
|
|
99 |
try{
|
|
|
100 |
String email = this.request.getParameter("email");
|
|
|
101 |
String accessToken = this.request.getParameter("accessToken");
|
|
|
102 |
UserClient userContextServiceClient = new UserClient();
|
|
|
103 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
104 |
User user = userClient.getUserByEmail(email);
|
| 20184 |
aman.kumar |
105 |
if(user!=null && user.getUserId()>0){
|
| 20180 |
aman.kumar |
106 |
//if user exists
|
|
|
107 |
//verify its accessToken
|
|
|
108 |
JSONObject result= new FacebookUtility().verifyFbToken(accessToken,email,user.isIsFacebookUser(),user.getFacebookId());
|
|
|
109 |
|
|
|
110 |
if("true".equalsIgnoreCase(result.getString("status"))){
|
|
|
111 |
|
|
|
112 |
String storedFbId = user.getFacebookId();
|
|
|
113 |
if((storedFbId==null|| (storedFbId!=null && storedFbId.isEmpty()))){
|
|
|
114 |
user.setFacebookId(result.getString("id"));
|
|
|
115 |
user.setIsFacebookUser(true);
|
|
|
116 |
}
|
|
|
117 |
json.put("status", "success");
|
|
|
118 |
setFbLoginCookie(userClient, user);
|
|
|
119 |
}else{
|
|
|
120 |
json.put("status", "fail");
|
|
|
121 |
json.put("message", "No such user exist");
|
|
|
122 |
}
|
|
|
123 |
}else{
|
|
|
124 |
//no such user exists
|
|
|
125 |
//ask him to signup
|
|
|
126 |
json.put("status", "fail");
|
|
|
127 |
json.put("message", "No such user exist");
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
setLoginJson(json.toString());
|
|
|
131 |
}catch(Exception e){
|
|
|
132 |
log.error(UserMessage.USER_AUTHENTICATION_FAILURE, e);
|
|
|
133 |
}
|
|
|
134 |
return "login-response";
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
private void setFbLoginCookie(in.shop2020.model.v1.user.UserContextService.Client userClient, User user){
|
|
|
138 |
|
|
|
139 |
try{
|
|
|
140 |
Cookie uidCookie = (Cookie) cookiesMap.get(UserInterceptor.USER_ID_COOKIE_NAME);
|
|
|
141 |
Cookie uicCookie = (Cookie) cookiesMap.get(UserInterceptor.USER_INFO_COOKIE_NAME);
|
|
|
142 |
HttpServletResponse response = ServletActionContext.getResponse();
|
|
|
143 |
if (uidCookie == null) {
|
|
|
144 |
DesEncrypter cookieEncryter = new DesEncrypter(UserInterceptor.COOKIE_DECRYPTION_STRING);
|
|
|
145 |
uidCookie = new Cookie(UserInterceptor.USER_ID_COOKIE_NAME, cookieEncryter.encrypt(userId + ""));
|
|
|
146 |
uidCookie.setPath("/");
|
|
|
147 |
if(!domainName.isEmpty()) {
|
|
|
148 |
uidCookie.setDomain(domainName);
|
|
|
149 |
}
|
|
|
150 |
}
|
|
|
151 |
if (uicCookie != null) {
|
|
|
152 |
uicCookie.setMaxAge(UserInterceptor.FACEBOOK_USER_COOKIE_EXPIRY_TIME);
|
|
|
153 |
cookiesMap.put(UserInterceptor.USER_INFO_COOKIE_NAME, uicCookie);
|
|
|
154 |
response.addCookie(uicCookie);
|
|
|
155 |
}
|
|
|
156 |
uidCookie.setMaxAge(UserInterceptor.FACEBOOK_USER_COOKIE_EXPIRY_TIME);
|
|
|
157 |
cookiesMap.put(UserInterceptor.USER_ID_COOKIE_NAME, uidCookie);
|
|
|
158 |
response.addCookie(uidCookie);
|
|
|
159 |
|
|
|
160 |
userClient.setUserAsLoggedIn(user.getUserId(),(new Date()).getTime());
|
|
|
161 |
String pincode = userClient.getDefaultPincode(user.getUserId());
|
|
|
162 |
|
|
|
163 |
// TODO: setTotalItems shouldn't be a method on userinfo. This allows
|
|
|
164 |
// for potentially updating the item count wrongly. The method setCartId
|
|
|
165 |
// should update the item count as well. Also, there can be a method
|
|
|
166 |
// called refreshItemCount() that automatically updates the number of
|
|
|
167 |
// items currently in the cart.
|
|
|
168 |
if(userinfo.getUserId() != -1){
|
|
|
169 |
userClient.mergeCart(userinfo.getCartId(), user.getActiveCartId());
|
|
|
170 |
|
|
|
171 |
List<Long> items = userClient.getBrowseHistoryItems(userinfo.getUserId());
|
|
|
172 |
if(items != null){
|
|
|
173 |
for(Long itemId: items){
|
|
|
174 |
userClient.updateBrowseHistory(user.getUserId(), itemId);
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
items = userClient.getMyResearchItems(userinfo.getUserId());
|
|
|
179 |
if(items != null){
|
|
|
180 |
for(Long itemId: items){
|
|
|
181 |
userClient.updateMyResearch(user.getUserId(), itemId);
|
|
|
182 |
}
|
|
|
183 |
}
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
userinfo.setUserId(user.getUserId());
|
|
|
187 |
userinfo.setEmail(user.getEmail());
|
|
|
188 |
userinfo.setLoggedIn(true);
|
|
|
189 |
userinfo.setPincode(pincode);
|
|
|
190 |
userinfo.setCartId(user.getActiveCartId());
|
|
|
191 |
Cart cart = userClient.getCart(user.getActiveCartId());
|
|
|
192 |
userinfo.setTotalItems(cart.getLinesSize());
|
|
|
193 |
userinfo.setTotalAmount(cart.getTotalPrice());
|
|
|
194 |
userinfo.setPrivateDealUser(isPrivateDealUser());
|
|
|
195 |
String src = user.getSource();
|
|
|
196 |
if (src == null) {
|
|
|
197 |
src = "";
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
}catch(Exception e){
|
|
|
201 |
e.printStackTrace();
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
|
| 20202 |
aman.kumar |
206 |
public String signupFacebookUser(){
|
|
|
207 |
try{
|
|
|
208 |
JSONObject json = new JSONObject();
|
|
|
209 |
String email = this.request.getParameter("email");
|
|
|
210 |
String accessToken = this.request.getParameter("accessToken");
|
|
|
211 |
UserClient userContextServiceClient = new UserClient();
|
|
|
212 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
213 |
User user = userClient.getUserByEmail(email);
|
|
|
214 |
if(user==null ){
|
|
|
215 |
//if user do not exists
|
|
|
216 |
//verify its accessToken
|
|
|
217 |
JSONObject result= new FacebookUtility().verifyFbToken(accessToken,email,user.isIsFacebookUser(),user.getFacebookId());
|
|
|
218 |
if("true".equalsIgnoreCase(result.getString("status"))){
|
|
|
219 |
//if token verified
|
|
|
220 |
//create facebook user/register user
|
|
|
221 |
boolean res = createNewUserForFacebook(email);
|
|
|
222 |
if(res){
|
| 20222 |
aman.kumar |
223 |
json.put("status", "success");
|
|
|
224 |
|
| 20202 |
aman.kumar |
225 |
}else{
|
| 20222 |
aman.kumar |
226 |
json.put("status", "fail");
|
|
|
227 |
json.put("message", getActionErrors().iterator().next());
|
| 20202 |
aman.kumar |
228 |
}
|
|
|
229 |
setFbLoginCookie(userClient, user);
|
|
|
230 |
}else{
|
|
|
231 |
json.put("status", "fail");
|
|
|
232 |
json.put("message", "Some error occurred. Please try again.");
|
|
|
233 |
}
|
|
|
234 |
}else{
|
|
|
235 |
//no such user exists
|
|
|
236 |
//ask him to signup
|
|
|
237 |
json.put("status", "fail");
|
|
|
238 |
json.put("message", "You are already a member. Please login.");
|
|
|
239 |
}
|
|
|
240 |
setLoginJson(json.toString());
|
|
|
241 |
}catch(Exception e){
|
|
|
242 |
e.printStackTrace();
|
|
|
243 |
}
|
| 20224 |
aman.kumar |
244 |
return "login-response";
|
| 20202 |
aman.kumar |
245 |
}
|
| 20180 |
aman.kumar |
246 |
|
| 20202 |
aman.kumar |
247 |
|
| 781 |
vikas |
248 |
private boolean loginUser() {
|
| 20202 |
aman.kumar |
249 |
JSONObject json = new JSONObject();
|
| 781 |
vikas |
250 |
try {
|
| 20176 |
aman.kumar |
251 |
log.info("in loginuser");
|
| 20202 |
aman.kumar |
252 |
String email, password = null;
|
| 7825 |
amar.kumar |
253 |
email = this.request.getParameter("email");
|
|
|
254 |
password = this.request.getParameter("password");
|
| 20202 |
aman.kumar |
255 |
boolean isValid = true;
|
|
|
256 |
/*if(!Utils.isValidEmail(email)) {
|
|
|
257 |
//addActionError("Please enter valid email address.");
|
|
|
258 |
json.put("message", "Please enter valid email address.");
|
|
|
259 |
json.put("status", "error");
|
|
|
260 |
isValid = false;
|
|
|
261 |
}*/
|
|
|
262 |
if(password == null ) {
|
|
|
263 |
//addActionError("Please enter password.");
|
|
|
264 |
json.put("message", "Please enter password.");
|
|
|
265 |
json.put("status", "error");
|
|
|
266 |
isValid = false;
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
if(!isValid){
|
|
|
270 |
setLoginJson(json.toString());
|
|
|
271 |
// DataLogger.logData(EventType.REGISTER_DATA_INCOMPLETE, getSessionId(), userinfo.getUserId(), email, "", email);
|
|
|
272 |
return isValid;
|
|
|
273 |
}
|
| 7825 |
amar.kumar |
274 |
String encryptedPassword = null;
|
| 20202 |
aman.kumar |
275 |
if(password!=null){
|
| 7825 |
amar.kumar |
276 |
encryptedPassword = desEncrypter.encrypt(password);
|
|
|
277 |
}
|
| 3126 |
rajveer |
278 |
UserClient userContextServiceClient = new UserClient();
|
| 1747 |
varun.gupt |
279 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
| 7825 |
amar.kumar |
280 |
User user = null;
|
|
|
281 |
boolean shouldChangeCookieExpiry = false;
|
|
|
282 |
if (userClient.userExists(email)){
|
|
|
283 |
shouldChangeCookieExpiry = true;
|
| 20202 |
aman.kumar |
284 |
|
|
|
285 |
if(shouldChangeCookieExpiry) {
|
| 7825 |
amar.kumar |
286 |
Cookie uidCookie = (Cookie) cookiesMap.get(UserInterceptor.USER_ID_COOKIE_NAME);
|
|
|
287 |
Cookie uicCookie = (Cookie) cookiesMap.get(UserInterceptor.USER_INFO_COOKIE_NAME);
|
|
|
288 |
HttpServletResponse response = ServletActionContext.getResponse();
|
|
|
289 |
if (uidCookie == null) {
|
|
|
290 |
DesEncrypter cookieEncryter = new DesEncrypter(UserInterceptor.COOKIE_DECRYPTION_STRING);
|
|
|
291 |
uidCookie = new Cookie(UserInterceptor.USER_ID_COOKIE_NAME, cookieEncryter.encrypt(userId + ""));
|
|
|
292 |
uidCookie.setPath("/");
|
|
|
293 |
if(!domainName.isEmpty()) {
|
|
|
294 |
uidCookie.setDomain(domainName);
|
|
|
295 |
}
|
|
|
296 |
}
|
|
|
297 |
if (uicCookie != null) {
|
|
|
298 |
uicCookie.setMaxAge(UserInterceptor.FACEBOOK_USER_COOKIE_EXPIRY_TIME);
|
|
|
299 |
cookiesMap.put(UserInterceptor.USER_INFO_COOKIE_NAME, uicCookie);
|
|
|
300 |
response.addCookie(uicCookie);
|
|
|
301 |
}
|
|
|
302 |
uidCookie.setMaxAge(UserInterceptor.FACEBOOK_USER_COOKIE_EXPIRY_TIME);
|
|
|
303 |
cookiesMap.put(UserInterceptor.USER_ID_COOKIE_NAME, uidCookie);
|
|
|
304 |
response.addCookie(uidCookie);
|
|
|
305 |
|
|
|
306 |
}
|
| 20202 |
aman.kumar |
307 |
//} else {
|
| 7825 |
amar.kumar |
308 |
user = userClient.authenticateUser(email, encryptedPassword);
|
| 20202 |
aman.kumar |
309 |
}else{
|
|
|
310 |
json.put("message", "Login Id/password is wrong");
|
|
|
311 |
json.put("status", "error");
|
|
|
312 |
setLoginJson(json.toString());
|
| 7825 |
amar.kumar |
313 |
}
|
| 793 |
rajveer |
314 |
userClient.setUserAsLoggedIn(user.getUserId(),(new Date()).getTime());
|
|
|
315 |
String pincode = userClient.getDefaultPincode(user.getUserId());
|
| 1175 |
varun.gupt |
316 |
// TODO: setTotalItems shouldn't be a method on userinfo. This allows
|
|
|
317 |
// for potentially updating the item count wrongly. The method setCartId
|
| 637 |
rajveer |
318 |
// should update the item count as well. Also, there can be a method
|
| 1175 |
varun.gupt |
319 |
// called refreshItemCount() that automatically updates the number of
|
| 637 |
rajveer |
320 |
// items currently in the cart.
|
| 1625 |
rajveer |
321 |
if(userinfo.getUserId() != -1){
|
| 1623 |
rajveer |
322 |
userClient.mergeCart(userinfo.getCartId(), user.getActiveCartId());
|
| 2982 |
rajveer |
323 |
List<Long> items = userClient.getBrowseHistoryItems(userinfo.getUserId());
|
|
|
324 |
if(items != null){
|
|
|
325 |
for(Long itemId: items){
|
|
|
326 |
userClient.updateBrowseHistory(user.getUserId(), itemId);
|
| 1623 |
rajveer |
327 |
}
|
|
|
328 |
}
|
| 2982 |
rajveer |
329 |
items = userClient.getMyResearchItems(userinfo.getUserId());
|
|
|
330 |
if(items != null){
|
|
|
331 |
for(Long itemId: items){
|
|
|
332 |
userClient.updateMyResearch(user.getUserId(), itemId);
|
| 1625 |
rajveer |
333 |
}
|
|
|
334 |
}
|
| 1623 |
rajveer |
335 |
}
|
| 1625 |
rajveer |
336 |
userinfo.setUserId(user.getUserId());
|
|
|
337 |
userinfo.setEmail(email);
|
|
|
338 |
userinfo.setLoggedIn(true);
|
|
|
339 |
userinfo.setPincode(pincode);
|
| 637 |
rajveer |
340 |
userinfo.setCartId(user.getActiveCartId());
|
| 3830 |
chandransh |
341 |
Cart cart = userClient.getCart(user.getActiveCartId());
|
|
|
342 |
userinfo.setTotalItems(cart.getLinesSize());
|
|
|
343 |
userinfo.setTotalAmount(cart.getTotalPrice());
|
| 11808 |
amit.gupta |
344 |
userinfo.setPrivateDealUser(isPrivateDealUser());
|
| 2996 |
vikas |
345 |
String src = user.getSource();
|
|
|
346 |
if (src == null) {
|
|
|
347 |
src = "";
|
|
|
348 |
}
|
| 12616 |
anikendra |
349 |
// DataLogger.logData(EventType.LOGIN_SUCCESS, getSessionId(), userinfo.getUserId(),
|
|
|
350 |
// email, src);
|
| 20202 |
aman.kumar |
351 |
json.put("message", "Login success");
|
|
|
352 |
json.put("status", "success");
|
|
|
353 |
setLoginJson(json.toString());
|
| 2637 |
vikas |
354 |
return true;
|
| 781 |
vikas |
355 |
} catch (Exception e) {
|
| 2959 |
chandransh |
356 |
log.error(UserMessage.USER_AUTHENTICATION_FAILURE, e);
|
| 20202 |
aman.kumar |
357 |
setLoginJson("{\"status\":\"error\",\"message\":\"LoginId/password wrong\"}");
|
| 781 |
vikas |
358 |
return false;
|
|
|
359 |
}
|
|
|
360 |
}
|
| 7825 |
amar.kumar |
361 |
|
|
|
362 |
private boolean createNewUserForFacebook(String email) {
|
|
|
363 |
String password;
|
|
|
364 |
password = RandomStringUtils.randomAlphabetic(8);
|
|
|
365 |
|
| 20178 |
aman.kumar |
366 |
String name = (String)this.request.getParameter("name");
|
|
|
367 |
String accessToken = (String)this.request.getParameter("accessToken");
|
|
|
368 |
String facebookId = (String)this.request.getParameter("facebookId");
|
| 7825 |
amar.kumar |
369 |
User user = new User();
|
|
|
370 |
user.setEmail(email);
|
|
|
371 |
String encryptedPassword = desEncrypter.encrypt(password);
|
|
|
372 |
user.setPassword(encryptedPassword);
|
|
|
373 |
user.setCommunicationEmail(email);
|
|
|
374 |
user.setName(name);
|
|
|
375 |
user.setFacebookAccessToken(accessToken);
|
|
|
376 |
if(user.getFacebookId()==null || user.getFacebookId().isEmpty()) {
|
|
|
377 |
user.setFacebookId(facebookId);
|
|
|
378 |
}
|
|
|
379 |
Cookie sourceCookie = (Cookie) cookiesMap.get(TrackingInterceptor.SRC_COOKIE);
|
|
|
380 |
if (sourceCookie != null) {
|
|
|
381 |
DesEncrypter des = new DesEncrypter(TrackingInterceptor.ENCRIPTION_STRING);
|
|
|
382 |
String sourceCookieVal = des.decrypt(sourceCookie.getValue());
|
|
|
383 |
user.setSource(sourceCookieVal);
|
|
|
384 |
}
|
|
|
385 |
|
|
|
386 |
Cookie sourceTimeCookie = (Cookie) cookiesMap.get(TrackingInterceptor.SRC_TIME_COOKIE);
|
|
|
387 |
long sourceTime = 0;
|
|
|
388 |
if (sourceTimeCookie != null) {
|
|
|
389 |
try {
|
|
|
390 |
sourceTime = Long.parseLong(sourceTimeCookie.getValue());
|
|
|
391 |
}
|
|
|
392 |
catch (Exception e) {
|
|
|
393 |
log.warn("Unable to parse session src time cookie.");
|
|
|
394 |
}
|
|
|
395 |
user.setSourceStartTime(sourceTime);
|
|
|
396 |
}
|
|
|
397 |
|
|
|
398 |
user.setSex(Sex.WONT_SAY);
|
|
|
399 |
user.setIsFacebookUser(true);
|
|
|
400 |
|
|
|
401 |
UserClient userContextServiceClient;
|
|
|
402 |
try {
|
|
|
403 |
userContextServiceClient = new UserClient();
|
|
|
404 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
405 |
try{
|
|
|
406 |
user = userClient.createUser(user);
|
|
|
407 |
}catch (UserContextException ux){
|
|
|
408 |
addActionError("User already exists with this email id.");
|
| 12616 |
anikendra |
409 |
// DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
|
| 7825 |
amar.kumar |
410 |
return false;
|
|
|
411 |
}
|
|
|
412 |
this.userId = user.getUserId();
|
|
|
413 |
long userId = user.getUserId();
|
|
|
414 |
userClient.setUserAsLoggedIn(userId, (new Date()).getTime());
|
|
|
415 |
String pincode = userClient.getDefaultPincode(user.getUserId());
|
|
|
416 |
|
|
|
417 |
if(userinfo.getUserId() != -1){
|
|
|
418 |
userClient.mergeCart(userinfo.getCartId(), user.getActiveCartId());
|
|
|
419 |
|
|
|
420 |
List<Long> items = userClient.getBrowseHistoryItems(userinfo.getUserId());
|
|
|
421 |
if(items != null){
|
|
|
422 |
for(Long itemId: items){
|
|
|
423 |
userClient.updateBrowseHistory(user.getUserId(), itemId);
|
|
|
424 |
}
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
items = userClient.getMyResearchItems(userinfo.getUserId());
|
|
|
428 |
if(items != null){
|
|
|
429 |
for(Long itemId: items){
|
|
|
430 |
userClient.updateMyResearch(user.getUserId(), itemId);
|
|
|
431 |
}
|
|
|
432 |
}
|
|
|
433 |
}
|
|
|
434 |
|
|
|
435 |
userinfo.setUserId(userId);
|
|
|
436 |
userinfo.setEmail(email);
|
|
|
437 |
userinfo.setLoggedIn(true);
|
|
|
438 |
userinfo.setPincode(pincode);
|
|
|
439 |
userinfo.setCartId(user.getActiveCartId());
|
|
|
440 |
Cart cart = userClient.getCart(userinfo.getCartId());
|
|
|
441 |
userinfo.setTotalItems(cart.getLinesSize());
|
|
|
442 |
userinfo.setTotalAmount(cart.getTotalPrice());
|
|
|
443 |
|
|
|
444 |
if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
|
|
|
445 |
long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
|
|
|
446 |
userClient.addTrackLog(affId, userId, TrackLogType.NEW_REGISTRATION, "",email, (new Date()).getTime());
|
|
|
447 |
}
|
| 12616 |
anikendra |
448 |
// DataLogger.logData(EventType.REGISTER_SUCCESS, getSessionId(), userinfo.getUserId(), email, "", email);
|
| 7825 |
amar.kumar |
449 |
|
|
|
450 |
return true;
|
|
|
451 |
} catch (TTransportException e) {
|
|
|
452 |
log.error("Unable to register user." + e);
|
|
|
453 |
} catch (UserContextException e) {
|
|
|
454 |
log.error("Unable to register user." + e);
|
|
|
455 |
} catch (TException e) {
|
|
|
456 |
log.error("Unable to register user." + e);
|
|
|
457 |
} catch (UserAffiliateException e) {
|
|
|
458 |
log.error("Unable to register user." + e);
|
|
|
459 |
} catch (ShoppingCartException e) {
|
|
|
460 |
log.error("Unable to register user." + e);
|
|
|
461 |
} catch (WidgetException e) {
|
|
|
462 |
log.error("Unable to register user." + e);
|
|
|
463 |
}
|
|
|
464 |
return false;
|
|
|
465 |
}
|
|
|
466 |
|
|
|
467 |
public String facebooklogin(){
|
|
|
468 |
try {
|
|
|
469 |
String dataResponse = signed_request.split("\\.")[1];
|
|
|
470 |
String encoded_json = dataResponse.replace("-", "+").replace("_", "/");
|
|
|
471 |
byte[] decoded_json = Base64.decodeBase64(encoded_json);
|
|
|
472 |
JSONObject json_data = new JSONObject(new String(decoded_json, "UTF-8"));
|
|
|
473 |
this.request.setAttribute("name", (new JSONObject(json_data.get("registration").toString())).get("name"));
|
|
|
474 |
this.request.setAttribute("email", (new JSONObject(json_data.get("registration").toString())).get("email"));
|
|
|
475 |
this.request.setAttribute("accessToken", json_data.get("oauth_token").toString());
|
|
|
476 |
this.request.setAttribute("facebookId", json_data.get("user_id").toString());
|
|
|
477 |
this.request.setAttribute("isFacebookUser", "true");
|
|
|
478 |
if(loginUser()){
|
|
|
479 |
return "redirect";
|
|
|
480 |
} else {
|
|
|
481 |
log.error("Error in logging through facebook");
|
|
|
482 |
addActionError(UserMessage.FACEBOOK_USER_AUTH_FAILURE);
|
|
|
483 |
return "login";
|
|
|
484 |
}
|
|
|
485 |
} catch (Exception e ) {
|
|
|
486 |
log.error("Error in reading facebook response for login", e);
|
|
|
487 |
addActionError(UserMessage.FACEBOOK_USER_AUTH_FAILURE);
|
|
|
488 |
return "login";
|
|
|
489 |
}
|
|
|
490 |
}
|
|
|
491 |
|
| 5510 |
rajveer |
492 |
public String authenticateUser() {
|
|
|
493 |
String email, password;
|
|
|
494 |
|
|
|
495 |
email = this.request.getParameter("email");
|
|
|
496 |
password = this.request.getParameter("password");
|
|
|
497 |
|
|
|
498 |
if (email == null || password == null) {
|
|
|
499 |
loginResult = "0";
|
|
|
500 |
return "result";
|
|
|
501 |
}
|
|
|
502 |
|
|
|
503 |
String encryptedPassword = desEncrypter.encrypt(password);
|
|
|
504 |
try{
|
|
|
505 |
UserClient userContextServiceClient = new UserClient();
|
|
|
506 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
|
|
507 |
userClient.authenticateUser(email, encryptedPassword);
|
|
|
508 |
}catch (Exception e) {
|
|
|
509 |
loginResult = "0";
|
|
|
510 |
return "result";
|
|
|
511 |
}
|
|
|
512 |
loginResult = "1";
|
|
|
513 |
return "result";
|
|
|
514 |
}
|
|
|
515 |
|
|
|
516 |
public String getLoginResult() {
|
|
|
517 |
return loginResult;
|
|
|
518 |
}
|
|
|
519 |
|
| 924 |
vikas |
520 |
public String getRedirectUrl() {
|
|
|
521 |
return redirectUrl;
|
| 781 |
vikas |
522 |
}
|
|
|
523 |
|
| 924 |
vikas |
524 |
public void setRedirectUrl(String redirectUrl) {
|
|
|
525 |
this.redirectUrl = redirectUrl;
|
|
|
526 |
}
|
| 6903 |
anupam.sin |
527 |
|
| 7825 |
amar.kumar |
528 |
public String getSigned_request() {
|
|
|
529 |
return signed_request;
|
|
|
530 |
}
|
|
|
531 |
public void setSigned_request(String signed_request) {
|
|
|
532 |
this.signed_request = signed_request;
|
|
|
533 |
}
|
|
|
534 |
|
| 20180 |
aman.kumar |
535 |
|
|
|
536 |
|
|
|
537 |
public String getLoginJson() {
|
|
|
538 |
return loginJson;
|
|
|
539 |
}
|
|
|
540 |
public void setLoginJson(String loginJson) {
|
|
|
541 |
this.loginJson = loginJson;
|
|
|
542 |
}
|
| 6903 |
anupam.sin |
543 |
public static void main(String[] args) {
|
|
|
544 |
DesEncrypter des = new DesEncrypter("saholic");
|
| 12788 |
amit.gupta |
545 |
System.out.println(des.decrypt("V9gWakvuejQEJqCJjYhZtA"));
|
| 6903 |
anupam.sin |
546 |
}
|
| 11808 |
amit.gupta |
547 |
|
|
|
548 |
private boolean isPrivateDealUser() throws TTransportException, TException{
|
|
|
549 |
try {
|
|
|
550 |
in.shop2020.model.v1.user.UserContextService.Client uc = new UserClient().getClient();
|
|
|
551 |
return uc.isPrivateDealUser(userinfo.getUserId());
|
|
|
552 |
} catch (TTransportException e) {
|
|
|
553 |
log.error("Unable to get user service client.", e);
|
|
|
554 |
}
|
|
|
555 |
return false;
|
|
|
556 |
}
|
| 637 |
rajveer |
557 |
}
|