Second cookie [ for 'remember me' username only ]
Hi all, I'd like to have a 'remember me' cookie for users who want their username to be remembered by the browser (but not the password). Dancer2::Core::Role::SessionFactory's set_cookie_header seems quite specific to sessions, so it appears that the right/best way to do it is to use push_header (as set_cookie_header does), viz: if (is_successful_login && defined params->{remember_me} && params->{remember_me}) { push_header( 'Set-Cookie', (remember_me_user => session('user')) ); } Is there a well-defined pattern for this? cheers, Nathan
On Mon, 24 Apr 2017 10:25:35 +1000 Nathan Bailey wrote:
Hi all, I'd like to have a 'remember me' cookie for users who want their username to be remembered by the browser (but not the password).
Dancer2::Core::Role::SessionFactory's set_cookie_header seems quite specific to sessions, so it appears that the right/best way to do it is to use push_header (as set_cookie_header does), viz: if (is_successful_login && defined params->{remember_me} && params->{remember_me}) { push_header( 'Set-Cookie', (remember_me_user => session('user')) ); }
You can just use the Dancer keyword "cookie": cookie 'remember_me_user' => session('user'), http_only => 1; Regards, Andy
Awesome! I have no idea how I missed that part of the manual. I'm using: cookie 'remember_me_user' => undef, http_only => 1, expires => -1; if they turn it off, which seems to delete it immediately. thanks, Nathan On 24 April 2017 at 17:21, Andrew Beverley <andy@andybev.com> wrote:
On Mon, 24 Apr 2017 10:25:35 +1000 Nathan Bailey wrote:
Hi all, I'd like to have a 'remember me' cookie for users who want their username to be remembered by the browser (but not the password).
Dancer2::Core::Role::SessionFactory's set_cookie_header seems quite specific to sessions, so it appears that the right/best way to do it is to use push_header (as set_cookie_header does), viz: if (is_successful_login && defined params->{remember_me} && params->{remember_me}) { push_header( 'Set-Cookie', (remember_me_user => session('user')) ); }
You can just use the Dancer keyword "cookie":
cookie 'remember_me_user' => session('user'), http_only => 1;
Regards,
Andy
participants (2)
-
Andrew Beverley -
Nathan Bailey