2014-01-05 41 views
2

我使用的是PlayFramework 2.1.4和SecureSocial 2.1.1。Play2 SecureSocial,POST在SecureadAction後執行爲GET

我在下面定義了routes,將請求設置爲POST

POST /postComment         controllers.Application.postComment 

一切順利在第一,但SecuredAction後,要求改爲GET。 日誌:

[info] application - onRouteRequest() requestHander = POST /postComment 
[debug] application - [securesocial] anonymous user trying to access : '/postComment' 
[debug] application - [securesocial] assets controller = controllers.ReverseAssets 
[info] application - onRouteRequest() requestHander = GET /login 
[error] application - [securesocial] can't find provider for id userpass 
[info] application - onRouteRequest() requestHander = GET /authenticate/facebook 
[debug] application - [securesocial] user logged in : [SocialUser(IdentityId(...)] 
[info] application - onRouteRequest() requestHander = GET /postComment 
[warn] application - onHandlerNotFound() requestHander = GET /postComment 

我該怎麼辦?請給我你的建議。

表單就是這樣(createComment.scala.html)。

@helper.form(action=routes.Application.postComment){ 
@helper.textarea(commentForm("body")) 
<div class="actions"> 
     <input type="submit" class="btn primary" value="submit"> 
</div> 
} 

,這是Application.scala

case class CommentData(body: String, vote: String) 

object Application extends Controller with SecureSocial { 
val commentForm = Form(mapping("body" -> nonEmptyText)(CommentData.apply)(CommentData.unapply)) 
def postComment = SecuredAction { implicit request => 
val id=session.get("targetCommentId"); 
commentForm.bindFromRequest.fold(
formWithErrors => { 
BadRequest(views.html.createComment(commentForm)).withSession(session+"targetCommentId"->id.toString) 
}, 
commentData => { 
val id = request.user.identityId.userId 
val body = commentData.body 
application.Application.createComment(id, body) 
Ok(views.html.topiclist()) 
}) 
} 
} 

回答

2

SecureSocial重定向到身份驗證後,原來的頁面,但這樣做有303參見其他應答會導致在GET請求目標資源。儘管說您無法重定向POST請求是一種簡化,但它不適用於SecureSocial AFAIK。

一種更好的方式來處理,這將是之前提示驗證用戶提交的點評形式,即:

  • 匿名用戶想要創建一個註釋,點擊「添加註釋」(或任何)
  • 通過FB
  • 重定向到評論表單(GET做認證),現在用經過驗證的用戶
  • 繼續處理表單提交(POST)

您可以閱讀有關POST重定向here的一些問題。

+0

非常感謝!我會在提交之前進行認證。 –