From: Jess Robinson Date: Fri, 11 May 2012 16:51:08 +0000 (+0000) Subject: Replacing SimpleLogin with Controller::Auth (requires patch to ::Auth) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4dbd098b6a7d334cbda64e4ca5d3d7aca8bbc86e;p=scpubgit%2Fstemmatology.git Replacing SimpleLogin with Controller::Auth (requires patch to ::Auth) Setup to use OpenID as well as local auth.. --- diff --git a/stemmaweb/Makefile.PL b/stemmaweb/Makefile.PL index e42015a..9586aab 100644 --- a/stemmaweb/Makefile.PL +++ b/stemmaweb/Makefile.PL @@ -23,7 +23,7 @@ requires 'Catalyst::Plugin::Authentication'; requires 'Catalyst::Plugin::Session'; requires 'Catalyst::Plugin::Session::Store::File'; requires 'Catalyst::Plugin::Session::State::Cookie'; -requires 'CatalystX::SimpleLogin'; +requires 'CatalystX::Controller::Auth'; ## requires 'Moose'; requires 'TryCatch'; diff --git a/stemmaweb/lib/stemmaweb.pm b/stemmaweb/lib/stemmaweb.pm index b2f68e8..6cf1729 100644 --- a/stemmaweb/lib/stemmaweb.pm +++ b/stemmaweb/lib/stemmaweb.pm @@ -24,11 +24,11 @@ use Catalyst qw/ ConfigLoader Static::Simple Unicode::Encoding - +CatalystX::SimpleLogin Authentication Session Session::Store::File Session::State::Cookie + StatusMessage /; extends 'Catalyst'; @@ -69,7 +69,29 @@ __PACKAGE__->config( class => 'Model::KiokuDB', model_name => 'User', }, - } + }, + openid => { + credential => { + class => 'OpenID', + }, + store => { + class => 'Model::KiokuDB', + model_name => 'User', + }, + auto_create_user => 1, + }, + }, + ## Auth with CatalystX::Controller::Auth + 'Controller::Users' => { + model => 'User', + login_id_field => 'username', + login_db_field => 'username', + action_after_login => '/index', + send_register_email => 0, + realm => 'openid', + login_fields => { openid => [], # qw/openid_identifier/], + default => [qw/username password/], + }, }, ); diff --git a/stemmaweb/lib/stemmaweb/Controller/Users.pm b/stemmaweb/lib/stemmaweb/Controller/Users.pm new file mode 100644 index 0000000..accc85b --- /dev/null +++ b/stemmaweb/lib/stemmaweb/Controller/Users.pm @@ -0,0 +1,50 @@ +package stemmaweb::Controller::Users; +use Moose; +use namespace::autoclean; + +BEGIN {extends 'CatalystX::Controller::Auth'; } + +=head1 NAME + +stemmaweb::Controller::Users - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + +sub base :Chained('/') :PathPart('') :CaptureArgs(0) +{ + my ( $self, $c ) = @_; + + $self->next::method( $c ); +} + +=head2 index + +=cut + +sub index :Path :Args(0) { + my ( $self, $c ) = @_; + + $c->response->body('Matched stemmaweb::Controller::Users in Users.'); +} + + +=head1 AUTHOR + +A clever guy + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +__PACKAGE__->meta->make_immutable; + +1; diff --git a/stemmaweb/lib/stemmaweb/Model/User.pm b/stemmaweb/lib/stemmaweb/Model/User.pm index a987ccd..f10b204 100644 --- a/stemmaweb/lib/stemmaweb/Model/User.pm +++ b/stemmaweb/lib/stemmaweb/Model/User.pm @@ -8,6 +8,8 @@ extends 'Catalyst::Model::KiokuDB'; has '+model_class' => ( default => 'Text::Tradition::UserStore' ); +1; + =head1 NAME stemmaweb::Model::User - User/Auth KiokuDB model for stemmaweb @@ -46,5 +48,3 @@ stores the Users alongside the Traditions. To replace the source of users for authentication, add the configuration shown in the L to your stemmaweb.conf file, and adjust as necessary. - -1; diff --git a/stemmaweb/root/src/auth/login.tt b/stemmaweb/root/src/auth/login.tt new file mode 100644 index 0000000..6af2f51 --- /dev/null +++ b/stemmaweb/root/src/auth/login.tt @@ -0,0 +1,39 @@ +[% IF status_msg %] +

[% status_msg | html %]

+[% END %] +[% IF error_msg %] +

[% error_msg | html %]

+[% END %] + +[% IF form.has_errors %] +

Some fields had errors:

+ + +[% END %] + +
+ + + +
+ +
+
+ + + [% form.field('remember').render %] + [% form.field('submit').render %] + +
\ No newline at end of file diff --git a/stemmaweb/root/src/auth/register.tt b/stemmaweb/root/src/auth/register.tt new file mode 100644 index 0000000..da497e6 --- /dev/null +++ b/stemmaweb/root/src/auth/register.tt @@ -0,0 +1,26 @@ +[% IF status_msg %] +

[% status_msg | html %]

+[% END %] +[% IF error_msg %] +

[% error_msg | html %]

+[% END %] + +[% IF form.has_errors %] +

Some fields had errors:

+ + +[% END %] + +
+ + [% form.field('username').render %] + [% form.field('password').render %] + [% form.field('confirm_password').render %] + + [% form.field('submit').render %] + +
\ No newline at end of file diff --git a/stemmaweb/t/controller_Users.t b/stemmaweb/t/controller_Users.t new file mode 100644 index 0000000..7fe5bfd --- /dev/null +++ b/stemmaweb/t/controller_Users.t @@ -0,0 +1,10 @@ +use strict; +use warnings; +use Test::More; + + +use Catalyst::Test 'stemmaweb'; +use stemmaweb::Controller::Users; + +ok( request('/users')->is_success, 'Request should succeed' ); +done_testing();