Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala Play框架中的重载方法错误_Scala_Playframework_Compiler Errors_Playframework 2.0 - Fatal编程技术网

Scala Play框架中的重载方法错误

Scala Play框架中的重载方法错误,scala,playframework,compiler-errors,playframework-2.0,Scala,Playframework,Compiler Errors,Playframework 2.0,我正在编写一个方法,以便在用户进行身份验证后正确设置会话cookie。按以下方式设置cookie不起作用。以下代码段导致“withSession”调用出错: 重载的方法值[withSession]不能应用于((字符串,Long)) 代码: “凭据”只是一个元组,包含用户提交的电子邮件和密码。如果我去掉了“withSession”部分,那么它运行良好。如果我将“Redirect”语句从模式匹配代码中移出,那么is就可以正常工作。为什么它不能像我上面所说的那样工作?如何修复它?我认为withSess

我正在编写一个方法,以便在用户进行身份验证后正确设置会话cookie。按以下方式设置cookie不起作用。以下代码段导致“withSession”调用出错:

重载的方法值[withSession]不能应用于((字符串,Long))

代码:


“凭据”只是一个元组,包含用户提交的电子邮件和密码。如果我去掉了“withSession”部分,那么它运行良好。如果我将“Redirect”语句从模式匹配代码中移出,那么is就可以正常工作。为什么它不能像我上面所说的那样工作?如何修复它?

我认为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)
      }
    }
  )
}
def withSession(session: (String, String)*): PlainResult = withSession(Session(session.toMap))