Cataly...sLogin(3pm)
π Catalyst::ActionRole::NeedsLogin(3pm) π
okay so bestie, gather round, because this one is short but it is mighty. This is the manual page for Catalyst::ActionRole::NeedsLogin β a little ActionRole that checks if somebody's logged in, and if they're not? It yeets them straight to the login page. No cap. πͺβ¨
πΈ NAME πΈ
Catalyst::ActionRole::NeedsLogin β checks if a user is logged in and if not redirects him to login page
it's giving "bouncer at the club but for your web app" π
β¨ 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'] });
lowkey the whole plot is right there: slap Does('NeedsLogin') on an action, and boom, that action is now members-only. π You can even hand it a :LoginRedirectMessage('...') attribute so the redirect says your custom thing instead of the default vibe. And yes, that config line up there says 'Contoller::Login' β copy it exactly as written, bestie, I do not make the rules, I just report them fr fr π«Ά
π¦ DESCRIPTION π¦
Provides a ActionRole for forcing the user to login.
that's it. that's the whole description. short, sweet, and iconic. it exists to make your users prove who they are before they get the goods. π
π WRAPPED METHODS π
execute
- If there is no logged-in user, it calls 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 (peep the synopsis, it's all there π). - If there is a user logged-in (i.e:
$c->useris true), it executes the body of the action as it is. Like, just runs it normally. Business as usual. π
so: no user β redirected. user β your code runs. the vibe check happens automatically and you didn't even have to lift a finger. π
π SEE ALSO π
go read these next, besties, they're the extended universe:
CatalystX::SimpleLogin::TraitFor::Controller::Login::WithRedirectCatalystX::SimpleLogin::Controller::LoginCatalystX::SimpleLogin::Form::Login
π AUTHORS π
See CatalystX::SimpleLogin for authors.
(the authors are being mysterious and forwarding you to the other page. respect the mystery. π«‘)
π LICENSE π
See CatalystX::SimpleLogin for license.
aaaand that's the whole page, you ate it, you read the entire thing, I'm so proud π₯Ή
this little beauty shipped as part of perl v5.36.0, dated 2022-08-28 β so give it a kiss goodbye and go protect your inbox, main character. πβ¨π
π¦ where this page comes from
- ubuntu noble: libcatalystx-simplelogin-perl 0.21-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcatalystx-simplelogin-perl 0.21-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatalystx-simplelogin-perl 0.21-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms