Skip to content

Commit

Permalink
#139 Fix broken logic in UserResource.
Browse files Browse the repository at this point in the history
  • Loading branch information
kozub committed Jan 9, 2020
1 parent 30997e1 commit 0efc8a3
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ class UserResource(
throw BadRequestAlertException("A new user cannot already have an ID", "userManagement", "idexists")
// Lowercase the user login before comparing with database
<%_ if (!reactive) { _%>
} else if (userRepository.findOneByLogin(userDTO.login!!.toLowerCase()) == null) {
} else if (userRepository.findOneByLogin(userDTO.login!!.toLowerCase()) != null) {
throw LoginAlreadyUsedException()
} else if (userRepository.findOneByEmailIgnoreCase(userDTO.email) == null) {
} else if (userRepository.findOneByEmailIgnoreCase(userDTO.email) != null) {
throw EmailAlreadyUsedException()
} else {
val newUser = userService.createUser(userDTO)
Expand Down Expand Up @@ -216,11 +216,11 @@ class UserResource(
fun updateUser(@Valid @RequestBody userDTO: <%= asDto('User') %>): ResponseEntity<<%= asDto('User') %>> {
log.debug("REST request to update User : {}", userDTO)
var existingUser = userRepository.findOneByEmailIgnoreCase(userDTO.email)
if (existingUser?.id != userDTO.id) {
if (existingUser != null && existingUser.id != userDTO.id) {
throw EmailAlreadyUsedException()
}
existingUser = userRepository.findOneByLogin(userDTO.login!!.toLowerCase())
if (existingUser?.id != userDTO.id) {
if (existingUser != null && existingUser.id != userDTO.id) {
throw LoginAlreadyUsedException()
}
val updatedUser = userService.updateUser(userDTO)
Expand Down

0 comments on commit 0efc8a3

Please sign in to comment.