Created
July 13, 2017 06:33
-
-
Save anonymous/bed7ea66ca2521944f5c35ec883ecc78 to your computer and use it in GitHub Desktop.
the description for this gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Logs in user with his credentials. | |
* | |
* @param credentials - user's email and password hash | |
* @return `LoginResponse`. | |
*/ | |
/** | |
* Logs in user with his credentials. | |
* | |
* @param credentials - user's email and password hash | |
* @return `LoginResponse`. | |
*/ | |
def login(credentials: Credentials): FS[LoginResponse] = { | |
import credentials._ | |
for { | |
userAndPassword <- persistence.getPasswordByEmail(email) | |
response <- userAndPassword match { | |
case Some((id, pass)) if password.isBcrypted(pass) => | |
(for { | |
_ <- log.info("User '$id' provided valid email and password") | |
token <- jwt.issue(id) | |
_ <- log.info(s"Token is $token") | |
} yield LoggedIn(token): LoginResponse): FS[LoginResponse] | |
case Some((id, _)) => | |
(for { | |
_ <- log.info(s"User '$id' provided invalid password") | |
} yield InvalidCredentials: LoginResponse): FS[LoginResponse] | |
case None => | |
(for { | |
_ <- log.info(s"Log in rejected: no access for '$email'") | |
} yield InvalidCredentials: LoginResponse): FS[LoginResponse] | |
} | |
} yield response | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment