CatalystX::Controller::Auth - A config-driven Catalyst authentication controller base class.
Version 0.12
This is a Catalyst controller for handling logging in/out and forgotten/changing/resetting passwords.
This controller was essentially born out of HTML::FormHandlerX::Form::Login (which it obviously uses), though that form does not want to become dependant on Catalyst.
See CatalystX::SimpleLogin for an alternative (the plan is for both to merge).
Extend it for your own authentication controller, then modify your config as required.
package MyApp::Controller::Auth; use Moose; use namespace::autoclean; BEGIN { extends 'CatalystX::Controller::Auth'; } __PACKAGE__->meta->make_immutable; 1;
Configure it as you like ...
<Controller::Auth> form_handler HTML::FormHandlerX::Form::Login view TT model DB::User login_id_field email login_id_db_field email register_template auth/register.tt login_template auth/login.tt change_password_template auth/change-password.tt forgot_password_template auth/forgot-password.tt reset_password_template auth/reset-password.tt forgot_password_email_view Email::Template forgot_password_email_from "Password Reset" <nobody@example.com> forgot_password_email_subject Password Reset forgot_password_email_template_plain reset-password-plain.tt register_successful_message "You are now registered" register_exists_failed_message "That username is already registered." login_required_message "You need to login." already_logged_in_message "You are already logged in." login_successful_message "Logged in!" logout_successful_message "You have been logged out successfully." login_failed_message "Bad username or password." password_changed_message "Password changed." password_reset_message "Password reset successfully." forgot_password_id_unknown "Email address not registered." token_salt 'tgve546vy6yv%^$fghY56VH54& H54&%$uy^5 Y^53U&$u v5ev' auto_login_after_register 1 action_after_register /admin/index action_after_login /admin/index action_after_change_password /admin/index </Controller::Auth>
Override actions as necessary (hopefully not too much, otherwise I have not built this right).
All feedback and patches are always welcome.
The controller currently bases off /base, ie...
/base
sub base :Chained('/base') :PathPart('') :CaptureArgs(0)
Override the base of the chain if you wish to chain off some other mid-point in your own app.
sub base :Chained('/my_base') :PathPart('users') :CaptureArgs(0) { my ( $self, $c ) = @_; $self->next::method( $c ); }
Chain off this action to make sure people are logged in.
sub authenticated :Chained('base') :PathPart('') :CaptureArgs(0)
Register.
sub register :Chained('base') :PathPart :Args(0)
Login, redirect if already logged in.
sub login :Chained('base') :PathPart :Args(0)
Logs out, and redirects back to /login.
sub logout :Chained('base') :PathPart :Args(0)
Send a forgotten password token to reset it.
sub forgot_password :Chained('base') :PathPart('forgot-password') :Args(0)
Uses Catalyst::View::Email::Template by default.
Catalyst::View::Email::Template
Reset password using a token sent in an email.
sub reset_password :Chained('base') :PathPart('reset-password') :Args(0)
Gets a user and puts them in the stash.
sub get :Chained('base') :PathPart('auth') :CaptureArgs(1)
Change your password.
sub change_password :Chained('get') :PathPart('change-password') :Args(0)
Damn more tests!
Rob Brown, <rob at intelcompute.com>
<rob at intelcompute.com>
Please report any bugs or feature requests to bug-catalystx-controller-auth at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-Controller-Auth. I will be notified, and then you will automatically be notified of progress on your bug as I make changes.
bug-catalystx-controller-auth at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc CatalystX::Controller::Auth
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-Controller-Auth
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/CatalystX-Controller-Auth
CPAN Ratings
http://cpanratings.perl.org/d/CatalystX-Controller-Auth
Search CPAN
http://search.cpan.org/dist/CatalystX-Controller-Auth/
t0m: Tomas Doran <bobtfish@bobtfish.net>
Copyright 2012 Rob Brown.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install CatalystX::Controller::Auth, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CatalystX::Controller::Auth
CPAN shell
perl -MCPAN -e shell install CatalystX::Controller::Auth
For more information on module installation, please visit the detailed CPAN module installation guide.