Flatten packages
Remove modules prefix
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package be.simplenotes.domain.usecases.users.login
|
||||
|
||||
import arrow.core.computations.either
|
||||
import arrow.core.filterOrElse
|
||||
import arrow.core.rightIfNotNull
|
||||
import be.simplenotes.domain.security.PasswordHash
|
||||
import be.simplenotes.domain.security.SimpleJwt
|
||||
import be.simplenotes.domain.validation.UserValidations
|
||||
import be.simplenotes.persistance.repositories.UserRepository
|
||||
import be.simplenotes.types.LoggedInUser
|
||||
import io.micronaut.context.annotation.Primary
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
@Primary
|
||||
internal class LoginUseCaseImpl(
|
||||
private val userRepository: UserRepository,
|
||||
private val passwordHash: PasswordHash,
|
||||
private val jwt: SimpleJwt
|
||||
) : LoginUseCase {
|
||||
override fun login(form: LoginForm) = either.eager<LoginError, Token> {
|
||||
val user = !UserValidations.validateLogin(form)
|
||||
!userRepository.find(user.username)
|
||||
.rightIfNotNull { Unregistered }
|
||||
.filterOrElse({ passwordHash.verify(form.password!!, it.password) }, { WrongPassword })
|
||||
.map { jwt.sign(LoggedInUser(it)) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user