Skip to content

Instantly share code, notes, and snippets.

@srp
Last active January 2, 2017 20:11
Show Gist options
  • Save srp/da6cab6d09ef9c7e2407c88c0d993f4f to your computer and use it in GitHub Desktop.
Save srp/da6cab6d09ef9c7e2407c88c0d993f4f to your computer and use it in GitHub Desktop.
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