Created
July 29, 2012 21:12
-
-
Save irumiha/3201859 to your computer and use it in GitHub Desktop.
This file contains 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
trait Security { | |
/** | |
* Retrieve the connected user email. | |
*/ | |
private def username(request: RequestHeader) = | |
request.session.get("username") | |
/** | |
* Redirect to login if the user in not authorized. | |
*/ | |
private def onUnauthorized(request: RequestHeader) = | |
Results.Redirect(routes.Application.login()) | |
/** | |
* Action for authenticated users. | |
*/ | |
def ifAuthenticated(f: String => Request[AnyContent] => Result) = | |
Action { req => | |
username(req).map(f(_)(req)) getOrElse(onUnauthorized(req)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment