Subversion Repositories SmartDukaan

Rev

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

Rev 12616 Rev 20202
Line 28... Line 28...
28
import org.apache.log4j.Logger;
28
import org.apache.log4j.Logger;
29
import org.apache.struts2.convention.annotation.Result;
29
import org.apache.struts2.convention.annotation.Result;
30
import org.apache.struts2.convention.annotation.Results;
30
import org.apache.struts2.convention.annotation.Results;
31
import org.apache.thrift.TException;
31
import org.apache.thrift.TException;
32
import org.apache.thrift.transport.TTransportException;
32
import org.apache.thrift.transport.TTransportException;
-
 
33
import org.json.JSONObject;
33
 
34
 
34
/**
35
/**
35
 * 
36
 * 
36
 * @author rajveer
37
 * @author rajveer
37
 *
38
 *
Line 48... Line 49...
48
	private static final long serialVersionUID = 1L;
49
	private static final long serialVersionUID = 1L;
49
	private static Logger log = Logger.getLogger(Class.class);
50
	private static Logger log = Logger.getLogger(Class.class);
50
	private DesEncrypter desEncrypter = new DesEncrypter("saholic");
51
	private DesEncrypter desEncrypter = new DesEncrypter("saholic");
51
	
52
	
52
	private String redirectUrl = "/";
53
	private String redirectUrl = "/";
53
 
-
 
-
 
54
	private String registerJson = "{}";
54
	public RegisterController(){
55
	public RegisterController(){
55
		super();
56
		super();
56
	}
57
	}
57
 
58
 
58
    public String index() throws SecurityException, IOException {
59
    public String index() throws SecurityException, IOException {
Line 64... Line 65...
64
    	return "redirect-to-login";
65
    	return "redirect-to-login";
65
    }
66
    }
66
 
67
 
67
    public String create() throws SecurityException, Exception {
68
    public String create() throws SecurityException, Exception {
68
    	
69
    	
69
    	if(registerUser())
70
    		registerUser();
70
    		return "redirect";
71
    		return "register-response";
71
    	else
72
    	//else
72
    		return "failure";
73
    	//	return "failure";
73
    }
74
    }
74
    
75
    
75
    public boolean registerUser(){
76
    public boolean registerUser(){
76
    	String email, password;
77
    	String email, password;
77
    	boolean isValid = true;
78
    	boolean isValid = true;
-
 
79
    	JSONObject json = new JSONObject();
-
 
80
    	String errorMessage = "{\"status\":\"error\",\"message\":\"Some Problem occurred. Please try again.\"}";
78
    	email = this.request.getParameter("email"); 
81
    	email = this.request.getParameter("email"); 
79
    	password = this.request.getParameter("txtPassword");
82
    	password = this.request.getParameter("txtPassword");
80
    	
83
    	try{
81
    	if(!Utils.isValidEmail(email))	{
84
    	if(!Utils.isValidEmail(email))	{
82
    		addActionError("Please enter valid email address.");
85
    		addActionError("Please enter valid email address.");
-
 
86
    		json.put("message", "Please enter valid email address.");
-
 
87
    		json.put("status", "error");
83
    		isValid = false;
88
    		isValid = false;
84
        }
89
        }
85
    	if(password == null )	{
90
    	if(password == null )	{
86
    		addActionError("Please enter password.");
91
    		addActionError("Please enter password.");
-
 
92
    		json.put("message", "Please enter password.");
-
 
93
    		json.put("status", "error");
87
    		isValid = false;
94
    		isValid = false;
88
        }
95
        }
89
    	
96
    	
90
    	if(!isValid){
97
    	if(!isValid){
-
 
98
    		setRegisterJson(json.toString());
91
//    	    DataLogger.logData(EventType.REGISTER_DATA_INCOMPLETE, getSessionId(), userinfo.getUserId(), email, "", email);
99
//    	    DataLogger.logData(EventType.REGISTER_DATA_INCOMPLETE, getSessionId(), userinfo.getUserId(), email, "", email);
92
    		return isValid;
100
    		return isValid;
93
    	}
101
    	}
94
    	
102
    	
95
		User user = new User();
103
		User user = new User();
Line 126... Line 134...
126
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
134
			in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
127
			try{
135
			try{
128
				user = userClient.createUser(user);
136
				user = userClient.createUser(user);
129
			}catch (UserContextException ux){
137
			}catch (UserContextException ux){
130
				addActionError("User already exists with this email id.");
138
				addActionError("User already exists with this email id.");
-
 
139
				json.put("message", "You are already a member. Please login.");
-
 
140
				json.put("status", "error");
-
 
141
				
-
 
142
				setRegisterJson(json.toString());
131
//				DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
143
//				DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
132
				return false;				
144
				return false;				
133
			}
145
			}
134
			
146
			
135
			long userId = user.getUserId();
147
			long userId = user.getUserId();
Line 172... Line 184...
172
	        if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
184
	        if (cookiesMap.containsKey(TrackingInterceptor.AFF_COOKIE)) {
173
	            long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
185
	            long affId = Long.parseLong(cookiesMap.get(TrackingInterceptor.AFF_COOKIE).getValue());
174
	            userClient.addTrackLog(affId, userId, TrackLogType.NEW_REGISTRATION, "",email, (new Date()).getTime());
186
	            userClient.addTrackLog(affId, userId, TrackLogType.NEW_REGISTRATION, "",email, (new Date()).getTime());
175
	        }
187
	        }
176
//	        DataLogger.logData(EventType.REGISTER_SUCCESS, getSessionId(), userinfo.getUserId(), email, "", email);
188
//	        DataLogger.logData(EventType.REGISTER_SUCCESS, getSessionId(), userinfo.getUserId(), email, "", email);
-
 
189
	        json.put("message", "Register successful");
-
 
190
			json.put("status", "success");
177
	
191
			
-
 
192
			setRegisterJson(json.toString());
178
			return true;
193
			return true;
179
		} catch (TTransportException e) {
194
		} catch (TTransportException e) {
180
			log.error("Unable to register user." + e);
195
			log.error("Unable to register user." + e);
-
 
196
			setRegisterJson(errorMessage);
181
		} catch (UserContextException e) {
197
		} catch (UserContextException e) {
182
			log.error("Unable to register user." + e);
198
			log.error("Unable to register user." + e);
-
 
199
			setRegisterJson(errorMessage);
183
		} catch (TException e) {
200
		} catch (TException e) {
184
			log.error("Unable to register user." + e);
201
			log.error("Unable to register user." + e);
-
 
202
			setRegisterJson(errorMessage);
185
		} catch (UserAffiliateException e) {
203
		} catch (UserAffiliateException e) {
186
			log.error("Unable to register user." + e);
204
			log.error("Unable to register user." + e);
-
 
205
			setRegisterJson(errorMessage);
187
		} catch (ShoppingCartException e) {
206
		} catch (ShoppingCartException e) {
188
			log.error("Unable to register user." + e);
207
			log.error("Unable to register user." + e);
-
 
208
			setRegisterJson(errorMessage);
189
		} catch (WidgetException e) {
209
		} catch (WidgetException e) {
190
			log.error("Unable to register user." + e);
210
			log.error("Unable to register user." + e);
-
 
211
			setRegisterJson(errorMessage);
191
		}
212
		}
-
 
213
    	}catch(Exception e){
-
 
214
    		log.error("Unable to register user." + e);
-
 
215
    		setRegisterJson(errorMessage);
-
 
216
    	}
192
//		DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
217
//		DataLogger.logData(EventType.REGISTER_FAILED_USER_EXISTS, getSessionId(), userinfo.getUserId(), email, "", email);
193
		return false;
218
		return false;
194
		
219
		
195
    }
220
    }
196
 
221
 
Line 207... Line 232...
207
 
232
 
208
	public void setRedirectUrl(String redirectUrl) {
233
	public void setRedirectUrl(String redirectUrl) {
209
		this.redirectUrl = redirectUrl;
234
		this.redirectUrl = redirectUrl;
210
	}
235
	}
211
	
236
	
-
 
237
	
-
 
238
	
-
 
239
	public String getRegisterJson() {
-
 
240
		return registerJson;
-
 
241
	}
-
 
242
 
-
 
243
	public void setRegisterJson(String registerJson) {
-
 
244
		this.registerJson = registerJson;
-
 
245
	}
-
 
246
 
212
	private boolean isPrivateDealUser() throws TTransportException, TException{
247
	private boolean isPrivateDealUser() throws TTransportException, TException{
213
		try {
248
		try {
214
			in.shop2020.model.v1.user.UserContextService.Client uc = new UserClient().getClient();
249
			in.shop2020.model.v1.user.UserContextService.Client uc = new UserClient().getClient();
215
			return uc.isPrivateDealUser(userinfo.getUserId());
250
			return uc.isPrivateDealUser(userinfo.getUserId());
216
		} catch (TTransportException e) {
251
		} catch (TTransportException e) {