2012-09-12 34 views
0

我正在編寫一個方法來在用戶驗證後正確設置會話cookie。如下設置cookie不起作用。以下代碼段將導致錯誤的 'withSession' 呼叫:Scala Play Framework中重載的方法錯誤

重載方法值[withSession]不能被應用到((字符串,龍))

代碼:

/** 
* Process login form submission. 
*/ 
def authenticate = Action { implicit request => 
    loginForm.bindFromRequest.fold(
    formWithErrors => BadRequest(views.html.login(formWithErrors)), 
    credentials => { 
     val user = models.User.findByEmail(credentials._1) 

     user match { 
     case Some(u) => { 
      Redirect(routes.Dashboard.index).withSession(Security.username -> u.id) 
     } 
     case None => Redirect(routes.Auth.login) 
     } 
    } 
) 
} 

'憑證'只是一個包含用戶提交的電子郵件和密碼的元組。如果我擺脫'withSession'部分,那麼它運行良好。如果我將「重定向」語句移出模式匹配代碼,則工作正常。爲什麼它不起作用,我如何解決它?

回答