| Line 2... |
Line 2... |
| 2 |
*
|
2 |
*
|
| 3 |
*/
|
3 |
*/
|
| 4 |
package in.shop2020.serving.controllers;
|
4 |
package in.shop2020.serving.controllers;
|
| 5 |
|
5 |
|
| 6 |
|
6 |
|
| 7 |
import in.shop2020.model.v1.user.UserContext;
|
7 |
import in.shop2020.model.v1.user.Phone;
|
| - |
|
8 |
import in.shop2020.model.v1.user.PhoneType;
|
| - |
|
9 |
import in.shop2020.model.v1.user.Sex;
|
| 8 |
import in.shop2020.model.v1.user.UserPrimaryInfo;
|
10 |
import in.shop2020.model.v1.user.User;
|
| 9 |
import in.shop2020.model.v1.user.UserState;
|
11 |
import in.shop2020.model.v1.user.UserState;
|
| 10 |
import in.shop2020.serving.pages.PageContentKeys;
|
12 |
import in.shop2020.serving.pages.PageContentKeys;
|
| 11 |
import in.shop2020.serving.pages.PageEnum;
|
13 |
import in.shop2020.serving.pages.PageEnum;
|
| 12 |
import in.shop2020.serving.pages.PageManager;
|
14 |
import in.shop2020.serving.pages.PageManager;
|
| - |
|
15 |
import in.shop2020.serving.utils.Utils;
|
| 13 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
16 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
| 14 |
|
17 |
|
| 15 |
import java.io.IOException;
|
18 |
import java.io.IOException;
|
| 16 |
import java.util.Date;
|
19 |
import java.util.Date;
|
| - |
|
20 |
import java.util.GregorianCalendar;
|
| 17 |
import java.util.HashMap;
|
21 |
import java.util.HashMap;
|
| - |
|
22 |
import java.util.HashSet;
|
| 18 |
import java.util.Map;
|
23 |
import java.util.Map;
|
| - |
|
24 |
import java.util.Set;
|
| 19 |
import java.util.StringTokenizer;
|
25 |
import java.util.StringTokenizer;
|
| 20 |
|
26 |
|
| 21 |
import javax.servlet.ServletContext;
|
27 |
import javax.servlet.ServletContext;
|
| - |
|
28 |
import javax.servlet.http.Cookie;
|
| 22 |
|
29 |
|
| 23 |
import org.apache.juli.logging.Log;
|
30 |
import org.apache.juli.logging.Log;
|
| 24 |
import org.apache.juli.logging.LogFactory;
|
31 |
import org.apache.juli.logging.LogFactory;
|
| 25 |
import org.apache.struts2.convention.annotation.Action;
|
32 |
import org.apache.struts2.convention.annotation.Action;
|
| 26 |
import org.apache.struts2.convention.annotation.Actions;
|
33 |
import org.apache.struts2.convention.annotation.Actions;
|
| Line 64... |
Line 71... |
| 64 |
public HttpHeaders index() throws SecurityException, IOException {
|
71 |
public HttpHeaders index() throws SecurityException, IOException {
|
| 65 |
Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
|
72 |
Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
|
| 66 |
|
73 |
|
| 67 |
params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
|
74 |
params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
|
| 68 |
params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
|
75 |
params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
|
| 69 |
params.put(PageContentKeys.SESSION_ID, new Long(userinfo.getSessionId()).toString());
|
- |
|
| 70 |
params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
|
76 |
params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
|
| 71 |
htmlSnippets = pageManager.getPageContents(PageEnum.REGISTRATION_PAGE, params);
|
77 |
htmlSnippets = pageManager.getPageContents(PageEnum.REGISTRATION_PAGE, params);
|
| 72 |
|
78 |
|
| 73 |
return new DefaultHttpHeaders("index");
|
79 |
return new DefaultHttpHeaders("index");
|
| 74 |
}
|
80 |
}
|
| Line 80... |
Line 86... |
| 80 |
else
|
86 |
else
|
| 81 |
return "failure";
|
87 |
return "failure";
|
| 82 |
}
|
88 |
}
|
| 83 |
|
89 |
|
| 84 |
public boolean registerUser() throws Exception{
|
90 |
public boolean registerUser() throws Exception{
|
| 85 |
String email, password, nameOfUser, mobileNumber, communicationEmail, sex, dobDay, dobYear, dobMonth;
|
91 |
String email, password, userName, mobileNumber, communicationEmail, sex, dobDay, dobYear, dobMonth;
|
| 86 |
|
92 |
|
| 87 |
nameOfUser = this.request.getParameter("nameOfUser");
|
93 |
userName = this.request.getParameter("nameOfUser");
|
| 88 |
email = this.request.getParameter("email");
|
94 |
email = this.request.getParameter("email");
|
| 89 |
password = this.request.getParameter("password");
|
95 |
password = this.request.getParameter("password");
|
| 90 |
|
96 |
|
| 91 |
mobileNumber = this.request.getParameter("mobileNumber");
|
97 |
mobileNumber = this.request.getParameter("mobileNumber");
|
| 92 |
communicationEmail = this.request.getParameter("communicationEmail");
|
98 |
communicationEmail = this.request.getParameter("communicationEmail");
|
| 93 |
|
99 |
|
| 94 |
dobDay = this.request.getParameter("dobDay");
|
100 |
dobDay = this.request.getParameter("dobDay");
|
| 95 |
dobMonth = this.request.getParameter("dobMonth");
|
101 |
dobMonth = this.request.getParameter("dobMonth");
|
| 96 |
dobYear = this.request.getParameter("dobYear");
|
102 |
dobYear = this.request.getParameter("dobYear");
|
| 97 |
sex = this.request.getParameter("sex");
|
103 |
sex = this.request.getParameter("sex");
|
| 98 |
|
- |
|
| 99 |
|
104 |
|
| 100 |
UserContextServiceClient userContextServiceClient = null;
|
105 |
UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
|
| 101 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
106 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
| 102 |
|
- |
|
| 103 |
userContextServiceClient = new UserContextServiceClient();
|
- |
|
| 104 |
userClient = userContextServiceClient.getClient();
|
- |
|
| 105 |
|
107 |
|
| 106 |
if(userClient.userExists(email)){
|
108 |
if(userClient.userExists(email)){
|
| - |
|
109 |
log.error("User Exists!!!!");
|
| 107 |
return false;
|
110 |
return false;
|
| 108 |
}else{
|
111 |
}
|
| - |
|
112 |
|
| 109 |
UserContext context = new UserContext();
|
113 |
User user = new User();
|
| - |
|
114 |
user.setName(userName);
|
| - |
|
115 |
user.setEmail(email);
|
| - |
|
116 |
user.setPassword(password);
|
| 110 |
UserPrimaryInfo primaryInfo = new UserPrimaryInfo();
|
117 |
user.setCommunicationEmail(communicationEmail);
|
| - |
|
118 |
|
| - |
|
119 |
// if(mobileNumber!=null){
|
| 111 |
UserState userState = new UserState();
|
120 |
// Phone phone = new Phone();
|
| 112 |
// set the data
|
121 |
// phone.setNumber(mobileNumber);
|
| 113 |
primaryInfo.setPassword(password);
|
122 |
// phone.setType(PhoneType.MOBILE);
|
| - |
|
123 |
// Set<Phone> phones = new HashSet<Phone>();
|
| - |
|
124 |
// phones.add(phone);
|
| 114 |
primaryInfo.setEmail(email);
|
125 |
// user.setPhones(phones);
|
| - |
|
126 |
// }
|
| 115 |
|
127 |
|
| - |
|
128 |
user.setSex(Sex.WONT_SAY);
|
| - |
|
129 |
if (sex != null) {
|
| - |
|
130 |
try {
|
| 116 |
if(dobDay != null && dobYear != null && dobMonth != null){
|
131 |
user.setSex(Sex.findByValue(Integer.parseInt(sex)));
|
| - |
|
132 |
} catch (NumberFormatException nfe) {
|
| 117 |
primaryInfo.setDateOfBirth((new Date(Integer.parseInt(dobYear), Integer.parseInt(dobMonth), Integer.parseInt(dobDay))).getTime());
|
133 |
log.error("Unusual value for sex. Leaving it marked as won't say.");
|
| 118 |
}
|
134 |
}
|
| 119 |
|
- |
|
| 120 |
context.setPrimaryInfo(primaryInfo);
|
- |
|
| 121 |
context.setUserState(userState);
|
- |
|
| 122 |
|
- |
|
| 123 |
context = userClient.createContext(context, false);
|
- |
|
| 124 |
|
- |
|
| 125 |
|
- |
|
| 126 |
//TODO to verify weather user should be logged in with registration
|
- |
|
| 127 |
|
- |
|
| 128 |
long userId = context.getId();
|
- |
|
| 129 |
|
- |
|
| 130 |
userClient.setUserAsLoggedIn(userId, (new Date()).getTime());
|
- |
|
| 131 |
|
- |
|
| 132 |
this.userinfo.setUserId(userId);
|
- |
|
| 133 |
this.userinfo.setEmail(email);
|
- |
|
| 134 |
this.userinfo.setLoggedIn(true);
|
- |
|
| 135 |
|
- |
|
| 136 |
return true;
|
- |
|
| 137 |
}
|
135 |
}
|
| - |
|
136 |
|
| - |
|
137 |
if (dobDay != null && dobYear != null && dobMonth != null) {
|
| - |
|
138 |
GregorianCalendar dateOfBirth = new GregorianCalendar(
|
| - |
|
139 |
Integer.parseInt(dobYear), Integer.parseInt(dobMonth),
|
| - |
|
140 |
Integer.parseInt(dobDay));
|
| - |
|
141 |
user.setDateOfBirth(dateOfBirth.getTimeInMillis());
|
| - |
|
142 |
}
|
| - |
|
143 |
|
| - |
|
144 |
user = userClient.createUser(user);
|
| - |
|
145 |
long userId = user.getUserId();
|
| - |
|
146 |
userClient.setUserAsLoggedIn(userId, (new Date()).getTime());
|
| - |
|
147 |
|
| - |
|
148 |
userinfo.setUserId(userId);
|
| - |
|
149 |
userinfo.setNameOfUser(userName);
|
| - |
|
150 |
userinfo.setEmail(email);
|
| - |
|
151 |
userinfo.setLoggedIn(true);
|
| - |
|
152 |
|
| - |
|
153 |
// TODO: setTotalItems shouldn't be a method on userinfo. This allows
|
| - |
|
154 |
// for potentially updating the item count wrongly. The method setCartId
|
| - |
|
155 |
// should update the item count as well. Also, there can be a method
|
| - |
|
156 |
// called refreshItemCount() that automatically updates the number of
|
| - |
|
157 |
// items currently in the cart.
|
| - |
|
158 |
userClient.mergeCart(userinfo.getCartId(), user.getActiveCartId());
|
| - |
|
159 |
userinfo.setCartId(user.getActiveCartId());
|
| - |
|
160 |
userinfo.setTotalItems(Utils.getNumberOfItemsInCart(userinfo.getCartId()));
|
| - |
|
161 |
|
| - |
|
162 |
return true;
|
| 138 |
}
|
163 |
}
|
| 139 |
|
164 |
|
| 140 |
public Map<String,String> getHtmlSnippets(){
|
165 |
public Map<String,String> getHtmlSnippets(){
|
| 141 |
System.out.println(" getHtmlSnippets is called");
|
166 |
System.out.println(" getHtmlSnippets is called");
|
| 142 |
return htmlSnippets;
|
167 |
return htmlSnippets;
|