Catalyst::ActionRole::NeedsLogin - checks if a user is logged in and if not redirects him to login page
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'] });
Provides a ActionRole for forcing the user to login.
If there is no logged-in user, call the login_redirect() method in the 'Login' controller with the Catalyst context object, $c, and the message specified by the :LoginRedirectMessage('Message here') method attribute (see the synopsis).
'Login'
:LoginRedirectMessage('Message here')
If there is a user logged-in (i.e: $c->user is true), execute the body of the action as it is.
$c->user
See CatalystX::SimpleLogin for authors.
See CatalystX::SimpleLogin for license.
To install CatalystX::SimpleLogin, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CatalystX::SimpleLogin
CPAN shell
perl -MCPAN -e shell install CatalystX::SimpleLogin
For more information on module installation, please visit the detailed CPAN module installation guide.