Pergunta

I have a method now that validates a username and password and returns a unique Ticket Option[String] for a session: User.authenticate(username, password).

I'm trying to work from the zentask example. I want to be able to validate the username and password and then put the ticket into a session parameter called sessiontoken. With what I'm doing now, I end up with the username instead of the ticket value in the session variable sessiontoken.

val loginForm = Form(
    tuple(
      "username" -> text,
      "password" -> text
    ) verifying ("Invalid username or password", result => result match {
      case (username, password) => 
         User.authenticate(username, password).isDefined
    })
  )


def authenticate = Action { implicit request =>
    loginForm.bindFromRequest.fold(
      formWithErrors => BadRequest(html.login(formWithErrors)),
      token => Redirect(routes.Application.index).withSession("sessiontoken" -> token._1)
    )
  }
Foi útil?

Solução

Your issue is that the loginForm you have is return a tuple with user/password. You are doing an authenticate to validate but you are not mapping to a token.

You are probably looking to use mapping instead of tuple if you want your form to return a token.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top