首页 文章

Scala Play Framework中的重载方法错误

提问于
浏览
0

我正在编写一种方法来在用户进行身份验证后正确设置会话cookie . 如下设置cookie不起作用 . 以下代码段会导致'withSession'调用出错:

Overloaded method value [withSession] cannot be applied to ((String, Long))

码:

/**
 * 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'部分,那么它运行正常 . 如果我从模式匹配代码中移出“重定向”语句,那么工作正常 . 为什么它不能像我上面那样工作,我该如何解决?

1 回答

相关问题