Play Framework Scala 2.2.2将多个值存储到会话中

时间:2014-08-02 13:03:51

标签: scala session-variables playframework-2.2

我想将用户角色存储到会话中。我如何在play framework + scala中执行此操作?

我的身份验证方法如下所示:

val loginForm = Form(
    tuple(
      "email" -> text,
      "password" -> text
    ) verifying ("Invalid username or password", result => result match {
      case (email, password) => User.authenticate(email, new sun.misc.BASE64Encoder().encode(md.digest(password.getBytes)).toString()).isDefined
    })
  )

 def authenticate = Action { implicit request =>
    loginForm.bindFromRequest.fold(
      formWithErrors => BadRequest(html.authentication.login(formWithErrors)),
      user => Redirect(routes.Application.index).withSession("username" -> user._1)
    )
  }

我的用户模式如下所示:

  val simple = {
    get[Long]("user.id") ~
      get[String]("user.firstname") ~
      get[String]("user.lastname") ~
      get[String]("user.password") ~
      get[String]("user.email") ~
      get[Long] ("user.role") ~
      get[Long]("user.companyId") map {
      case id~firstname~lastname~password~email~role~companyId => User(id, firstname, lastname, password, email, role, companyId)
    }
  }

0 个答案:

没有答案