Skip to content

Commit

Permalink
#139 Fix broken logic in UserResource and UserServiceIt
Browse files Browse the repository at this point in the history
  • Loading branch information
kozub committed Jan 9, 2020
1 parent 30997e1 commit 1dc819c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class UserServiceIT <% if (databaseType === 'cassandra') { %>: AbstractCassandra
userRepository.save<% if (databaseType === 'sql') { %>AndFlush<% } %>(user)<% if (reactive) { %>.block()<% } %>

val maybeUser = userService.completePasswordReset("johndoe2", user.resetKey!!)<% if (reactive) { %>.blockOptional()<% } %>
assertThat(maybeUser).isNotNull
assertThat(maybeUser).isNull()
userRepository.delete(user)<% if (reactive) { %>.block()<% } %>
}

Expand All @@ -303,7 +303,7 @@ class UserServiceIT <% if (databaseType === 'cassandra') { %>: AbstractCassandra
userRepository.save<% if (databaseType === 'sql') { %>AndFlush<% } %>(user)<% if (reactive) { %>.block()<% } %>

val maybeUser = userService.completePasswordReset("johndoe2", user.resetKey!!)<% if (reactive) { %>.blockOptional()<% } %>
assertThat(maybeUser).isNotNull
assertThat(maybeUser).isNull()
userRepository.delete(user)<% if (reactive) { %>.block()<% } %>
}

Expand Down

0 comments on commit 1dc819c

Please sign in to comment.