简体   繁体   English

Scala Play Framework中的方法重载错误

[英]Overloaded method error in Scala Play Framework

I am writing a method to set the session cookie properly after a user authenticates. 我正在编写一种在用户验证后正确设置会话cookie的方法。 Setting the cookies as follows does not work. 如下设置cookie无效。 The following snippet results in an error with the 'withSession' call: 以下代码段导致“ withSession”调用出错:

Overloaded method value [withSession] cannot be applied to ((String, Long)) 重载的方法值[withSession]无法应用于(((String,Long))

Code: 码:

/**
 * 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)
      }
    }
  )
}

'credentials' is simply a tuple with the email and password submitted by the user. “凭据”只是一个包含用户提交的电子邮件和密码的元组。 If I get rid of 'withSession' part then it runs fine. 如果我摆脱了“ withSession”部分,那么它将运行良好。 If I move the 'Redirect' statement out of the pattern matching code then is works fine. 如果我将“重定向”语句从模式匹配代码中移出,则工作正常。 Why does it not work as I have it above and how do I fix it? 为什么上面没有显示它不起作用?如何解决?

I think withSession expects a String, String 我认为withSession需要一个String,String

Have a look at http://www.playframework.org/documentation/api/2.0.3/scala/index.html#play.api.mvc.SimpleResult 看看http://www.playframework.org/documentation/api/2.0.3/scala/index.html#play.api.mvc.SimpleResult

def withSession(session: (String, String)*): PlainResult = withSession(Session(session.toMap))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM