Subversion Repositories SmartDukaan

Rev

Rev 22930 | Rev 23273 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22930 Rev 23204
Line 71... Line 71...
71
 
71
 
72
	private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
72
	private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
73
 
73
 
74
	@Value("${notifications.api.host}")
74
	@Value("${notifications.api.host}")
75
	private String nodeHost;
75
	private String nodeHost;
-
 
76
	
76
	@Value("${notifications.api.port}")
77
	@Value("${notifications.api.port}")
77
	private int nodePort;
78
	private int nodePort;
78
 
79
 
79
	@Value("${admin.token}")
80
	@Value("${admin.token}")
80
	private String validAdminToken;
81
	private String validAdminToken;
Line 129... Line 130...
129
			user = userRepository.selectById(userInfo.getUserId());
130
			user = userRepository.selectById(userInfo.getUserId());
130
		} else {
131
		} else {
131
			try {
132
			try {
132
				user = userRepository.selectByEmailId(userInfo.getEmail());
133
				user = userRepository.selectByEmailId(userInfo.getEmail());
133
			} catch (ProfitMandiBusinessException e1) {
134
			} catch (ProfitMandiBusinessException e1) {
-
 
135
			}
-
 
136
			if(user == null){
-
 
137
				try {
-
 
138
					user = userRepository.selectBySecondryEmailId(userInfo.getEmail());
-
 
139
				} catch (ProfitMandiBusinessException e1) {
134
				LOGGER.info("Uneregistered user", userInfo.getEmail());
140
					LOGGER.info("Uneregistered user", userInfo.getEmail());
-
 
141
				}
135
			}
142
			}
136
		}
143
		}
137
		if (user != null) {
144
		if (user != null) {
138
			responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
145
			responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
139
			responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
146
			responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
Line 249... Line 256...
249
	public ResponseEntity<?> getByMobileNumber(HttpServletRequest request,
256
	public ResponseEntity<?> getByMobileNumber(HttpServletRequest request,
250
			@RequestParam(name = "mobileNumber") String mobileNumber) throws ProfitMandiBusinessException{
257
			@RequestParam(name = "mobileNumber") String mobileNumber) throws ProfitMandiBusinessException{
251
		LOGGER.info("requested url : " + request.getRequestURL().toString());
258
		LOGGER.info("requested url : " + request.getRequestURL().toString());
252
		return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
259
		return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
253
	}
260
	}
-
 
261
	
-
 
262
	
254
 
263
 
255
	@ApiImplicitParams({
264
	@ApiImplicitParams({
256
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
265
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
257
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ACTIVATE, method = RequestMethod.POST)
266
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ACTIVATE, method = RequestMethod.POST)
258
	public ResponseEntity<?> activateUser(HttpServletRequest request,
267
	public ResponseEntity<?> activateUser(HttpServletRequest request,
Line 308... Line 317...
308
	}
317
	}
309
 
318
 
310
	@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID, method = RequestMethod.GET)
319
	@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID, method = RequestMethod.GET)
311
	public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId) throws ProfitMandiBusinessException{
320
	public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId) throws ProfitMandiBusinessException{
312
		LOGGER.info("requested url : " + request.getRequestURL().toString());
321
		LOGGER.info("requested url : " + request.getRequestURL().toString());
-
 
322
		User user = null;
-
 
323
		try{
313
		return responseSender.ok(userRepository.selectByEmailId(emailId));
324
			user = userRepository.selectByEmailId(emailId);
-
 
325
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
-
 
326
			user = userRepository.selectBySecondryEmailId(emailId);
-
 
327
		}
-
 
328
		return responseSender.ok(user);
314
	}
329
	}
315
 
330
 
316
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ADD, method = RequestMethod.POST)
331
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ADD, method = RequestMethod.POST)
317
	public ResponseEntity<?> addRole(HttpServletRequest request, @RequestBody UserAddRoleRequest userAddRoleRequest) throws ProfitMandiBusinessException{
332
	public ResponseEntity<?> addRole(HttpServletRequest request, @RequestBody UserAddRoleRequest userAddRoleRequest) throws ProfitMandiBusinessException{
318
		LOGGER.info("requested url : " + request.getRequestURL().toString());
333
		LOGGER.info("requested url : " + request.getRequestURL().toString());
Line 342... Line 357...
342
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL, method = RequestMethod.GET)
357
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL, method = RequestMethod.GET)
343
	public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id) {
358
	public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id) {
344
		LOGGER.info("requested url : " + request.getRequestURL().toString());
359
		LOGGER.info("requested url : " + request.getRequestURL().toString());
345
		return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
360
		return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
346
	}
361
	}
-
 
362
	
-
 
363
	@ApiImplicitParams({
-
 
364
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
-
 
365
	@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID_AND_FOFO_STORE_CODE, method = RequestMethod.GET)
-
 
366
	public ResponseEntity<?> getSecondryEmailAndStoreCode(HttpServletRequest request) throws ProfitMandiBusinessException{
-
 
367
		LOGGER.info("requested url : " + request.getRequestURL().toString());
-
 
368
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
-
 
369
		return responseSender.ok(userService.getEmailsAndFofoStoreCodeByUserId(userId));
-
 
370
	}
-
 
371
	
-
 
372
	@ApiImplicitParams({
-
 
373
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
-
 
374
@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID, method = RequestMethod.PUT)
-
 
375
	public ResponseEntity<?> updateSecondryEmailId(HttpServletRequest request,
-
 
376
		@RequestParam(name = ProfitMandiConstants.SECONDRY_EMAIL_ID) String secondryEmailId) throws Throwable {
-
 
377
	int userId = (int) request.getAttribute("userId");
-
 
378
	User user = userRepository.selectById(userId);
-
 
379
	user.setSecondryEmailId(secondryEmailId);
-
 
380
	userRepository.persist(user);
-
 
381
	return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1001"));
-
 
382
}
347
 
383
 
348
	@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
384
	@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
349
	public ResponseEntity<?> getAdminToken(HttpServletRequest request,
385
	public ResponseEntity<?> getAdminToken(HttpServletRequest request,
350
			@RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) {
386
			@RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) {
351
		LOGGER.info("requested url : " + request.getRequestURL().toString());
387
		LOGGER.info("requested url : " + request.getRequestURL().toString());
352
		if (!adminToken.equals(validAdminToken)) {
388
		if (!adminToken.equals(validAdminToken)) {
353
			return responseSender.forbidden(null);
389
			return responseSender.forbidden(null);
354
		}
390
		}
355
 
391
 
356
		Map<String, Object> responseMap = new HashMap<>(2);
392
		Map<String, Object> responseMap = new HashMap<>(2);
-
 
393
		User user = null;
357
		try {
394
		try {
358
			User user = userRepository.selectByEmailId(emailId);
395
			user = userRepository.selectByEmailId(emailId);
-
 
396
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
397
			
-
 
398
		}
-
 
399
		
-
 
400
		if(user == null){
-
 
401
			try{
-
 
402
				user = userRepository.selectBySecondryEmailId(emailId);
-
 
403
			}catch(ProfitMandiBusinessException profitMandiBusinessException){
-
 
404
				
-
 
405
			}
-
 
406
		}
-
 
407
		if(user != null){
359
			List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
408
			List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
360
			String[] roleTypes = new String[userRoles.size()];
409
			String[] roleTypes = new String[userRoles.size()];
361
			int index = 0;
410
			int index = 0;
362
			for (UserRole userRole : userRoles) {
411
			for (UserRole userRole : userRoles) {
363
				roleTypes[index++] = userRole.getRoleType().toString();
412
				roleTypes[index++] = userRole.getRoleType().toString();
364
			}
413
			}
365
			responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), roleTypes));
414
			responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), roleTypes));
366
			responseMap.put(ProfitMandiConstants.REGISTERED, true);
415
			responseMap.put(ProfitMandiConstants.REGISTERED, true);
367
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
416
		}else{
368
			responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(emailId));
417
			responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(emailId));
369
			responseMap.put(ProfitMandiConstants.REGISTERED, false);
418
			responseMap.put(ProfitMandiConstants.REGISTERED, false);
370
		}
419
		}
371
		return responseSender.ok(responseMap);
420
		return responseSender.ok(responseMap);
372
 
421