| 507 |
rajveer |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
import in.shop2020.model.v1.user.UserContext;
|
|
|
8 |
import in.shop2020.model.v1.user.UserPrimaryInfo;
|
|
|
9 |
import in.shop2020.model.v1.user.UserState;
|
|
|
10 |
import in.shop2020.serving.pages.PageContentKeys;
|
|
|
11 |
import in.shop2020.serving.pages.PageEnum;
|
|
|
12 |
import in.shop2020.serving.pages.PageManager;
|
|
|
13 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
|
|
14 |
|
|
|
15 |
import java.io.IOException;
|
|
|
16 |
import java.util.Date;
|
|
|
17 |
import java.util.HashMap;
|
|
|
18 |
import java.util.Map;
|
|
|
19 |
import java.util.StringTokenizer;
|
|
|
20 |
|
|
|
21 |
import javax.servlet.ServletContext;
|
|
|
22 |
|
|
|
23 |
import org.apache.juli.logging.Log;
|
|
|
24 |
import org.apache.juli.logging.LogFactory;
|
|
|
25 |
import org.apache.struts2.convention.annotation.Action;
|
|
|
26 |
import org.apache.struts2.convention.annotation.Actions;
|
|
|
27 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
28 |
import org.apache.struts2.convention.annotation.Results;
|
|
|
29 |
import org.apache.struts2.interceptor.ParameterAware;
|
|
|
30 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
|
|
31 |
import org.apache.struts2.rest.HttpHeaders;
|
|
|
32 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
33 |
|
|
|
34 |
import com.opensymphony.xwork2.ModelDriven;
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
*
|
|
|
38 |
* @author rajveer
|
|
|
39 |
*
|
|
|
40 |
*/
|
|
|
41 |
|
|
|
42 |
public class RegisterController extends BaseController{
|
|
|
43 |
|
|
|
44 |
private PageManager pageManager = null;
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
*
|
|
|
48 |
*/
|
|
|
49 |
private static Log log = LogFactory.getLog(RegisterController.class);
|
|
|
50 |
|
|
|
51 |
private Map<String,String> htmlSnippets;
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
public RegisterController(){
|
|
|
55 |
super();
|
|
|
56 |
pageManager = PageManager.getPageManager();
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
public HttpHeaders index() throws SecurityException, IOException {
|
|
|
61 |
Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
|
|
|
62 |
|
|
|
63 |
params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
|
|
|
64 |
params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
|
|
|
65 |
params.put(PageContentKeys.SESSION_ID, new Long(userinfo.getSessionId()).toString());
|
|
|
66 |
params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
|
|
|
67 |
htmlSnippets = pageManager.getPageContents(PageEnum.REGISTRATION_PAGE, params);
|
|
|
68 |
|
|
|
69 |
return new DefaultHttpHeaders("index");
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
public String create() throws SecurityException, Exception {
|
|
|
73 |
|
|
|
74 |
if(registerUser())
|
|
|
75 |
return "success";
|
|
|
76 |
else
|
|
|
77 |
return "failure";
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
public boolean registerUser() throws Exception{
|
|
|
81 |
String email, password, nameOfUser, sex, dobDay, dobYear, dobMonth;
|
|
|
82 |
|
|
|
83 |
email = this.request.getParameter("email");
|
|
|
84 |
password = this.request.getParameter("password");
|
|
|
85 |
nameOfUser = this.request.getParameter("nameofuser");
|
|
|
86 |
dobDay = this.request.getParameter("dobday");
|
|
|
87 |
dobMonth = this.request.getParameter("dobmonth");
|
|
|
88 |
dobYear = this.request.getParameter("dobyear");
|
|
|
89 |
sex = this.request.getParameter("sex");
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
UserContextServiceClient userContextServiceClient = null;
|
|
|
93 |
in.shop2020.model.v1.user.UserContextService.Client userClient = null;
|
|
|
94 |
|
|
|
95 |
userContextServiceClient = new UserContextServiceClient();
|
|
|
96 |
userClient = userContextServiceClient.getClient();
|
|
|
97 |
|
|
|
98 |
if(userClient.userExists(email)){
|
|
|
99 |
return false;
|
|
|
100 |
}else{
|
|
|
101 |
UserContext context = new UserContext();
|
|
|
102 |
UserPrimaryInfo primaryInfo = new UserPrimaryInfo();
|
|
|
103 |
UserState userState = new UserState();
|
|
|
104 |
// set the data
|
|
|
105 |
primaryInfo.setPassword(password);
|
|
|
106 |
primaryInfo.setEmail(email);
|
|
|
107 |
|
|
|
108 |
if(dobDay != null && dobYear != null && dobMonth != null){
|
|
|
109 |
primaryInfo.setDateOfBirth((new Date(Integer.parseInt(dobYear), Integer.parseInt(dobMonth), Integer.parseInt(dobDay))).getTime());
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
context.setPrimaryInfo(primaryInfo);
|
|
|
113 |
context.setUserState(userState);
|
|
|
114 |
|
|
|
115 |
context = userClient.createContext(context, false);
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
//TODO to verify weather user should be logged in with registration
|
|
|
119 |
|
|
|
120 |
long userId = context.getId();
|
|
|
121 |
|
|
|
122 |
userClient.setUserAsLoggedIn(userId, (new Date()).getTime());
|
|
|
123 |
|
|
|
124 |
this.userinfo.setUserId(userId);
|
|
|
125 |
this.userinfo.setEmail(email);
|
|
|
126 |
this.userinfo.setLoggedIn(true);
|
|
|
127 |
|
|
|
128 |
return true;
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
public Map<String,String> getHtmlSnippets(){
|
|
|
133 |
System.out.println(" getHtmlSnippets is called");
|
|
|
134 |
return htmlSnippets;
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
public String getHeaderSnippet(){
|
|
|
138 |
return htmlSnippets.get("HEADER");
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
public String getMainMenuSnippet(){
|
|
|
142 |
return htmlSnippets.get("MAIN_MENU");
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
public String getSearchBarSnippet(){
|
|
|
146 |
return htmlSnippets.get("SEARCH_BAR");
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
public String getCustomerServiceSnippet(){
|
|
|
151 |
return htmlSnippets.get("CUSTOMER_SERVICE");
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
public String getRegistrationHeaderSnippet(){
|
|
|
155 |
return htmlSnippets.get("REGISTRATION_HEADER");
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
public String getRegistrationFormSnippet(){
|
|
|
159 |
return htmlSnippets.get("REGISTRATION_FORM");
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
public String getRecommendationsSnippet(){
|
|
|
163 |
return htmlSnippets.get("RECOMMENDATIONS");
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
public String getBrowseHistorySnippet(){
|
|
|
167 |
return htmlSnippets.get("BROWSE_HISTORY");
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
public String getFooterSnippet(){
|
|
|
171 |
return htmlSnippets.get("FOOTER");
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
public String getJsFileSnippet(){
|
|
|
175 |
return htmlSnippets.get("JS_FILES");
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
public String getCssFileSnippet(){
|
|
|
179 |
return htmlSnippets.get("CSS_FILES");
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
}
|