In the zentasks example for Play2 we have the method
def isAuthenticated(f: => String => Request[AnyContent] => Result) = {
Security.Authenticated(username, onUnauthorized) { user =>
Action(request => f(user)(request))
}
}
What I would like to do is add another method that I could use if I wanted to get the user directly from the database.
It gets a little boring having to add a wrapper in all methods
def method() = isAuthenticated { username => implicit request =>
UserDAO.findOneByEmail(username).map { user =>
Ok(html.user.view(user))
}.getOrElse(Forbidden)
}
I’m new to functional programming and all these => is making my head spin 🙂
Any suggestions?
You can define another method, for example
IsAuthenticatedUser, which would take a parameter of typeUser => Request[AnyContent] => Result:You can then use it like as follows: