| 1 | package CatalystX::SimpleLogin::TraitFor::Controller::Login::Logout; | ||||||||||
| 2 | 8 | ▶ | use MooseX::MethodAttributes::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 8 | ▶ | use MooseX::Types::Moose qw/Str Bool/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 7 | ▶ | sub logout : Chained('/') PathPart('logout') Args(0) { | ||||||||
|
Subroutine
logout: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 7 | 7 | my ($self, $c) = @_; | |||||||||
| 8 | 7 | $c->logout; | |||||||||
| 9 | 7 | $c->change_session_id; | |||||||||
| 10 | 7 | ▶ | $self->do_clear_session_on_logout($c) if $self->clear_session_on_logout; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 11 | 7 | $c->res->redirect($self->redirect_after_logout_uri($c)); | |||||||||
| 12 | 8 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 8 | has clear_session_on_logout => ( | |||||||||
| 15 | isa => Bool, | ||||||||||
| 16 | is => 'ro', | ||||||||||
| 17 | default => 0, | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | sub do_clear_session_on_logout { | ||||||||
|
Subroutine
do_clear_session_on_logout: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 21 | 1 | my ($self, $c) = @_; | |||||||||
| 22 | 1 | $c->delete_session; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 7 | ▶ | sub redirect_after_logout_uri { | ||||||||
|
Subroutine
redirect_after_logout_uri: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 26 | 7 | my ($self, $c) = @_; | |||||||||
| 27 | 7 | $c->uri_for($self->_redirect_after_logout_uri); | |||||||||
| 28 | } | ||||||||||
| 29 | 8 | has _redirect_after_logout_uri => ( | |||||||||
| 30 | isa => Str, | ||||||||||
| 31 | default => '/', | ||||||||||
| 32 | init_arg => 'redirect_after_logout_uri', | ||||||||||
| 33 | is => 'ro', | ||||||||||
| 34 | ); | ||||||||||
| 35 | |||||||||||
| 36 | 8 | 1; | |||||||||
| 37 | |||||||||||
| 38 | =head1 NAME | ||||||||||
| 39 | |||||||||||
| 40 | CatalystX::SimpleLogin::TraitFor::Controller::Login::Logout - log users out | ||||||||||
| 41 | |||||||||||
| 42 | =head1 DESCRIPTION | ||||||||||
| 43 | |||||||||||
| 44 | Simple controller role for logging users out. Provides a | ||||||||||
| 45 | C<logout> action (at /logout by default) which redirects | ||||||||||
| 46 | the user to the homepage by default. | ||||||||||
| 47 | |||||||||||
| 48 | =head1 ACTIONS | ||||||||||
| 49 | |||||||||||
| 50 | =head2 logout : Chained('/') PathPart('logout') Args(0) | ||||||||||
| 51 | |||||||||||
| 52 | Calls C<< $c->logout >>, then redirects to the logout uri | ||||||||||
| 53 | retuned by C<< $self->redirect_after_logout_uri >>. | ||||||||||
| 54 | |||||||||||
| 55 | =head1 METHODS | ||||||||||
| 56 | |||||||||||
| 57 | =head2 redirect_after_logout_uri | ||||||||||
| 58 | |||||||||||
| 59 | Returns the uri to redirect to after logout. | ||||||||||
| 60 | |||||||||||
| 61 | Defaults to C<< $c->uri_for('/'); >> you can override this | ||||||||||
| 62 | by setting the C<<redirect_after_logout_uri>> key in config | ||||||||||
| 63 | to a path to be passed to C<< $c->uri_for >>. | ||||||||||
| 64 | |||||||||||
| 65 | Alternatively, you can write your own redirect_after_logout_uri | ||||||||||
| 66 | in your Login controller if you are extending CatalystX::SimpleLogin | ||||||||||
| 67 | and it will override the method from this role. | ||||||||||
| 68 | |||||||||||
| 69 | =head2 do_clear_session_on_logout | ||||||||||
| 70 | |||||||||||
| 71 | Deletes the session after a logout. | ||||||||||
| 72 | |||||||||||
| 73 | To enable this use the following in your config: | ||||||||||
| 74 | __PACKAGE__->config('Controller::Login' => { clear_session_on_logout => 1 }); | ||||||||||
| 75 | |||||||||||
| 76 | =head1 SEE ALSO | ||||||||||
| 77 | |||||||||||
| 78 | =over | ||||||||||
| 79 | |||||||||||
| 80 | =item L<CatalystX::SimpleLogin::Controller::Login> | ||||||||||
| 81 | |||||||||||
| 82 | =back | ||||||||||
| 83 | |||||||||||
| 84 | =head1 AUTHORS | ||||||||||
| 85 | |||||||||||
| 86 | See L<CatalystX::SimpleLogin> for authors. | ||||||||||
| 87 | |||||||||||
| 88 | =head1 LICENSE | ||||||||||
| 89 | |||||||||||
| 90 | See L<CatalystX::SimpleLogin> for license. | ||||||||||
| 91 | |||||||||||
| 92 | =cut | ||||||||||
| 93 | |||||||||||