[Catalyst] Re: Persistent login

Michael Reece mreece at vinq.com
Wed May 16 18:28:22 GMT 2007


there's no especially sane way to extend the session cookie on a per- 
user basis that i have found.


here is a hack that i am experimenting with:

if ($c->login($username, $password)) {
     $c->session->{remember_me} = $c->req->params->{remember_me};
     # ...
}

and in package MyApp.pm (or a plugin or a subclass of the  
State::Cookie plugin or ...)

sub calculate_session_cookie_expires {
     my $c = shift;
     return $c->session->{remember_me}
         ? time() + 60 * 60 * 24 * 90   # 90 days
         : $c->NEXT::calculate_session_cookie_expires(@_);
}


On May 15, 2007, at 6:47 PM, Evaldas Imbrasas wrote:

> On 5/15/07, Jonathan Rockway <jon at jrock.us> wrote:
>> Use the session plugin and set the session expiration to ... 1  
>> week.  If some
>> data needs to expire sooner than that ... expire it sooner than that.
>>
>> Here's what I would do.  Create a session and log the user in.   
>> Store a "last
>> login" time in the user_class.  If the last_login (or last_activity;
>> whatever) is too long ago, delete data from the session and start  
>> over.
>
> Yep, makes sense. However, even in that case, I was hoping that the
> standard session/auth plugins would support this functionality without
> doing anything additional in my Controller::Auth, i.e.:
>
> if ($c->req->params->{login_remember}) {
>  $c->login($email, $password, $expires_long);
> } else {
>  $c->login($email, $password, $expires_short);
> }
>
> Am I wrong in thinking that pretty much any decent login system has to
> support this anyway?.. (This is my first Catalyst project, so I
> wouldn't be surprised if there's a one-liner out there that would
> solve this problem without a need for the above - sorry if that's the
> case.)
>
> -- 
> -----------------------------------------------------
> Evaldas Imbrasas
> http://www.imbrasas.com
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/ 
> catalyst at lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/

---
michael reece :: software engineer :: mreece at vinq.com





More information about the Catalyst mailing list