Skip to content

Instantly share code, notes, and snippets.

@asheshambasta
Created January 7, 2016 17:11
Show Gist options
  • Save asheshambasta/c7f748a9c2ce4b9e656a to your computer and use it in GitHub Desktop.
Save asheshambasta/c7f748a9c2ce4b9e656a to your computer and use it in GitHub Desktop.
user authentication example
// 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