Last active
January 2, 2017 20:11
-
-
Save srp/da6cab6d09ef9c7e2407c88c0d993f4f to your computer and use it in GitHub Desktop.
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
case class LoginRequest(username: String, password: String) | |
case class UserDetails(username: String, hashedPassword: String) | |
def login(dbConn: DbConnection, req: Request): Try[Response] = | |
for { | |
reqJsonStr <- req.body | |
reqJson <- json.parse(reqJsonStr) | |
loginReq <- validateAndDecode[LoginRequest](reqJson) | |
userDetails <- dbConn.findUser[UserDetails](dbConn, loginReq.username) | |
_ <- doesPasswordMatch(userDetails.hashedPassword, loginReq.password) | |
jwtToken <- jwt.generateToken() | |
} yield Response(200, Map("token" -> jwtToken)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment