コード例 #1
0
 /** POST /account -> update the current user information. */
 @RequestMapping(
     value = "/account",
     method = RequestMethod.POST,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<String> saveAccount(@RequestBody UserDTO userDTO) {
   User userHavingThisLogin = userRepository.findOneByLogin(userDTO.getLogin());
   if (userHavingThisLogin != null
       && !userHavingThisLogin.getLogin().equals(SecurityUtils.getCurrentLogin())) {
     return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
   }
   userService.updateUserInformation(
       userDTO.getFirstName(), userDTO.getLastName(), userDTO.getEmail(), userDTO.getLangKey());
   return new ResponseEntity<>(HttpStatus.OK);
 }
コード例 #2
0
 /** GET /account -> get the current user. */
 @RequestMapping(
     value = "/account",
     method = RequestMethod.GET,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<UserDTO> getAccount() {
   User user = userService.getUserWithAuthorities();
   if (user == null) {
     return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
   }
   List<String> roles = new ArrayList<>();
   for (Authority authority : user.getAuthorities()) {
     roles.add(authority.getName());
   }
   return new ResponseEntity<>(
       new UserDTO(
           user.getLogin(),
           null,
           user.getFirstName(),
           user.getLastName(),
           user.getEmail(),
           user.getLangKey(),
           roles),
       HttpStatus.OK);
 }