| 1 | package Catalyst::Plugin::Session::PerUser::AutoLogout; | ||
| 2 | use Moose; | ||
| 3 | extends 'Catalyst::Plugin::Session::PerUser'; | ||
| 4 | |||
| 5 | our $VERSION = '0.002'; | ||
| 6 | |||
| 7 | after set_authenticated => sub { | ||
| 8 | my $c = shift; | ||
| 9 | |||
| 10 | if (my $existing_session = $c->user_session->{session_id}) { | ||
| 11 | $c->delete_session_data("${_}:$existing_session") for qw/session flash expires/; | ||
| 12 | $c->user_session->{logged_out} = $existing_session; | ||
| 13 | } | ||
| 14 | |||
| 15 | $c->user_session->{session_id} = $c->sessionid; | ||
| 16 | }; | ||
| 17 | |||
| 18 | 1; | ||
| 19 | |||
| 20 | =head1 NAME | ||
| 21 | |||
| 22 | Catalyst::Plugin::Session::PerUser::AutoLogout - Log a user out of other sessions | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | For some reason, you might want to ensure each user is only logged in once. This | ||
| 27 | plugin extends L<Catalyst::Plugin::Session::PerUser> and automatically removes a | ||
| 28 | user's previous session whenever they log in again, thus forcing that other | ||
| 29 | session to end and logging them out. | ||
| 30 | |||
| 31 | I<You> would probably not want to do this, but you might be being paid by | ||
| 32 | someone who does want that. |