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