Setting a cookie resets the session?
I have a login page POST handler, and I want to remember the login parameters for the next attempt: post '/login' => sub { if (handle_login(stuff)) { cookie 'myapp' => { 'username' => params->{username}, 'other' => params->{stuff}, }; redirect '/'; # top-level app URL } # else, login failed, so stay on /login route }; It seems that as soon as I set the cookie, I invalidate the session. I know this because I have a "before" hook that checks whether the session is logged in, and bounces me back to the '/login' route. Without the cookie() call, I get logged in, and go to '/'. With it, I keep getting bounced back to '/login' because Dumper(session) gives me a blank session with only an id field set. How and where am I *supposed* to set the cookie, so it stays attached to the newly-logged-in session?
On Thu, Feb 13, 2014 at 11:59 PM, Warren Young <warren@etr-usa.com> wrote:
I have a login page POST handler, and I want to remember the login parameters for the next attempt:
post '/login' => sub { if (handle_login(stuff)) { cookie 'myapp' => { 'username' => params->{username}, 'other' => params->{stuff}, };
redirect '/'; # top-level app URL } # else, login failed, so stay on /login route };
It seems that as soon as I set the cookie, I invalidate the session.
I know this because I have a "before" hook that checks whether the session is logged in, and bounces me back to the '/login' route. Without the cookie() call, I get logged in, and go to '/'. With it, I keep getting bounced back to '/login' because Dumper(session) gives me a blank session with only an id field set.
How and where am I *supposed* to set the cookie, so it stays attached to the newly-logged-in session?
The session engine already abstracts out the cookie stuff for you. It creates a cookie behind the scenes (I think called dancer.session). Generally, you don't need to set a cookie, unless you are doing something fancy. I think what you want to do is simply: session user_name => params->{username}, session other => params->{stuff}; -Naveed Massjouni
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On 2/14/2014 01:08, Naveed Massjouni wrote:
I think what you want to do is simply:
session user_name => params->{username}, session other => params->{stuff};
No. The session goes away when the user logs out. When the user logs out, they get bounced back to the login page, and I want the user info and other parameters available to use when building that page, to pre-populate all the fields except for password.
On 2/13/2014 21:59, Warren Young wrote:
I have a login page POST handler, and I want to remember the login parameters for the next attempt:
post '/login' => sub { if (handle_login(stuff)) { cookie 'myapp' => { 'username' => params->{username}, 'other' => params->{stuff}, };
For the archives: I figured out the problem. I had 'session_name' set to 'myapp' in config.yml, which means my login parameter cookie was overwriting the session cookie. I must not have been thinking clearly when I did that, because it's obvious to me now that they're separate things, with necessarily different lifetimes.
participants (2)
-
Naveed Massjouni -
Warren Young