Subversion Repositories SmartDukaan

Rev

Rev 4911 | Rev 5041 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4911 Rev 5036
Line 5... Line 5...
5
 
5
 
6
 
6
 
7
import in.shop2020.datalogger.EventType;
7
import in.shop2020.datalogger.EventType;
8
import in.shop2020.model.v1.user.Cart;
8
import in.shop2020.model.v1.user.Cart;
9
import in.shop2020.model.v1.user.Sex;
9
import in.shop2020.model.v1.user.Sex;
-
 
10
import in.shop2020.model.v1.user.ShoppingCartException;
10
import in.shop2020.model.v1.user.TrackLogType;
11
import in.shop2020.model.v1.user.TrackLogType;
11
import in.shop2020.model.v1.user.User;
12
import in.shop2020.model.v1.user.User;
-
 
13
import in.shop2020.model.v1.user.UserAffiliateException;
-
 
14
import in.shop2020.model.v1.user.UserContextException;
-
 
15
import in.shop2020.model.v1.user.WidgetException;
12
import in.shop2020.serving.interceptors.TrackingInterceptor;
16
import in.shop2020.serving.interceptors.TrackingInterceptor;
13
import in.shop2020.serving.utils.DesEncrypter;
17
import in.shop2020.serving.utils.DesEncrypter;
14
import in.shop2020.serving.utils.Utils;
18
import in.shop2020.serving.utils.Utils;
15
import in.shop2020.thrift.clients.UserClient;
19
import in.shop2020.thrift.clients.UserClient;
16
import in.shop2020.utils.DataLogger;
20
import in.shop2020.utils.DataLogger;
Line 22... Line 26...
22
import javax.servlet.http.Cookie;
26
import javax.servlet.http.Cookie;
23
 
27
 
24
import org.apache.log4j.Logger;
28
import org.apache.log4j.Logger;
25
import org.apache.struts2.convention.annotation.Result;
29
import org.apache.struts2.convention.annotation.Result;
26
import org.apache.struts2.convention.annotation.Results;
30
import org.apache.struts2.convention.annotation.Results;
-
 
31
import org.apache.thrift.TException;
-
 
32
import org.apache.thrift.transport.TTransportException;
27
 
33
 
28
/**
34
/**
29
 * 
35
 * 
30
 * @author rajveer
36
 * @author rajveer
31
 *
37
 *
Line 64... Line 70...
64
    		return "redirect";
70
    		return "redirect";
65
    	else
71
    	else
66
    		return "failure";
72
    		return "failure";
67
    }
73
    }
68
    
74
    
69
    public boolean registerUser() throws Exception{
75
    public boolean registerUser(){
70
    	String email, password;
76
    	String email, password;
71
    	boolean isValid = true;
77
    	boolean isValid = true;
72
    	email = this.request.getParameter("email"); 
78
    	email = this.request.getParameter("email"); 
73
    	password = this.request.getParameter("txtPassword");
79
    	password = this.request.getParameter("txtPassword");
74
    	
80
    	
Line 84... Line 90...
84
    	if(!isValid){
90
    	if(!isValid){
85
    	    DataLogger.logData(EventType.REGISTER_DATA_INCOMPLETE, getSessionId(), userinfo.getUserId(), email, "", email);
91
    	    DataLogger.logData(EventType.REGISTER_DATA_INCOMPLETE, getSessionId(), userinfo.getUserId(), email, "", email);
86
    		return isValid;
92
    		return isValid;
87
    	}
93
    	}
88
    	
94
    	
89
		UserClient userContextServiceClient = new UserClient();
-
 
90
		in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
-
 
91
 
-
 
92
		if(userClient.userExists(email)){
-
 
93
			addActionError("User already exists with this email id.");
-
 
94
			DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
-
 
95
			return false;
-
 
96
		}
-
 
97
 
-
 
98
		User user = new User();
95
		User user = new User();
99
		user.setEmail(email);
96
		user.setEmail(email);
100
		String encryptedPassword = desEncrypter.encrypt(password);
97
		String encryptedPassword = desEncrypter.encrypt(password);
101
		user.setPassword(encryptedPassword);
98
		user.setPassword(encryptedPassword);
102
		user.setCommunicationEmail(email);
99
		user.setCommunicationEmail(email);
Line 120... Line 117...
120
        }
117
        }
121
		
118
		
122
		user.setSex(Sex.WONT_SAY);
119
		user.setSex(Sex.WONT_SAY);
123
		
120
		
124
 
121
 
125
		user = userClient.createUser(user);
122
		UserClient userContextServiceClient;
126
		long userId = user.getUserId();
123
		try {
127
		userClient.setUserAsLoggedIn(userId, (new Date()).getTime());
124
			userContextServiceClient = new UserClient();
128
		String pincode = userClient.getDefaultPincode(user.getUserId());
-
 
129
		
125
		
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.
-
 
135
		if(userinfo.getUserId() != -1){
-
 
136
			userClient.mergeCart(userinfo.getCartId(), user.getActiveCartId());
126
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
137
		
127
			try{
138
			List<Long> items = userClient.getBrowseHistoryItems(userinfo.getUserId());
128
				user = userClient.createUser(user);
139
			if(items != null){
129
			}catch (UserContextException ux){
140
				for(Long itemId: items){
130
				addActionError("User already exists with this email id.");
141
					userClient.updateBrowseHistory(user.getUserId(), itemId);
131
				DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
142
				}
132
				return false;				
143
			}
133
			}
-
 
134
			
-
 
135
			long userId = user.getUserId();
-
 
136
			userClient.setUserAsLoggedIn(userId, (new Date()).getTime());
-
 
137
			String pincode = userClient.getDefaultPincode(user.getUserId());
144
		
138
		
-
 
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
					}
-
 
152
				}
-
 
153
			
145
			items = userClient.getMyResearchItems(userinfo.getUserId());
154
				items = userClient.getMyResearchItems(userinfo.getUserId());
146
			if(items != null){
155
				if(items != null){
147
				for(Long itemId: items){
156
					for(Long itemId: items){
148
					userClient.updateMyResearch(user.getUserId(), itemId);
157
						userClient.updateMyResearch(user.getUserId(), itemId);
-
 
158
					}
149
				}
159
				}
150
			}
160
			}
-
 
161
			
-
 
162
			userinfo.setUserId(userId);
-
 
163
			userinfo.setEmail(email);
-
 
164
			userinfo.setLoggedIn(true);
-
 
165
			userinfo.setPincode(pincode);
-
 
166
			userinfo.setCartId(user.getActiveCartId());
-
 
167
			Cart cart = userClient.getCart(userinfo.getCartId());
-
 
168
			userinfo.setTotalItems(cart.getLinesSize());
-
 
169
			userinfo.setTotalAmount(cart.getTotalPrice());
-
 
170
			
-
 
171
	        if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
-
 
172
	            long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
-
 
173
	            userClient.addTrackLog(affId, userId, TrackLogType.NEW_REGISTRATION, "",email, (new Date()).getTime());
-
 
174
	        }
-
 
175
	        DataLogger.logData(EventType.REGISTER_SUCCESS, getSessionId(), userinfo.getUserId(), email, "", email);
-
 
176
	
-
 
177
			return true;
-
 
178
		} catch (TTransportException e) {
-
 
179
			// TODO Auto-generated catch block
-
 
180
			e.printStackTrace();
-
 
181
		} catch (UserContextException e) {
-
 
182
			// TODO Auto-generated catch block
-
 
183
			e.printStackTrace();
-
 
184
		} catch (TException e) {
-
 
185
			// TODO Auto-generated catch block
-
 
186
			e.printStackTrace();
-
 
187
		} catch (UserAffiliateException e) {
-
 
188
			// TODO Auto-generated catch block
-
 
189
			e.printStackTrace();
-
 
190
		} catch (ShoppingCartException e) {
-
 
191
			// TODO Auto-generated catch block
-
 
192
			e.printStackTrace();
-
 
193
		} catch (WidgetException e) {
-
 
194
			// TODO Auto-generated catch block
-
 
195
			e.printStackTrace();
151
		}
196
		}
-
 
197
		return false;
152
		
198
		
153
		userinfo.setUserId(userId);
-
 
154
		userinfo.setEmail(email);
-
 
155
		userinfo.setLoggedIn(true);
-
 
156
		userinfo.setPincode(pincode);
-
 
157
		userinfo.setCartId(user.getActiveCartId());
-
 
158
		Cart cart = userClient.getCart(userinfo.getCartId());
-
 
159
		userinfo.setTotalItems(cart.getLinesSize());
-
 
160
		userinfo.setTotalAmount(cart.getTotalPrice());
-
 
161
		
-
 
162
        if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
-
 
163
            long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
-
 
164
            userClient.addTrackLog(affId, userId, TrackLogType.NEW_REGISTRATION, "",email, (new Date()).getTime());
-
 
165
        }
-
 
166
        DataLogger.logData(EventType.REGISTER_SUCCESS, getSessionId(), userinfo.getUserId(), email, "", email);
-
 
167
 
-
 
168
		return true;
-
 
169
    }
199
    }
170
 
200
 
171
	public String getRegistrationHeaderSnippet(){
201
	public String getRegistrationHeaderSnippet(){
172
		return htmlSnippets.get("REGISTRATION_HEADER");
202
		return htmlSnippets.get("REGISTRATION_HEADER");
173
	}
203
	}