Last active
August 29, 2015 14:13
-
-
Save BioQwer/c1991f33e1bfc1beb089 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public User getCurrentUser(Principal principal) { | |
System.out.println("principal.getName() = " + principal.getName()); | |
System.out.println(" userService.getByLogin(principal.getName()) = " + userService.getByLogin(principal.getName())); | |
return userService.getByLogin(principal.getName()); | |
} | |
/** | |
* Edit user method | |
* !! if Change user.login you must to re singIn on client !! | |
*/ | |
@RequestMapping(method = RequestMethod.POST) | |
@ResponseBody | |
public Object editUser(Principal principal, @RequestBody User user, HttpServletResponse response) { | |
response.setStatus(400); | |
// Check user for situation when login or email is busy | |
User checker = userService.getByEmail(user.getEmail()); | |
if ((checker != null) && (checker.getUserId() != user.getUserId())) { | |
return new Constraint("email", user.getEmail(), "Email " + user.getEmail() + " is busy"); | |
} else { | |
checker = userService.getByLogin(user.getLogin()); | |
if ((checker != null) && (checker.getUserId() != user.getUserId())) { | |
return new Constraint("login", user.getLogin(), "Login " + user.getLogin() + " is busy"); | |
} | |
} | |
//try to edit user | |
try { | |
response.setStatus(200); | |
if (user.getUserId() == getCurrentUser(principal).getUserId()) | |
return userService.editUser(user); | |
else | |
throw new BadRequestException(); | |
} catch (ConstraintViolationException e) { | |
e.printStackTrace(); | |
response.setStatus(400); | |
return getInCorrectValues(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment