[Catalyst-commits] r7652 - / trunk/examples/NewAuthApp trunk/examples/NewAuthApp/lib trunk/examples/NewAuthApp/lib/NewAuthApp/Controller trunk/examples/NewAuthApp/root trunk/examples/NewAuthApp/root/admin trunk/examples/NewAuthApp/root/auth trunk/examples/NewAuthApp/t

zarquon at dev.catalyst.perl.org zarquon at dev.catalyst.perl.org
Wed Apr 30 11:42:03 BST 2008


Author: zarquon
Date: 2008-04-30 11:42:03 +0100 (Wed, 30 Apr 2008)
New Revision: 7652

Added:
   trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Admin.pm
   trunk/examples/NewAuthApp/root/admin/
   trunk/examples/NewAuthApp/root/admin/index.tt
   trunk/examples/NewAuthApp/root/auth/unauth.tt
   trunk/examples/NewAuthApp/t/controller_Admin.t
Modified:
   /
   trunk/examples/NewAuthApp/Makefile.PL
   trunk/examples/NewAuthApp/lib/NewAuthApp.pm
   trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Auth.pm
   trunk/examples/NewAuthApp/newauthapp.conf
   trunk/examples/NewAuthApp/root/auth/login.tt
   trunk/examples/NewAuthApp/root/success.tt
Log:
 r12997 at zaphod:  kd | 2008-04-30 13:01:59 +1000
 now with authorization



Property changes on: 
___________________________________________________________________
Name: svk:merge
   - 1b129c88-ebf4-0310-add9-f09427935aba:/local/catalyst:4278
1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst:12996
3b9770f9-e80c-0410-a7de-cd203d167417:/local/catalyst:3514
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst:6909
   + 1b129c88-ebf4-0310-add9-f09427935aba:/local/catalyst:4278
1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst:12997
3b9770f9-e80c-0410-a7de-cd203d167417:/local/catalyst:3514
dd8ad9ea-0304-0410-a433-df5f223e7bc0:/local/Catalyst:6909

Modified: trunk/examples/NewAuthApp/Makefile.PL
===================================================================
--- trunk/examples/NewAuthApp/Makefile.PL	2008-04-30 10:41:18 UTC (rev 7651)
+++ trunk/examples/NewAuthApp/Makefile.PL	2008-04-30 10:42:03 UTC (rev 7652)
@@ -7,6 +7,7 @@
 requires 'Catalyst::Plugin::ConfigLoader';
 requires 'Catalyst::Plugin::Static::Simple';
 requires 'Catalyst::Plugin::Authentication';
+requires 'Catalyst::Plugin::Authorization::Roles';
 requires 'Catalyst::Plugin::Session';
 requires 'Catalyst::Plugin::Session::State::Cookie';
 requires 'Catalyst::Plugin::Session::Store::FastMmapp';

Added: trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Admin.pm
===================================================================
--- trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Admin.pm	                        (rev 0)
+++ trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Admin.pm	2008-04-30 10:42:03 UTC (rev 7652)
@@ -0,0 +1,23 @@
+package NewAuthApp::Controller::Admin;
+
+use strict;
+use warnings;
+use base 'Catalyst::Controller';
+
+sub auto : Private {
+    my ($self, $c) = @_;
+    if ($c->check_user_roles(qw/admin/)) {
+        return 1;
+    }
+    else {
+        $c->stash->{template} = 'auth/unauth.tt';
+        return 0;
+    }
+}
+
+sub index : Private {
+    my ($self, $c) = @_;
+    $c->stash->{template} = 'admin/index.tt';
+}
+
+1;

Modified: trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Auth.pm
===================================================================
--- trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Auth.pm	2008-04-30 10:41:18 UTC (rev 7651)
+++ trunk/examples/NewAuthApp/lib/NewAuthApp/Controller/Auth.pm	2008-04-30 10:42:03 UTC (rev 7652)
@@ -42,5 +42,9 @@
     }
 }
 
+sub unauthorized : Private {
+    my ($self, $c) = @_;
+    $c->stash->{template}= 'auth/unauth.tt';
+}
 
 1;

Modified: trunk/examples/NewAuthApp/lib/NewAuthApp.pm
===================================================================
--- trunk/examples/NewAuthApp/lib/NewAuthApp.pm	2008-04-30 10:41:18 UTC (rev 7651)
+++ trunk/examples/NewAuthApp/lib/NewAuthApp.pm	2008-04-30 10:42:03 UTC (rev 7652)
@@ -8,6 +8,7 @@
                ConfigLoader
                Static::Simple
                Authentication
+               Authorization::Roles
                Session
                Session::State::Cookie
                Session::Store::FastMmap

Modified: trunk/examples/NewAuthApp/newauthapp.conf
===================================================================
--- trunk/examples/NewAuthApp/newauthapp.conf	2008-04-30 10:41:18 UTC (rev 7651)
+++ trunk/examples/NewAuthApp/newauthapp.conf	2008-04-30 10:42:03 UTC (rev 7652)
@@ -1,4 +1,5 @@
 name NewAuthApp
+admin me at example.com
 <Plugin::Authentication>
     <realms>
         <members>
@@ -6,13 +7,12 @@
                 class   Minimal
                 <users>
                     <bob>
-                        roles   edit
-                        roles   delete
+                        roles   user
+                        roles   admin
                         password   bob
-                        editor   yes
                     </bob>
                     <bill>
-                        roles   comment
+                        roles   user
                         password   bill
                     </bill>
                 </users>

Added: trunk/examples/NewAuthApp/root/admin/index.tt
===================================================================
--- trunk/examples/NewAuthApp/root/admin/index.tt	                        (rev 0)
+++ trunk/examples/NewAuthApp/root/admin/index.tt	2008-04-30 10:42:03 UTC (rev 7652)
@@ -0,0 +1,8 @@
+[% WRAPPER page.tt title = c.config.name  %]
+<h1> Hi [% c.user.id %], you're allowed to admin  </h1>
+
+There's not much else to see here, you can <a href='[% c.uri_for('/auth/logout')%]'>logout</a>.
+
+[% USE dumper; dumper.dump_html(c.user) %]
+
+[% END %]

Modified: trunk/examples/NewAuthApp/root/auth/login.tt
===================================================================
--- trunk/examples/NewAuthApp/root/auth/login.tt	2008-04-30 10:41:18 UTC (rev 7651)
+++ trunk/examples/NewAuthApp/root/auth/login.tt	2008-04-30 10:42:03 UTC (rev 7652)
@@ -1,6 +1,7 @@
 [% WRAPPER page.tt title = c.config.name  %]
 <h1> Please login</h1>
-[% IF c.stash.message != '' %] <h2> style='color:red'> [% c.stash.message %] </h2> [% END %]
+[% IF c.stash.message != '' %] <h2 style='color:red'> [% c.stash.message %] </h2> [% END %]
+<p>(hint user: bob, password: bob, for admin and user:bill, password: bill for ordinary user).</p>
 <form name="login" method='post' action='[% c.uri_for('/auth/login')  %]'>
 User: <input name='user' type='text' /><br />
 Password: <input name='password' type='password' /><br />

Added: trunk/examples/NewAuthApp/root/auth/unauth.tt
===================================================================
--- trunk/examples/NewAuthApp/root/auth/unauth.tt	                        (rev 0)
+++ trunk/examples/NewAuthApp/root/auth/unauth.tt	2008-04-30 10:42:03 UTC (rev 7652)
@@ -0,0 +1,4 @@
+[% WRAPPER page.tt title = c.config.name  %]
+<h1> [%c.user.id %]: You are not allowed to view this page.</h1>
+You can <a href="[% c.req.referrer  %]">go back</a> where you came from, or <a href="[% c.uri_for('/auth/logout') %]">logout</a> and try logging in again as a different user.  If you think this is an error, please contact <a href="mailto:[%c.config.admin %]">[% c.config.admin %]</a>
+[% END %]

Modified: trunk/examples/NewAuthApp/root/success.tt
===================================================================
--- trunk/examples/NewAuthApp/root/success.tt	2008-04-30 10:41:18 UTC (rev 7651)
+++ trunk/examples/NewAuthApp/root/success.tt	2008-04-30 10:42:03 UTC (rev 7652)
@@ -1,5 +1,7 @@
 [% WRAPPER page.tt title = c.config.name  %]
 <h1> Login successful</h1>
+<p>Hi [% c.user.id %], you can <a href='[% c.uri_for('/auth/logout')%]'>logout</a> now if you like, or try to visit <a href="[% c.uri_for('/admin') %]">this</a> page which is protected by user roles.</p>
+<hr />
 [% USE dumper; dumper.dump_html(c.user) %]
-You can <a href='[% c.uri_for('/auth/logout')%]'>logout</a> now if you like.
+
 [% END %]

Added: trunk/examples/NewAuthApp/t/controller_Admin.t
===================================================================
--- trunk/examples/NewAuthApp/t/controller_Admin.t	                        (rev 0)
+++ trunk/examples/NewAuthApp/t/controller_Admin.t	2008-04-30 10:42:03 UTC (rev 7652)
@@ -0,0 +1,10 @@
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+BEGIN { use_ok 'Catalyst::Test', 'NewAuthApp' }
+BEGIN { use_ok 'NewAuthApp::Controller::Admin' }
+
+ok( request('/admin')->is_success, 'Request should succeed' );
+
+




More information about the Catalyst-commits mailing list