/usr/share/perl5/Catalyst/ActionRole/NeedsLogin.pm is in libcatalystx-simplelogin-perl 0.18-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | package Catalyst::ActionRole::NeedsLogin;
use Moose::Role;
use namespace::autoclean;
around execute => sub {
my $orig = shift;
my $self = shift;
my ($controller, $c, @args) = @_;
if (!$c->user) {
my $message = ($self->attributes->{LoginRedirectMessage}[0])
? $self->attributes->{LoginRedirectMessage}[0]
:'You need to login to view this page!';
$c->controller('Login')->login_redirect($c, $message, @args);
$c->detach;
}
else {
return $self->$orig(@_);
}
};
1;
__END__
=head1 NAME
Catalyst::ActionRole::NeedsLogin - checks if a user is logged in and if not redirects him to login page
=head1 SYNOPSIS
package MyApp::Controller::NeedsAuth;
use Moose;
use namespace::autoclean;
# One needs to inherit from Catalyst::Controller in order
# to get the Does('NeedsLogin') functionality.
BEGIN { extends 'Catalyst::Controller'; }
sub inbox : Path Does('NeedsLogin') {
# Redirects to /login if not logged in
my ($self, $c) = @_;
$c->stash->{template} = "inbox.tt2";
return;
}
sub inbox : Path Does('NeedsLogin') :LoginRedirectMessage('Your custom Message') {
# Redirects to /login if not logged in-
}
# Turn on in config
MyApp->config('Contoller::Login' => { traits => ['WithRedirect'] });
=head1 DESCRIPTION
Provides a ActionRole for forcing the user to login.
=head1 WRAPPED METHODS
=head2 execute
If there is no logged-in user, call the login_redirect() method in the
C<'Login'> controller with the Catalyst context object, $c, and the
message specified by the C<:LoginRedirectMessage('Message here')> method
attribute (see the synopsis).
If there is a user logged-in (i.e: C<< $c->user >> is true), execute the body
of the action as it is.
=head1 SEE ALSO
=over
=item L<CatalystX::SimpleLogin::TraitFor::Controller::Login::WithRedirect>
=item L<CatalystX::SimpleLogin::Controller::Login>
=item L<CatalystX::SimpleLogin::Form::Login>
=back
=head1 AUTHORS
See L<CatalystX::SimpleLogin> for authors.
=head1 LICENSE
See L<CatalystX::SimpleLogin> for license.
=cut
|