Skip to content

Instantly share code, notes, and snippets.

@Centaur
Created December 20, 2013 09:30
Show Gist options
  • Save Centaur/8052447 to your computer and use it in GitHub Desktop.
Save Centaur/8052447 to your computer and use it in GitHub Desktop.
path("login") {
post {
formFields('username, 'password) { (username, password) =>
val queryResult = (db ? Admin(username, password).find).mapTo[QueryResult]
onSuccess(queryResult) { qr =>
qr.rows match {
case Some(Seq(single: RowData)) =>
onSuccess(createSession(single)) { session_id =>
setCookie(HttpCookie(identity_cookie_name, session_id)) {
redirect("/admin/index", StatusCodes.SeeOther)
}
}
case _ => complete(StatusCodes.Unauthorized, "用户名或密码错误")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment