Permalink
Browse files

improved signatures for SecuredAction

  • Loading branch information...
jaliss committed Nov 28, 2012
1 parent 0cd784b commit 996ec756348c0e150f89358a3d2b447358288609
@@ -70,13 +70,13 @@ object PasswordChange extends Controller with SecureSocial {
}
}
- def page = SecuredAction() { implicit request =>
+ def page = SecuredAction { implicit request =>
execute { (request: SecuredRequest[AnyContent], form: Form[ChangeInfo]) =>
Ok(use[TemplatesPlugin].getPasswordChangePage(request, form))
}
}
- def handlePasswordChange = SecuredAction() { implicit request =>
+ def handlePasswordChange = SecuredAction { implicit request =>
execute { (request: SecuredRequest[AnyContent], form: Form[ChangeInfo]) =>
form.bindFromRequest()(request).fold (
errors => BadRequest(use[TemplatesPlugin].getPasswordChangePage(request, errors)),
@@ -59,9 +59,10 @@ trait SecureSocial extends Controller {
* A secured action. If there is no user in the session the request is redirected
* to the login page
*
- * @param ajaxCall A boolean specifying if this is request is for a ajax call or not
- * @param p
- * @param f
+ * @param ajaxCall a boolean indicating whether this is an ajax call or not
+ * @param authorize an Authorize object that checks if the user is authorized to invoke the action
+ * @param p the body parser to use
+ * @param f the wrapped action to invoke
* @tparam A
* @return
*/
@@ -103,14 +104,49 @@ trait SecureSocial extends Controller {
/**
* A secured action. If there is no user in the session the request is redirected
* to the login page.
- * @param f
+ *
+ * @param ajaxCall a boolean indicating whether this is an ajax call or not
+ * @param authorize an Authorize object that checks if the user is authorized to invoke the action
+ * @param f the wrapped action to invoke
* @return
*/
- def SecuredAction(ajaxCall: Boolean = false, authorize: Option[Authorization] = None)
+ def SecuredAction(ajaxCall: Boolean, authorize: Authorization)
(f: SecuredRequest[AnyContent] => Result): Action[AnyContent] =
- {
- SecuredAction(ajaxCall, authorize, parse.anyContent)(f)
- }
+ SecuredAction(ajaxCall, Some(authorize), p = parse.anyContent)(f)
+
+ /**
+ * A secured action. If there is no user in the session the request is redirected
+ * to the login page.
+ *
+ * @param authorize an Authorize object that checks if the user is authorized to invoke the action
+ * @param f the wrapped action to invoke
+ * @return
+ */
+ def SecuredAction(authorize: Authorization)
+ (f: SecuredRequest[AnyContent] => Result): Action[AnyContent] =
+ SecuredAction(false,authorize)(f)
+
+ /**
+ * A secured action. If there is no user in the session the request is redirected
+ * to the login page.
+ *
+ * @param ajaxCall a boolean indicating whether this is an ajax call or not
+ * @param f the wrapped action to invoke
+ * @return
+ */
+ def SecuredAction(ajaxCall: Boolean)
+ (f: SecuredRequest[AnyContent] => Result): Action[AnyContent] =
+ SecuredAction(ajaxCall, None, parse.anyContent)(f)
+
+ /**
+ * A secured action. If there is no user in the session the request is redirected
+ * to the login page.
+ *
+ * @param f the wrapped action to invoke
+ * @return
+ */
+ def SecuredAction(f: SecuredRequest[AnyContent] => Result): Action[AnyContent] =
+ SecuredAction(false)(f)
/**
* A request that adds the User for the current call
@@ -21,12 +21,12 @@ import securesocial.core.{SocialUser, Authorization}
object Application extends Controller with securesocial.core.SecureSocial {
- def index = SecuredAction() { implicit request =>
+ def index = SecuredAction { implicit request =>
Ok(views.html.index(request.user))
}
// a sample action using the new authorization hook
- def onlyTwitter = SecuredAction(authorize = Some(WithProvider("twitter"))) { implicit request =>
+ def onlyTwitter = SecuredAction(WithProvider("twitter")) { implicit request =>
Ok("You can see this because you logged in using Twitter")
}
}

0 comments on commit 996ec75

Please sign in to comment.