Cataly...eLogin(3pm)
π NAME π
CatalystX::SimpleLogin β it gives you a whole reusable Login controller, literally one line of code, no cap. This one lives in the User Contributed Perl Documentation corner of the 3pm section, and bestie, it's about to make auth so much less of a whole thing.
π SYNOPSIS π
okay so here's the vibe. You write this, exactly this:
package MyApp;
use Moose;
use namespace::autoclean;
use Catalyst qw/
+CatalystX::SimpleLogin
Authentication
Session
Session::State::Cookie
Session::Store::File
/;
extends 'Catalyst';
__PACKAGE__->config(
'Plugin::Authentication' => { # Auth config here }
);
__PACKAGE__->config(
'Controller::Login' => { # SimpleLogin config here }
);
__PACKAGE__->setup;
and that's it. That's the whole entire setup. π
π ATTENTION! π
ngl if you're brand new here, do not rawdog this page first. Go read CatalystX::SimpleLogin::Manual instead β it's the gentle, hold-your-hand intro to using this code. Come back here when you're done there. π«Ά
πΈ DESCRIPTION πΈ
CatalystX::SimpleLogin is an application class Moose::Role, and what it does is inject a Catalyst::Controller into your application β specifically an instance of CatalystX::SimpleLogin::Controller::Login. β¨
And the payoff? You get a simple login page and a simple logout page, and all it costs you is one line of code plus one template. That's the trade. Iconic honestly. π
β REQUIREMENTS β
Before you get your hopes up, you need all of these:
- A Catalyst application
- Working authentication configuration
- Working session configuration
- A view
π¦ CUSTOMISATION π¦
CatalystX::SimpleLogin is a prototype for CatalystX::Elements. So one of the goals here is making it as easy as possible for users to customise the provided component to the maximum degree possible β and also, to keep a linear relationship between the effort you put in and the level of customisation you get out. Put in a little, get a little. Put in a lot... you get it. π
Three traits ship with SimpleLogin: WithRedirect, Logout, and RenderAsTTTemplate. You set them in the config, like this:
__PACKAGE__->config(
'Controller::Login' => {
traits => [qw/ Logout WithRedirect RenderAsTTTemplate /],
login_form_args => { # see the login form },
);
π§© COMPONENTS π§©
CatalystX::SimpleLogin::Controller::Loginβ your first point of call for customisation. Override the action configs to reconfigure the paths of theloginorlogoutactions. Subclass it if you want to apply method modifiers that run before / after the login or logout actions, or to override methods. π οΈCatalystX::SimpleLogin::TraitFor::Controller::Login::Logoutβ provides the"logout"action and all its associated methods. You can compose this manually yourself if that one action is all you want.
This trait is set by default, but heads up: if you set another trait in your config, you will have to include it. π
CatalystX::SimpleLogin::TraitFor::Controller::Login::WithRedirectβ provides the"login"action with a wrapper that redirects to a page which needs authentication β the page the user was previously redirected from. Goes hand in hand withCatalyst::ActionRole::NeedsLogin. π€CatalystX::SimpleLogin::TraitFor::Controller::Login::RenderAsTTTemplate- sets the stash variable'template'to point to a string reference containing the rendered template, so that it's not necessary to have alogin.tttemplate file. bye bye extra file πCatalystX::SimpleLogin::Form::Loginβ theHTML::FormHandlerform for the login form.Catalyst::ActionRole::NeedsLoginβ Used to cause a specific path to redirect to the login page if a user is not authenticated.
π TODO π
Here's a list of what I think needs working on, in no particular order.
Please feel free to add to or re-arrange this list :)
- Fix extension documentation
- Document all this stuff.
- Examples of use / customisation in documentation
- Fixing one uninitialized value warning in LoginRedirect
- Disable the use of NeedsLogin ActionRole when WithRedirect is not loaded
π» SOURCE CODE π»
http://github.com/bobtfish/catalystx-simplelogin/tree/master
git://github.com/bobtfish/catalystx-simplelogin.git
Forks and patches are welcome. #formhandler or #catalyst (irc.perl.org) are both good places to ask about using or developing this code. come hang out fr fr π«
π SEE ALSO π
CatalystMooseandMoose::RoleMooseX::MethodAttributes::Roleβ Actions composed fromMoose::Role.CatalystX::InjectComponentβ Injects the controller classHTML::FormHandlerβ Generates the login formCatalyst::Plugin::Authenticationβ Responsible for the actual heavy lifting of authenticating the user πͺCatalyst::Plugin::SessionCatalyst::Controllerβ Allows you to decorate actions with roles (E.gCatalyst::ActionRole::NeedsLogin)CatalystX::Component::Traitsβ AllowsMoose::Roleto be composed onto components from config
π AUTHORS π
- Tomas Doran (t0m)
"bobtfish@bobtfish.net" - Zbigniew Lukasiak
- Stephan Jauernick (stephan48)
"stephan@stejau.de" - Gerda Shank (gshank)
"gshank@cpan.org" - Florian Ragwitz
"rafl@debian.org" - Shlomi Fish
- Oleg Kostyuk (cub-uanic)
"cub@cpan.org"
π LICENSE π
Copyright 2009 Tomas Doran. Some rights reserved.
This software is free software, and is licensed under the same terms as perl itself.
and that's a wrap bestie β¨ This page was brought to you by perl v5.36.0, dated 2022-08-28, straight outta the User Contributed Perl Documentation. go build something cute with it π
π¦ 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