Cataly...eLogin(3pm)

πŸ“¦
version 0.21 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 the login or logout actions. 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 with Catalyst::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 a login.tt template file. bye bye extra file πŸ‘‹
  • CatalystX::SimpleLogin::Form::Login β€” the HTML::FormHandler form 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 πŸ”—

  • Catalyst
  • Moose and Moose::Role
  • MooseX::MethodAttributes::Role β€” Actions composed from Moose::Role.
  • CatalystX::InjectComponent β€” Injects the controller class
  • HTML::FormHandler β€” Generates the login form
  • Catalyst::Plugin::Authentication β€” Responsible for the actual heavy lifting of authenticating the user πŸ’ͺ
  • Catalyst::Plugin::Session
  • Catalyst::Controller β€” Allows you to decorate actions with roles (E.g Catalyst::ActionRole::NeedsLogin)
  • CatalystX::Component::Traits β€” Allows Moose::Role to 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