.withSession doesn't appear to work with Redirect?

102 views
Skip to first unread message

7es-jeff

unread,
Jun 2, 2012, 3:31:45 PM6/2/12
to play-framework
Hello,

I posted this on Stack Overflow yesterday, but I didn't any responses.
Maybe you guys could help me out?

I am trying to create a new session in the Play 2.0, but it doesn't
seem to stick.

After getting an OpenID result, I want to redirect them back to the
index (for now, anyway), along with the OpenID information they just
got back.

Redirect(routes.Application.index).withSession(
"id" -> info.id,
"email" ->
info.attributes.get("email").getOrElse("unk...@unknown.com"),
"timestamp" -> (System.currentTimeMillis() /
1000L).toString)

This calls the following function:

def index = Action { implicit request =>
Ok(html.index(request))
}

However, the implicit request, according to Eclipse, has null cookies,
and a null session. What's going on here?

If it helps, this is the full function that the OpenID information
comes from:

def openIDCallback = Action { implicit request =>
AsyncResult(
OpenID.verifiedId.extend(_.value match {
case Redeemed(info) => {
Redirect(routes.Application.index).withSession(
"id" -> info.id,
"email" ->
info.attributes.get("email").getOrElse("unk...@unknown.com"),
"timestamp" -> (System.currentTimeMillis() /
1000L).toString)
}
case Thrown(t) => {
// Here you should look at the error, and give feedback to
the user
Redirect(routes.Application.index)
}
}))
}

Thanks!

7es-jeff

unread,
Jun 3, 2012, 3:45:38 PM6/3/12
to play-framework
Nevermind, I figured it out. A little bit of a dumb error on my part.

The nulls are there because the vals are lazy, and the reason for my
initial debugging was that the information I was trying to pull from
the session cookie wasn't working. The actual reason was because I was
using cookie.get(), not session.get(). So when I debugged and saw the
nulls, I thought my problem was in another part of my code, instead of
catching my simple mistake.
Reply all
Reply to author
Forward
0 new messages