Keep cookie even if session is closed

What will be the best approach to the game! user memorization application? I think the only possible solution is to use cookies on the client side, right? But as soon as the browser shuts down, this session is destroyed and is invalid for the next request? How do you solve (d) this?

At the moment, I have encrypted useridin the session (per session), for example:

session("userid", user.id);

And then I use an interceptor to not skip parameters each when I need it, as described here: How to avoid passing parameters everywhere in play2?

But how to remember a user, or even beter, to automatically register a user at the next request ?

EDIT: 2016-03-11 Keep in mind that some browsers may store session cookies for a longer period. For example, you can install in Chrome to remember open tabs on the next visit. This means that the playback session cookie will be restored the next time you open the browser.

And as in Play 2.4, the session maxAge cookie (you must set to application.conf) is renamed to:play.http.session.maxAge

+5
source share
4 answers

To make a session not a timeout when users close their browser, you can use the parameter session.maxAgein application.conf.

eg:.

# Set session maximum age in seconds (4w)
session.maxAge=2419200 
+5
source

Quote from Play 2.0 Session Documentation :

- . , -. - , , (, , ..).

cookie , , , , .

, , , . , , , , , -, cookie, , .

+1

newSession cookie, .

, cookie , . , cookie dev ( Chrome, Firefox) .

0

, . .

def RememberAction(f: Request[AnyContent] => Result): Action[AnyContent] = {
  Action { request =>
    if (! request.session.get ("email"). isDefined && request.cookies.get ("remember-email"). isDefined) {
      f (request) .asInstanceOf [PlainResult] .withSession ("email" -> request.cookies.get ("remember-email"). get.value)
    } else {
      f (request)
    }
  }
}

Then you can use this action in your controllers as follows:

    def index = RememberAction {implicit request =>
      Ok ("Hello World!")
    }

0
source

All Articles