Subversion Repositories SmartDukaan

Rev

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

Rev 1044 Rev 1175
Line 3... Line 3...
3
 */
3
 */
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
6
import in.shop2020.model.v1.user.User;
6
import in.shop2020.model.v1.user.User;
7
import in.shop2020.serving.utils.DesEncrypter;
7
import in.shop2020.serving.utils.DesEncrypter;
-
 
8
import in.shop2020.serving.utils.UserMessage;
8
import in.shop2020.thrift.clients.UserContextServiceClient;
9
import in.shop2020.thrift.clients.UserContextServiceClient;
9
 
10
 
10
import java.io.IOException;
11
import java.io.IOException;
11
import java.util.Date;
12
import java.util.Date;
12
 
13
 
Line 51... Line 52...
51
	public String create() throws SecurityException, Exception {
52
	public String create() throws SecurityException, Exception {
52
		if (loginUser()) {
53
		if (loginUser()) {
53
			log.info(redirectUrl);
54
			log.info(redirectUrl);
54
			return "redirect";
55
			return "redirect";
55
		} else {
56
		} else {
56
			addActionError("Either email or password is wrong.");
57
			addActionError(UserMessage.USER_AUTHENTICATION_FAILURE);
57
			return "login";
58
			return "login";
58
		}
59
		}
59
	}
60
	}
60
 
61
 
61
	private boolean loginUser() {
62
	private boolean loginUser() {
Line 81... Line 82...
81
			userinfo.setNameOfUser(user.getName());
82
			userinfo.setNameOfUser(user.getName());
82
			userinfo.setEmail(email);
83
			userinfo.setEmail(email);
83
			userinfo.setLoggedIn(true);
84
			userinfo.setLoggedIn(true);
84
			userinfo.setPincode(pincode);
85
			userinfo.setPincode(pincode);
85
 
86
 
86
			// TODO: setTotalItems shouldn't be a method on userinfo. This
87
			// TODO: setTotalItems shouldn't be a method on userinfo. This allows
87
			// allows
-
 
88
			// for potentially updating the item count wrongly. The method
88
			// for potentially updating the item count wrongly. The method setCartId
89
			// setCartId
-
 
90
			// should update the item count as well. Also, there can be a method
89
			// should update the item count as well. Also, there can be a method
91
			// called refreshItemCount() that automatically updates the number
90
			// called refreshItemCount() that automatically updates the number of
92
			// of
-
 
93
			// items currently in the cart.
91
			// items currently in the cart.
94
			userClient.mergeCart(userinfo.getCartId(), user.getActiveCartId());
92
			userClient.mergeCart(userinfo.getCartId(), user.getActiveCartId());
95
			userinfo.setCartId(user.getActiveCartId());
93
			userinfo.setCartId(user.getActiveCartId());
96
			int totalItems = userClient.getCart(user.getActiveCartId())
94
			int totalItems = userClient.getCart(user.getActiveCartId())
97
					.getLinesSize();
95
					.getLinesSize();
98
			userinfo.setTotalItems(totalItems);
96
			userinfo.setTotalItems(totalItems);
99
 
97
 
100
			return true;
98
			return true;
101
		} catch (Exception e) {
99
		} catch (Exception e) {
102
			log.error("Wrong username or password.");
100
			log.error(UserMessage.USER_AUTHENTICATION_FAILURE);
103
			return false;
101
			return false;
104
		}
102
		}
105
	}
103
	}
106
 
104
 
107
	public String getRedirectUrl() {
105
	public String getRedirectUrl() {