Skip to content

Instantly share code, notes, and snippets.

@cb372
Created February 18, 2016 18:22
Show Gist options
  • Save cb372/68cb049a05c2aa050f2c to your computer and use it in GitHub Desktop.
Save cb372/68cb049a05c2aa050f2c to your computer and use it in GitHub Desktop.
import play.api.mvc.Security
object AuthAction extends Security.AuthenticatedBuilder[User](...)
type AuthReq = Security.AuthenticatedRequest[_, User]
object AuditLogAction extends ActionFunction[AuthReq, AuthReq] {
def invokeBlock[A](request: AuthReq[A], block: AuthReq[A] => Future[Result]): Future[Result] = {
/*
* 本当はPOSTの場合、request.body.asFormUrlEncoded も出力したいけど、
* AnyContent でなく A しか持ってない。
* ジェネリクスを無くして A を AnyContent に固定したい。
*/
println(s"User: ${request.user.email}, path: ${request.path}, method: ${request.method}")
block(request)
}
}
object MyCtlr extends Controller {
def authPage = (AuthAction andThen AuditLogAction){ implicit request =>
// ...
}
}
@lloydmeta
Copy link

Would the following work?

def invokeBlock[A](request: AuthReq[A], block: AuthReq[A] => Future[Result]): Future[Result] = {
   request.body match {
      case c: AnyContent => c.asFormUrlEncoded.foreach(println)
      case _ => // not AnyContent
    }
   // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment