Allow login with username or email

This commit is contained in:
Billy Brawner 2019-10-29 12:15:31 -06:00
parent 6191ed9fe4
commit 08ecc1ce26

View file

@ -13,7 +13,12 @@ constructor(private val userRepository: UserRepository) : UserDetailsService {
@Throws(UsernameNotFoundException::class)
override fun loadUserByUsername(username: String): UserDetails {
return userRepository.findByName(username).orElse(null)
?: throw UsernameNotFoundException("Unable to find user with username $username")
userRepository.findByName(username).orElse(null)?.let {
return it
}
userRepository.findByEmail(username).orElse(null)?.let {
return it
}
throw UsernameNotFoundException("Unable to find user with username $username")
}
}