Created
June 15, 2012 08:00
-
-
Save onsails/2935299 to your computer and use it in GitHub Desktop.
Play20 IsAuthenticated helper
This file contains hidden or 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
| def IsAuthenticated( | |
| f: => AuthenticatedRequest => Result, | |
| x: => RequestHeader => Result = onUnauthorized) = { | |
| Security.Authenticated(sessionUserId, x) { id => | |
| User.findById(id.toLong).map { user => | |
| Action(request => f(AuthenticatedRequest(user, request))) | |
| }.getOrElse( | |
| Action(request => onUnauthorized(request).withSession(Session()))) | |
| } | |
| } | |
| def securedAction = IsAuthenticated { implicit request => | |
| Ok("Secured result") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment