Skip to content

Instantly share code, notes, and snippets.

@onsails
Created June 15, 2012 08:00
Show Gist options
  • Select an option

  • Save onsails/2935299 to your computer and use it in GitHub Desktop.

Select an option

Save onsails/2935299 to your computer and use it in GitHub Desktop.
Play20 IsAuthenticated helper
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