Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def authenticate = Action { implicit request =>
- signinForm.bindFromRequest.fold(
- formWithErrors => BadRequest(html.signin(formWithErrors)),
- user => Redirect(routes.Application.active).withSession(Security.username -> User.getUserName(user))
- )
- }
- def authenticate(email: String, password: String) : Option[User] = {
- (findByEmail(email)).filter { (user => BCrypt.checkpw(password, user.password)) }
- }
- def findByEmail(email: String) : Option[User] = {
- UserDAO.findOne(MongoDBObject("email" -> email))
- }
- val signinForm = Form {
- mapping(
- "email" -> nonEmptyText,
- "password" -> text)(User.authenticate)(_.map(user => (user.email, "")))
- .verifying("Invalid email or password", result => result.isDefined)
- }
- def authenticate = Action { implicit request =>
- signinForm.bindFromRequest.fold(
- formWithErrors => BadRequest(html.signin(formWithErrors)),
- user => Redirect(routes.Application.active).withSession(Security.username -> User.getUserName(user.get))
- )
- }
- val optUser: Option[User] = ...
- val user: User = optUser.get
- val optUser: Option[User] = ...
- optUser match {
- case Some(user) => // do something with user
- case None => // do something to handle the absent user
- }
- val optUser: Option[User] = ...
- optUser.map(user => doSomething(user))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement