| Line 96... |
Line 96... |
| 96 |
@Autowired
|
96 |
@Autowired
|
| 97 |
private FofoStoreRepository fofoStoreRepository;
|
97 |
private FofoStoreRepository fofoStoreRepository;
|
| 98 |
|
98 |
|
| 99 |
@Autowired
|
99 |
@Autowired
|
| 100 |
private MVCResponseSender mvcResponseSender;
|
100 |
private MVCResponseSender mvcResponseSender;
|
| 101 |
|
101 |
|
| 102 |
@Autowired
|
102 |
@Autowired
|
| 103 |
private RestClient restClient;
|
103 |
private RestClient restClient;
|
| 104 |
|
104 |
|
| 105 |
@Autowired
|
105 |
@Autowired
|
| 106 |
private CookiesProcessor cookiesProcessor;
|
106 |
private CookiesProcessor cookiesProcessor;
|
| Line 142... |
Line 142... |
| 142 |
|
142 |
|
| 143 |
@RequestMapping(value = "/", method = RequestMethod.GET)
|
143 |
@RequestMapping(value = "/", method = RequestMethod.GET)
|
| 144 |
public String home() {
|
144 |
public String home() {
|
| 145 |
return "redirect:/login";
|
145 |
return "redirect:/login";
|
| 146 |
}
|
146 |
}
|
| 147 |
|
147 |
|
| 148 |
@RequestMapping(value = "/mobileapp", method = RequestMethod.GET)
|
148 |
@RequestMapping(value = "/mobileapp", method = RequestMethod.GET)
|
| 149 |
public String mobileApp(HttpServletRequest request, Model model) throws Exception {
|
149 |
public String mobileApp(HttpServletRequest request, Model model) throws Exception {
|
| 150 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
150 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 151 |
if(roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
151 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 152 |
model.addAttribute("authToken", getToken(fofoDetails.getEmailId()));
|
152 |
model.addAttribute("authToken", getToken(fofoDetails.getEmailId()));
|
| 153 |
}
|
153 |
}
|
| 154 |
return "mobileapp";
|
154 |
return "mobileapp";
|
| 155 |
}
|
155 |
}
|
| 156 |
|
156 |
|
| 157 |
private String getToken(String emailId) throws Exception {
|
157 |
private String getToken(String emailId) throws Exception {
|
| 158 |
List<NameValuePair> nameValuePairs = new ArrayList<>();
|
158 |
List<NameValuePair> nameValuePairs = new ArrayList<>();
|
| 159 |
nameValuePairs.add(new BasicNameValuePair("adminToken", "ecip$stgMay2014"));
|
159 |
nameValuePairs.add(new BasicNameValuePair("adminToken", "ecip$stgMay2014"));
|
| 160 |
nameValuePairs.add(new BasicNameValuePair("emailId", emailId));
|
160 |
nameValuePairs.add(new BasicNameValuePair("emailId", emailId));
|
| 161 |
String queryString=URLEncodedUtils.format(nameValuePairs, "UTF-8");
|
161 |
String queryString = URLEncodedUtils.format(nameValuePairs, "UTF-8");
|
| 162 |
String response = restClient.post("http://app.profitmandi.com:8080/profitmandi-web/user/admin?" + queryString, new HashMap<>(), new HashMap<>());
|
162 |
String response = restClient.post("http://app.profitmandi.com:8080/profitmandi-web/user/admin?" + queryString,
|
| - |
|
163 |
new HashMap<>(), new HashMap<>());
|
| 163 |
Type t = new TypeToken<ProfitMandiResponse<Map<String,Object>>>() {}.getType();
|
164 |
Type t = new TypeToken<ProfitMandiResponse<Map<String, Object>>>() {
|
| - |
|
165 |
}.getType();
|
| 164 |
ProfitMandiResponse <Map<String,Object>> apiResponse = new Gson().fromJson(response, t);
|
166 |
ProfitMandiResponse<Map<String, Object>> apiResponse = new Gson().fromJson(response, t);
|
| 165 |
if(apiResponse.getStatusCode().equals("200")) {
|
167 |
if (apiResponse.getStatusCode().equals("200")) {
|
| 166 |
return (new StringBuilder((String)apiResponse.getResponse().get("token")).reverse().toString());
|
168 |
return (new StringBuilder((String) apiResponse.getResponse().get("token")).reverse().toString());
|
| 167 |
} else {
|
169 |
} else {
|
| 168 |
throw new Exception("Unauthorised access");
|
170 |
throw new Exception("Unauthorised access");
|
| 169 |
}
|
171 |
}
|
| 170 |
|
172 |
|
| 171 |
}
|
173 |
}
|
| - |
|
174 |
|
| 172 |
@RequestMapping(value = "/login-as-partner", method = RequestMethod.GET)
|
175 |
@RequestMapping(value = "/login-as-partner", method = RequestMethod.GET)
|
| 173 |
public String adminLogin(HttpServletRequest request, Model model, HttpServletResponse response,
|
176 |
public String adminLogin(HttpServletRequest request, Model model, HttpServletResponse response,
|
| 174 |
@RequestParam int fofoId) throws Exception {
|
177 |
@RequestParam int fofoId) throws Exception {
|
| 175 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
178 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 176 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
179 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 177 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
180 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
| 178 |
User user = userRepository.selectById(userId);
|
181 |
User user = userRepository.selectById(userId);
|
| 179 |
Set<Integer> roleIds = userRoleRepository
|
182 |
Set<Integer> roleIds = userRoleRepository.selectByUserId(userId).stream().map(x -> x.getRoleId())
|
| 180 |
.selectByUserId(userId).stream()
|
- |
|
| 181 |
.map(x -> x.getRoleId()).collect(Collectors.toSet());
|
183 |
.collect(Collectors.toSet());
|
| 182 |
LoginDetails newFofoDetails = new LoginDetails();
|
184 |
LoginDetails newFofoDetails = new LoginDetails();
|
| 183 |
newFofoDetails.setFofoId(fofoId);
|
185 |
newFofoDetails.setFofoId(fofoId);
|
| 184 |
newFofoDetails.setRoleIds(roleIds);
|
186 |
newFofoDetails.setRoleIds(roleIds);
|
| 185 |
newFofoDetails.setEmailId(user.getEmailId());
|
187 |
newFofoDetails.setEmailId(user.getEmailId());
|
| 186 |
model.addAttribute("response", true);
|
188 |
model.addAttribute("response", true);
|
| Line 217... |
Line 219... |
| 217 |
authUser.setLastLoginTimestamp(LocalDateTime.now());
|
219 |
authUser.setLastLoginTimestamp(LocalDateTime.now());
|
| 218 |
authRepository.persist(authUser);
|
220 |
authRepository.persist(authUser);
|
| 219 |
}
|
221 |
}
|
| 220 |
|
222 |
|
| 221 |
} else {
|
223 |
} else {
|
| - |
|
224 |
try {
|
| 222 |
emailId = googleTokenUtil.getEmailId(token);
|
225 |
emailId = googleTokenUtil.getEmailId(token);
|
| - |
|
226 |
} catch(Exception e) {
|
| - |
|
227 |
//in case we cannot connect to google server.
|
| - |
|
228 |
emailId = emailIdOrMobileNumber;
|
| - |
|
229 |
}
|
| 223 |
if (ProfitMandiConstants.BLOCKED_EMAILS.contains(emailId)) {
|
230 |
if (ProfitMandiConstants.BLOCKED_EMAILS.contains(emailId)) {
|
| 224 |
}
|
231 |
}
|
| 225 |
}
|
232 |
}
|
| 226 |
fofoDetails.setEmailId(emailId);
|
233 |
fofoDetails.setEmailId(emailId);
|
| 227 |
fofoDetails.setFofoId(-1);
|
234 |
fofoDetails.setFofoId(-1);
|
| Line 263... |
Line 270... |
| 263 |
LOGGER.error("Data Inconsistent", pmbe);
|
270 |
LOGGER.error("Data Inconsistent", pmbe);
|
| 264 |
}
|
271 |
}
|
| 265 |
}
|
272 |
}
|
| 266 |
String redirectUrl = null;
|
273 |
String redirectUrl = null;
|
| 267 |
|
274 |
|
| 268 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
- |
|
| 269 |
Role roleFofo = roleRepository.selectByName(RoleType.RETAILER.toString());
|
275 |
Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 270 |
Role roleFofoAdmin = roleRepository.selectByName(RoleType.RETAILER.toString());
|
276 |
Role roleFofoAdmin = roleRepository.selectByName(RoleType.FOFO_ADMIN.toString());
|
| 271 |
|
277 |
|
| 272 |
if ((fofoDetails.getRoleIds().contains(roleRetailer.getId())
|
- |
|
| 273 |
&& fofoDetails.getRoleIds().contains(roleFofo.getId())
|
278 |
if (fofoDetails.getRoleIds().contains(roleFofo.getId())) {
|
| 274 |
|| (fofoDetails.getRoleIds().contains(roleFofoAdmin.getId())))) {
|
- |
|
| 275 |
redirectUrl = "/dashboard";
|
279 |
redirectUrl = "/dashboard";
|
| - |
|
280 |
if(fofoDetails.getRoleIds().contains(roleFofo.getId())) {
|
| - |
|
281 |
|
| - |
|
282 |
}
|
| 276 |
} else {
|
283 |
} else {
|
| 277 |
redirectUrl = "/login";
|
284 |
redirectUrl = "/login";
|
| 278 |
}
|
285 |
}
|
| 279 |
|
286 |
|
| 280 |
if (!redirectUrl.equals("/login")) {
|
287 |
if (redirectUrl.equals("/dashboard")) {
|
| 281 |
user.setLoginTimestamp(LocalDateTime.now());
|
288 |
user.setLoginTimestamp(LocalDateTime.now());
|
| 282 |
userRepository.persist(user);
|
- |
|
| 283 |
this.addCookiesToResponse(fofoDetails, request, response);
|
289 |
this.addCookiesToResponse(fofoDetails, request, response);
|
| 284 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to {}",
|
290 |
LOGGER.info("Requested token email_id is valid, user login to system, shoud be redirect to {}",
|
| 285 |
redirectUrl);
|
291 |
redirectUrl);
|
| 286 |
model.addAttribute("response", mvcResponseSender.createResponseString("RTLR_OK_1002", true,
|
292 |
model.addAttribute("response", mvcResponseSender.createResponseString("RTLR_OK_1002", true,
|
| 287 |
request.getContextPath() + redirectUrl, name));
|
293 |
request.getContextPath() + redirectUrl, name));
|
| 288 |
} else {
|
294 |
} else {
|
| 289 |
LOGGER.error("Requested token email_id is not valid, please try to login");
|
295 |
LOGGER.error("Requested token email_id is not valid, please try to login");
|
| - |
|
296 |
/**
|
| - |
|
297 |
* TODO:Amit
|
| - |
|
298 |
* This redirect should be handle.
|
| - |
|
299 |
*/
|
| 290 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId(),
|
300 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, fofoDetails.getEmailId(),
|
| 291 |
"RTLR_1000");
|
301 |
"RTLR_1000");
|
| 292 |
}
|
302 |
}
|
| 293 |
return "response";
|
303 |
return "response";
|
| 294 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
304 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|