| Line 160... |
Line 160... |
| 160 |
public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest loginRequest) throws Exception {
|
160 |
public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest loginRequest) throws Exception {
|
| 161 |
String email = loginRequest.getEmail() != null ? loginRequest.getEmail() : googleLoginProcessor.process(loginRequest.getToken());
|
161 |
String email = loginRequest.getEmail() != null ? loginRequest.getEmail() : googleLoginProcessor.process(loginRequest.getToken());
|
| 162 |
return responseSender.ok(getAuthTokenMap(email, loginRequest));
|
162 |
return responseSender.ok(getAuthTokenMap(email, loginRequest));
|
| 163 |
}
|
163 |
}
|
| 164 |
|
164 |
|
| - |
|
165 |
@RequestMapping(value = "/user/unregistered", method = RequestMethod.GET)
|
| - |
|
166 |
public ResponseEntity<?> unregisteredToken() throws Exception {
|
| - |
|
167 |
Map<String, Object> responseMap = new HashMap<>();
|
| - |
|
168 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create());
|
| - |
|
169 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
| - |
|
170 |
return responseSender.ok(responseMap);
|
| - |
|
171 |
}
|
| - |
|
172 |
|
| 165 |
@RequestMapping(value = ProfitMandiConstants.URL_B2B_APP_VERSION, method = RequestMethod.GET)
|
173 |
@RequestMapping(value = ProfitMandiConstants.URL_B2B_APP_VERSION, method = RequestMethod.GET)
|
| 166 |
public ResponseEntity<?> checkForUpdate(HttpServletRequest request, @RequestParam int version) {
|
174 |
public ResponseEntity<?> checkForUpdate(HttpServletRequest request, @RequestParam int version) {
|
| 167 |
Map<String, Object> responseMap = new HashMap<>();
|
175 |
Map<String, Object> responseMap = new HashMap<>();
|
| 168 |
responseMap.put("appVersion", ProfitMandiConstants.B2B_APP_VERSION);
|
176 |
responseMap.put("appVersion", ProfitMandiConstants.B2B_APP_VERSION);
|
| 169 |
responseMap.put("appUrl", ProfitMandiConstants.B2B_APP_URL);
|
177 |
responseMap.put("appUrl", ProfitMandiConstants.B2B_APP_URL);
|
| Line 290... |
Line 298... |
| 290 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
298 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
| 291 |
public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
|
299 |
public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
|
| 292 |
Map<String, Object> responseMap = new HashMap<>();
|
300 |
Map<String, Object> responseMap = new HashMap<>();
|
| 293 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
301 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 294 |
LOGGER.info("userinfo1 {}", userInfo);
|
302 |
LOGGER.info("userinfo1 {}", userInfo);
|
| - |
|
303 |
|
| 295 |
User user = null;
|
304 |
User user = null;
|
| - |
|
305 |
// Case 1: When userId is present in token
|
| 296 |
if (userInfo.getUserId() > -1) {
|
306 |
if (userInfo.getUserId() > -1) {
|
| 297 |
user = userRepository.selectById(userInfo.getUserId());
|
307 |
user = userRepository.selectById(userInfo.getUserId());
|
| 298 |
String city = user.getCity();
|
- |
|
| 299 |
|
308 |
|
| - |
|
309 |
// Special FOFO Associate handling for smartdukaan domain
|
| - |
|
310 |
boolean isSmartDukaanEmail = userInfo.getEmail() != null
|
| - |
|
311 |
&& user.getEmailId() != null
|
| 300 |
if (!(userInfo.getEmail() == null || user.getEmailId().indexOf("@smartdukaan.com") == -1)) {
|
312 |
&& user.getEmailId().contains("@smartdukaan.com");
|
| - |
|
313 |
if (isSmartDukaanEmail) {
|
| 301 |
String userName = null;
|
314 |
String userName;
|
| 302 |
if (user.getSecondryEmailId() != null && user.getSecondryEmailId().equals(userInfo.getEmail())) {
|
315 |
if (user.getSecondryEmailId() != null && user.getSecondryEmailId().equals(userInfo.getEmail())) {
|
| 303 |
|
- |
|
| 304 |
userName = user.getFirstName() + " " + user.getLastName();
|
316 |
userName = user.getFirstName() + " " + user.getLastName();
|
| 305 |
} else {
|
317 |
} else {
|
| 306 |
AuthUser authUser = authRepository.selectByGmailId(userInfo.getEmail());
|
318 |
AuthUser authUser = authRepository.selectByGmailId(userInfo.getEmail());
|
| 307 |
LOGGER.info("authUser {}", authUser);
|
319 |
LOGGER.info("authUser {}", authUser);
|
| 308 |
if (authUser == null || !authUser.isActive()) {
|
320 |
if (authUser == null || !authUser.isActive()) {
|
| 309 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
|
321 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
|
| 310 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
322 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
| 311 |
return responseSender.ok(responseMap);
|
323 |
return responseSender.ok(responseMap);
|
| Line 318... |
Line 330... |
| 318 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
330 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
| 319 |
responseMap.put("storeUrl", "");
|
331 |
responseMap.put("storeUrl", "");
|
| 320 |
return responseSender.ok(responseMap);
|
332 |
return responseSender.ok(responseMap);
|
| 321 |
}
|
333 |
}
|
| 322 |
} else {
|
334 |
} else {
|
| - |
|
335 |
// Case 2: When userId is not present, try locate by emails
|
| 323 |
try {
|
336 |
try {
|
| 324 |
|
- |
|
| 325 |
LOGGER.info("userinfo4 {}", userInfo);
|
337 |
LOGGER.info("userinfo4 {}", userInfo);
|
| 326 |
user = userRepository.selectByEmailId(userInfo.getEmail());
|
338 |
user = userRepository.selectByEmailId(userInfo.getEmail());
|
| 327 |
} catch (ProfitMandiBusinessException e1) {
|
339 |
} catch (ProfitMandiBusinessException e1) {
|
| - |
|
340 |
LOGGER.warn("Failed to fetch user by primary email: {}", userInfo.getEmail(), e1);
|
| 328 |
}
|
341 |
}
|
| 329 |
if (user == null) {
|
342 |
if (user == null) {
|
| 330 |
try {
|
343 |
try {
|
| 331 |
LOGGER.info("userinfo8 {}", userInfo);
|
344 |
LOGGER.info("userinfo8 {}", userInfo);
|
| 332 |
user = userRepository.selectBySecondryEmailId(userInfo.getEmail());
|
345 |
user = userRepository.selectBySecondryEmailId(userInfo.getEmail());
|
| 333 |
} catch (ProfitMandiBusinessException e1) {
|
346 |
} catch (ProfitMandiBusinessException e1) {
|
| 334 |
LOGGER.info("Uneregistered user", userInfo.getEmail());
|
347 |
LOGGER.info("Unregistered user: {}", userInfo.getEmail());
|
| 335 |
}
|
348 |
}
|
| 336 |
}
|
349 |
}
|
| 337 |
}
|
350 |
}
|
| - |
|
351 |
|
| 338 |
if (user != null) {
|
352 |
if (user != null) {
|
| 339 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
353 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
| 340 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
354 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
| 341 |
responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
|
355 |
responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
|
| 342 |
|
356 |
|
| 343 |
if(roleManager.isUser(userInfo.getRoleIds()) && !roleManager.isRetailer(userInfo.getRoleIds())) {
|
- |
|
| 344 |
|
- |
|
| 345 |
} else {
|
- |
|
| 346 |
|
- |
|
| 347 |
}
|
- |
|
| 348 |
|
- |
|
| 349 |
|
- |
|
| 350 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
357 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
| 351 |
LOGGER.info("userRoles {} ", user.getEmailId());
|
358 |
LOGGER.info("userRoles for {}", user.getEmailId());
|
| 352 |
|
359 |
|
| 353 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
360 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| 354 |
// generate new token if roles have been updated
|
361 |
// generate new token if roles have been updated
|
| 355 |
if (userInfo.getRoleIds() == null || roleIds.size() != userInfo.getRoleIds().size()) {
|
362 |
if (userInfo.getRoleIds() == null || roleIds.size() != userInfo.getRoleIds().size()) {
|
| 356 |
String[] roleIdStrings = new String[roleIds.size()];
|
363 |
String[] roleIdStrings = roleIds.stream().map(String::valueOf).toArray(String[]::new);
|
| 357 |
int index = 0;
|
- |
|
| 358 |
for (int roleId : roleIds) {
|
- |
|
| 359 |
roleIdStrings[index++] = String.valueOf(roleId);
|
- |
|
| 360 |
}
|
- |
|
| 361 |
String newToken = JWTUtil.create(user.getId(), retailerId, roleIdStrings);
|
364 |
String newToken = JWTUtil.create(user.getId(), retailerId, roleIdStrings);
|
| 362 |
responseMap.put("newAuthToken", newToken);
|
365 |
responseMap.put("newAuthToken", newToken);
|
| 363 |
}
|
366 |
}
|
| - |
|
367 |
|
| 364 |
// if user is retailer
|
368 |
// if user is retailer
|
| 365 |
Set<Integer> roleIdsSet = new HashSet<Integer>(roleIds);
|
369 |
Set<Integer> roleIdsSet = new HashSet<>(roleIds);
|
| 366 |
if (roleManager.isRetailer(roleIdsSet)) {
|
370 |
if (roleManager.isRetailer(roleIdsSet)) {
|
| 367 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
371 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
| 368 |
Retailer retailer = retailerRepository.selectById(uc.getUserId());
|
372 |
Retailer retailer = retailerRepository.selectById(uc.getUserId());
|
| 369 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
|
373 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
|
| 370 |
if (saholicUser.getAddressId() != null) {
|
374 |
if (saholicUser.getAddressId() != null) {
|
| Line 592... |
Line 596... |
| 592 |
|
596 |
|
| 593 |
return responseSender.ok(this.getAuthTokenMap(emailId, loginRequest));
|
597 |
return responseSender.ok(this.getAuthTokenMap(emailId, loginRequest));
|
| 594 |
|
598 |
|
| 595 |
}
|
599 |
}
|
| 596 |
|
600 |
|
| 597 |
@RequestMapping(value = "/mobileappsettings")
|
- |
|
| 598 |
public ResponseEntity<?> mobileAppSettings(HttpServletRequest request, @RequestParam(name = "t") int timestamp, @RequestParam(name = "imeinumber") String imeinumber) throws ProfitMandiBusinessException, ClientProtocolException, IOException {
|
- |
|
| 599 |
final String uri = "http://192.168.158.89/mobileappsettings?t=" + timestamp + "&imeinumber=" + imeinumber;
|
- |
|
| 600 |
final String BASIC_AUTH = "Basic " + Base64.getEncoder().encodeToString("dtr:dtr18Feb2015".getBytes());
|
- |
|
| 601 |
Map<String, String> headers = new HashMap<>();
|
- |
|
| 602 |
Map<String, String> params = new HashMap<>();
|
- |
|
| 603 |
headers.put("Authorization", BASIC_AUTH);
|
- |
|
| 604 |
if (timestamp == 0) {
|
- |
|
| 605 |
return responseSender.ok(OrderController.APP_SETTINGS);
|
- |
|
| 606 |
} else {
|
- |
|
| 607 |
return responseSender.ok(OrderController.APP_SETTINGS_BLANK);
|
- |
|
| 608 |
}
|
- |
|
| 609 |
}
|
- |
|
| 610 |
|
- |
|
| 611 |
@RequestMapping(value = "/mobileappsettings1", method = RequestMethod.POST)
|
601 |
@RequestMapping(value = "/mobileappsettings1", method = RequestMethod.POST)
|
| 612 |
public ResponseEntity<?> mobileAppSettings1(HttpServletRequest request, @RequestParam(name = "t") int timestamp,
|
602 |
public ResponseEntity<?> mobileAppSettings1(HttpServletRequest request, @RequestParam(name = "t") int timestamp,
|
| 613 |
@RequestParam(name = "imeinumber") String imeinumber)
|
603 |
@RequestParam(name = "imeinumber") String imeinumber)
|
| 614 |
throws ProfitMandiBusinessException, ClientProtocolException, IOException {
|
604 |
throws ProfitMandiBusinessException, ClientProtocolException, IOException {
|
| 615 |
LocalDateTime settingsLastUpdated = LocalDateTime.ofEpochSecond(timestamp, 0, ZoneOffset.ofHoursMinutes(5, 30));
|
605 |
LocalDateTime settingsLastUpdated = LocalDateTime.ofEpochSecond(timestamp, 0, ZoneOffset.ofHoursMinutes(5, 30));
|