Scala Play session value not saving -



Scala Play session value not saving -

so working on webapp in scala play 2.3 using intellij 14.1.1.

the problem storing values in session. have this:

def authcredentials = action { implicit request => loginform.bindfromrequest.fold( formwitherrors => badrequest(views.html.login(formwitherrors.witherror("badlogin","username or password incorrect."))), goodform => redirect(routes.accountcontroller.display).withsession(request.session + ("username" -> goodform._1)) ) }

and in accountcontroller:

def display = action { implicit request => request.session.get("username").map { username => ok(views.html.account(user.getuser(username))).withsession(request.session + ("username" -> username)) }.getorelse(redirect(routes.logincontroller.login)).withnewsession }

now in the above function finding username , rendering business relationship page once. problem after when want navigate page business relationship page such alter password page or refresh of business relationship page redirect login new session.

what doing wrong , there improve way check if session authenticated access page instead of repeat code on each display function.

it seems simple parentheses problem, seek :

def display = action { implicit request => request.session.get("username").map { username => ok(views.html.account(user.getuser(username))).withsession(request.session + ("username" -> username)) }.getorelse(redirect(routes.logincontroller.login).withnewsession) }

you in fact resetting session in case in controller, withnewsession phone call within getorelse, send new session in case of no username found in current one.

scala session playframework

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -