make user login case insensitive

This commit is contained in:
Gauthier Roebroeck 2019-10-18 15:22:44 +08:00
parent e5e7526365
commit cb2778278a
2 changed files with 5 additions and 5 deletions

View file

@ -6,6 +6,6 @@ import org.springframework.stereotype.Repository
@Repository
interface KomgaUserRepository : CrudRepository<KomgaUser, Long> {
fun existsByEmail(email: String): Boolean
fun findByEmail(email: String): KomgaUser?
fun existsByEmailIgnoreCase(email: String): Boolean
fun findByEmailIgnoreCase(email: String): KomgaUser?
}

View file

@ -24,13 +24,13 @@ class KomgaUserDetailsLifecycle(
) : UserDetailsService {
override fun loadUserByUsername(username: String): UserDetails =
userRepository.findByEmail(username)?.let {
userRepository.findByEmailIgnoreCase(username)?.let {
KomgaPrincipal(it)
} ?: throw UsernameNotFoundException(username)
@Transactional
fun updatePassword(user: UserDetails, newPassword: String, expireSessions: Boolean): UserDetails {
userRepository.findByEmail(user.username)?.let { komgaUser ->
userRepository.findByEmailIgnoreCase(user.username)?.let { komgaUser ->
logger.info { "Changing password for user ${user.username}" }
komgaUser.password = passwordEncoder.encode(newPassword)
userRepository.save(komgaUser)
@ -46,7 +46,7 @@ class KomgaUserDetailsLifecycle(
@Transactional
@Throws(UserEmailAlreadyExistsException::class)
fun createUser(user: UserDetails): UserDetails {
if (userRepository.existsByEmail(user.username)) throw UserEmailAlreadyExistsException("A user with the same email already exists: ${user.username}")
if (userRepository.existsByEmailIgnoreCase(user.username)) throw UserEmailAlreadyExistsException("A user with the same email already exists: ${user.username}")
val komgaUser = KomgaUser(
email = user.username,