[Catalyst] Session

Will Smith willbelair at yahoo.com
Tue Mar 28 16:11:27 CEST 2006


Thanks Yuval,
   
  I'll try that.
   
  Regards,
   
  Will

Yuval Kogman <nothingmuch at woobling.org> wrote:
  On Mon, Mar 27, 2006 at 21:17:18 -0800, Will Smith wrote:
> Hello,
> I have a couple questions that I would like to ask. I am using these Session plugins for my app:
> Session Session::Store::File Session::State::Cookie
> 
> I have a sub that logs the user out and kills the session:
> $c->session->delete();

$c->session returns a hash reference, not an object.

> 1- Could someone please show me how to kill this session. I have
> tried $c->session_delete(); and clear(), but still get errors.

In Catalyst::Plugin::Session's documentation (e.g. here:
http://search.cpan.org/perldoc?Catalyst%3A%3APlugin%3A%3ASession)
you can find the delete_session method, which does what you want.

> 2- How could I control a user's session, in other words, a user
> can login at one machine only; if that user (or someone else)
> tries to login at another machine at the same time, the previous
> login will be kicked out. Please give me some sample code that I
> could start with.

I hope you're using Catalyst::Plugin::Authentication

Todo this you need to keep a link to the session data within the
user table. Then you could override the set_authenticated method
(called after a successful login, or any other credential):

sub set_authenticated {
my ( $c, $user ) = @_;
$user->sessionid( $c->sessionid );
$self->NEXT::set_authenticated( $user );
}

Then override the 'prepare' routine in post order, to perform
additional verification:

sub prepare {
my $c = shift->NEXT::prepare(@_); # post order

if ( $c->user_exists ) {
my $user = $c->user;
unless ( $user->sessionid eq $c->sessionid ) {
$c->stash->{logout_reason} = "logged in in separate session";
$c->logout;
}
}
}

I hope this works for you!

-- 
Yuval Kogman 
http://nothingmuch.woobling.org 0xEBD27418

_______________________________________________
Catalyst mailing list
Catalyst at lists.rawmode.org
http://lists.rawmode.org/mailman/listinfo/catalyst


		
---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060328/3fa4fbc5/attachment.htm 


More information about the Catalyst mailing list