Created
January 7, 2016 17:11
-
-
Save asheshambasta/c7f748a9c2ce4b9e656a to your computer and use it in GitHub Desktop.
user authentication example
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
// authenticate a user with a email + password | |
trait Authenticable { | |
def email: String | |
def password: String | |
def auth: Option[User] = dbAuthenticate(email, password) // dbAuthenticate is an example method that handles the authentication using a secure DB | |
def ~ = auth | |
} | |
case class UserForm(email: String, password: String) extends Authenticatable | |
// a login attempt is typically a POST request (SSL) to an endpoint `/api/v1/user/login` with `email` + `password` | |
for { | |
(email, pass) <- dataStream | |
uf <- UserForm(email, pass) | |
user <- uf ~ | |
} yield user // will yeield a user if authentication is a success |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment