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