From 08ecc1ce26d77f6f5b43fae1bcd2356d3605fa98 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Tue, 29 Oct 2019 12:15:31 -0600 Subject: [PATCH] Allow login with username or email --- .../budgetserver/config/JdbcUserDetailsService.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/wbrawner/budgetserver/config/JdbcUserDetailsService.kt b/src/main/kotlin/com/wbrawner/budgetserver/config/JdbcUserDetailsService.kt index a2c45f8..b268070 100644 --- a/src/main/kotlin/com/wbrawner/budgetserver/config/JdbcUserDetailsService.kt +++ b/src/main/kotlin/com/wbrawner/budgetserver/config/JdbcUserDetailsService.kt @@ -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") } } \ No newline at end of file