| 507 |
rajveer |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
|
|
6 |
|
| 555 |
chandransh |
7 |
import in.shop2020.model.v1.user.Phone;
|
|
|
8 |
import in.shop2020.model.v1.user.PhoneType;
|
|
|
9 |
import in.shop2020.model.v1.user.Sex;
|
|
|
10 |
import in.shop2020.model.v1.user.User;
|
| 507 |
rajveer |
11 |
import in.shop2020.model.v1.user.UserState;
|
|
|
12 |
import in.shop2020.serving.pages.PageContentKeys;
|
|
|
13 |
import in.shop2020.serving.pages.PageEnum;
|
|
|
14 |
import in.shop2020.serving.pages.PageManager;
|
| 555 |
chandransh |
15 |
import in.shop2020.serving.utils.Utils;
|
| 507 |
rajveer |
16 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
17 |
|
|
|
18 |
import java.io.IOException;
|
|
|
19 |
import java.util.Date;
|
| 555 |
chandransh |
20 |
import java.util.GregorianCalendar;
|
| 507 |
rajveer |
21 |
import java.util.HashMap;
|
| 555 |
chandransh |
22 |
import java.util.HashSet;
|
| 507 |
rajveer |
23 |
import java.util.Map;
|
| 555 |
chandransh |
24 |
import java.util.Set;
|
| 507 |
rajveer |
25 |
import java.util.StringTokenizer;
|
|
|
26 |
|
|
|
27 |
import javax.servlet.ServletContext;
|
| 555 |
chandransh |
28 |
import javax.servlet.http.Cookie;
|
| 507 |
rajveer |
29 |
|
|
|
30 |
import org.apache.juli.logging.Log;
|
|
|
31 |
import org.apache.juli.logging.LogFactory;
|
|
|
32 |
import org.apache.struts2.convention.annotation.Action;
|
|
|
33 |
import org.apache.struts2.convention.annotation.Actions;
|
|
|
34 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
35 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
36 |
import org.apache.struts2.interceptor.ParameterAware;
|
|
|
37 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
38 |
import org.apache.struts2.rest.HttpHeaders;
|
|
|
39 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
40 |
|
|
|
41 |
import com.opensymphony.xwork2.ModelDriven;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
*
|
|
|
45 |
* @author rajveer
|
|
|
46 |
*
|
|
|
47 |
*/
|
|
|
48 |
|
| 550 |
rajveer |
49 |
@Results({
|
|
|
50 |
@Result(name="success", type="redirectAction",
|
|
|
51 |
params = {"actionName" , "home"})
|
|
|
52 |
})
|
| 507 |
rajveer |
53 |
public class RegisterController extends BaseController{
|
|
|
54 |
|
|
|
55 |
private PageManager pageManager = null;
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
*
|
|
|
59 |
*/
|
|
|
60 |
private static Log log = LogFactory.getLog(RegisterController.class);
|
|
|
61 |
|
|
|
62 |
private Map<String,String> htmlSnippets;
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
public RegisterController(){
|
|
|
66 |
super();
|
|
|
67 |
pageManager = PageManager.getPageManager();
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
public HttpHeaders index() throws SecurityException, IOException {
|
|
|
72 |
Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
|
|
|
73 |
|
|
|
74 |
params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
|
|
|
75 |
params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
|
|
|
76 |
params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
|
|
|
77 |
htmlSnippets = pageManager.getPageContents(PageEnum.REGISTRATION_PAGE, params);
|
|
|
78 |
|
|
|
79 |
return new DefaultHttpHeaders("index");
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public String create() throws SecurityException, Exception {
|
|
|
83 |
|
|
|
84 |
if(registerUser())
|
|
|
85 |
return "success";
|
|
|
86 |
else
|
|
|
87 |
return "failure";
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
public boolean registerUser() throws Exception{
|
| 555 |
chandransh |
91 |
String email, password, userName, mobileNumber, communicationEmail, sex, dobDay, dobYear, dobMonth;
|
| 507 |
rajveer |
92 |
|
| 555 |
chandransh |
93 |
userName = this.request.getParameter("nameOfUser");
|
| 507 |
rajveer |
94 |
email = this.request.getParameter("email");
|
|
|
95 |
password = this.request.getParameter("password");
|
| 550 |
rajveer |
96 |
|
|
|
97 |
mobileNumber = this.request.getParameter("mobileNumber");
|
|
|
98 |
communicationEmail = this.request.getParameter("communicationEmail");
|
|
|
99 |
|
|
|
100 |
dobDay = this.request.getParameter("dobDay");
|
|
|
101 |
dobMonth = this.request.getParameter("dobMonth");
|
|
|
102 |
dobYear = this.request.getParameter("dobYear");
|
| 507 |
rajveer |
103 |
sex = this.request.getParameter("sex");
|
|
|
104 |
|
| 555 |
chandransh |
105 |
UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
|
|
|
106 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userContextServiceClient.getClient();
|
| 507 |
rajveer |
107 |
|
|
|
108 |
if(userClient.userExists(email)){
|
| 555 |
chandransh |
109 |
log.error("User Exists!!!!");
|
| 507 |
rajveer |
110 |
return false;
|
| 555 |
chandransh |
111 |
}
|
|
|
112 |
|
|
|
113 |
User user = new User();
|
|
|
114 |
user.setName(userName);
|
|
|
115 |
user.setEmail(email);
|
|
|
116 |
user.setPassword(password);
|
|
|
117 |
user.setCommunicationEmail(communicationEmail);
|
|
|
118 |
|
|
|
119 |
// if(mobileNumber!=null){
|
|
|
120 |
// Phone phone = new Phone();
|
|
|
121 |
// phone.setNumber(mobileNumber);
|
|
|
122 |
// phone.setType(PhoneType.MOBILE);
|
|
|
123 |
// Set<Phone> phones = new HashSet<Phone>();
|
|
|
124 |
// phones.add(phone);
|
|
|
125 |
// user.setPhones(phones);
|
|
|
126 |
// }
|
|
|
127 |
|
|
|
128 |
user.setSex(Sex.WONT_SAY);
|
|
|
129 |
if (sex != null) {
|
|
|
130 |
try {
|
|
|
131 |
user.setSex(Sex.findByValue(Integer.parseInt(sex)));
|
|
|
132 |
} catch (NumberFormatException nfe) {
|
|
|
133 |
log.error("Unusual value for sex. Leaving it marked as won't say.");
|
| 507 |
rajveer |
134 |
}
|
| 555 |
chandransh |
135 |
}
|
| 507 |
rajveer |
136 |
|
| 555 |
chandransh |
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 |
}
|
| 507 |
rajveer |
143 |
|
| 555 |
chandransh |
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;
|
| 507 |
rajveer |
163 |
}
|
|
|
164 |
|
|
|
165 |
public Map<String,String> getHtmlSnippets(){
|
|
|
166 |
System.out.println(" getHtmlSnippets is called");
|
|
|
167 |
return htmlSnippets;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
public String getHeaderSnippet(){
|
|
|
171 |
return htmlSnippets.get("HEADER");
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
public String getMainMenuSnippet(){
|
|
|
175 |
return htmlSnippets.get("MAIN_MENU");
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
public String getSearchBarSnippet(){
|
|
|
179 |
return htmlSnippets.get("SEARCH_BAR");
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
public String getCustomerServiceSnippet(){
|
|
|
184 |
return htmlSnippets.get("CUSTOMER_SERVICE");
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
public String getRegistrationHeaderSnippet(){
|
|
|
188 |
return htmlSnippets.get("REGISTRATION_HEADER");
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
public String getRegistrationFormSnippet(){
|
|
|
192 |
return htmlSnippets.get("REGISTRATION_FORM");
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
public String getRecommendationsSnippet(){
|
|
|
196 |
return htmlSnippets.get("RECOMMENDATIONS");
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
public String getBrowseHistorySnippet(){
|
|
|
200 |
return htmlSnippets.get("BROWSE_HISTORY");
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
public String getFooterSnippet(){
|
|
|
204 |
return htmlSnippets.get("FOOTER");
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
public String getJsFileSnippet(){
|
|
|
208 |
return htmlSnippets.get("JS_FILES");
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
public String getCssFileSnippet(){
|
|
|
212 |
return htmlSnippets.get("CSS_FILES");
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
}
|