Replacing SimpleLogin with Controller::Auth (requires patch to ::Auth)
Jess Robinson [Fri, 11 May 2012 16:51:08 +0000 (16:51 +0000)]
Setup to use OpenID as well as local auth..

stemmaweb/Makefile.PL
stemmaweb/lib/stemmaweb.pm
stemmaweb/lib/stemmaweb/Controller/Users.pm [new file with mode: 0644]
stemmaweb/lib/stemmaweb/Model/User.pm
stemmaweb/root/src/auth/login.tt [new file with mode: 0644]
stemmaweb/root/src/auth/register.tt [new file with mode: 0644]
stemmaweb/t/controller_Users.t [new file with mode: 0644]

index e42015a..9586aab 100644 (file)
@@ -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';
index b2f68e8..6cf1729 100644 (file)
@@ -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 (file)
index 0000000..accc85b
--- /dev/null
@@ -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;
index a987ccd..f10b204 100644 (file)
@@ -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</SYNOPSIS> 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 (file)
index 0000000..6af2f51
--- /dev/null
@@ -0,0 +1,39 @@
+[% IF status_msg %]
+                       <p>[% status_msg | html %]</p>
+[% END %]
+[% IF error_msg %]
+                       <p class="error">[% error_msg | html %]</p>
+[% END %]
+
+[% IF form.has_errors %]
+                       <p class="error">Some fields had errors:</p>
+                                       
+                       <ul class="errors">
+       [% FOREACH msg IN form.errors %]
+                               <li>[% msg | html %]</li>
+       [% END %]
+                       </ul>
+[% END %]
+
+       <form method="post" action="[% c.uri_for_action('/users/login').hostless | html %]" autocomplete="off">
+
+    <select name="realm">
+     <option value="default">Local</option>
+     <option value="openid">OpenID</option>
+    </select>
+
+<div id="field-openid-identifier">
+<label for="openid_identifier">OpenID login/url</label>
+<input type="text" name="openid_identifier" id="openid_identifier"/><br>
+</div>
+
+<!--
+<div style="display:none">
+       [% form.field('username').render %]
+       [% form.field('password').render %]
+</div>
+-->
+    [% form.field('remember').render %]
+       [% form.field('submit').render %]
+
+       </form>
\ 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 (file)
index 0000000..da497e6
--- /dev/null
@@ -0,0 +1,26 @@
+[% IF status_msg %]
+                       <p>[% status_msg | html %]</p>
+[% END %]
+[% IF error_msg %]
+                       <p class="error">[% error_msg | html %]</p>
+[% END %]
+
+[% IF form.has_errors %]
+                       <p class="error">Some fields had errors:</p>
+                                       
+                       <ul class="errors">
+       [% FOREACH msg IN form.errors %]
+                               <li>[% msg | html %]</li>
+       [% END %]
+                       </ul>
+[% END %]
+
+       <form method="post" action="[% c.uri_for_action('/users/register').hostless | html %]" autocomplete="off">
+
+       [% form.field('username').render %]
+       [% form.field('password').render %]
+       [% form.field('confirm_password').render %]
+
+       [% form.field('submit').render %]
+
+       </form>
\ No newline at end of file
diff --git a/stemmaweb/t/controller_Users.t b/stemmaweb/t/controller_Users.t
new file mode 100644 (file)
index 0000000..7fe5bfd
--- /dev/null
@@ -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();