Reputation: 12990
Say I have a Action and I want it to optionally force https.
How can I add a parameter to a custom action?
import play.api.mvc._
def onlyHttps[A](action: Action[A]) = Action.async(action.parser) { request =>
request.headers.get("X-Forwarded-Proto").collect {
case "https" => action(request)
} getOrElse {
Future.successful(Forbidden("Only HTTPS requests allowed"))
}
}
So in my controller:
def index = onlyHttps(false) {
// ..
}
Another area is I want to check if the currently logged in user has a certain level of permission, so I want to pass the permission type(s) as a parameter to my custom actions.
Upvotes: 2
Views: 80
Reputation: 160005
Simply add another parameter list:
def onlyHttps[A](limitToHttps: Boolean)(action: Action[A]) = /*
Your implementation here. You can access `limitToHttps` here. */
Upvotes: 2