[Catalyst-commits] r8479 - in Catalyst-Authentication-Store-Htpasswd/1.000/trunk: . lib/Catalyst/Authentication/Store

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Tue Sep 30 09:05:47 BST 2008


Author: t0m
Date: 2008-09-30 09:05:47 +0100 (Tue, 30 Sep 2008)
New Revision: 8479

Modified:
   Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Changes
   Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Makefile.PL
   Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Todo
   Catalyst-Authentication-Store-Htpasswd/1.000/trunk/lib/Catalyst/Authentication/Store/Htpasswd.pm
Log:
Another test suite fix (t0m == FAIL), and a couple of the little features on the Todo list, written but not in the test suite yet..

Modified: Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Changes
===================================================================
--- Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Changes	2008-09-29 23:21:20 UTC (rev 8478)
+++ Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Changes	2008-09-30 08:05:47 UTC (rev 8479)
@@ -1,3 +1,9 @@
+1.002  ??? Oct   ?? ??:??:?? GMT 2008
+    - Add Test::WWW::Mechanize::Catalyst to build_requires.
+      CPANTs will keep hitting me until I get it right :(
+    - Add code and docs for user_field configuration option
+    - Add code and docs for user_class configuration option
+
 1.001  Mon Sept  29 18:56:30 GMT 2008
     - Remove Tangram from test application models so that tests
       pass for other people. FAIL.

Modified: Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Makefile.PL
===================================================================
--- Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Makefile.PL	2008-09-29 23:21:20 UTC (rev 8478)
+++ Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Makefile.PL	2008-09-30 08:05:47 UTC (rev 8479)
@@ -8,5 +8,6 @@
 requires 'Authen::Htpasswd' => '0.13';
 requires 'Class::Accessor::Fast';
 requires 'Crypt::PasswdMD5';
+build_requires 'Test::WWW::Mechanize::Catalyst';
 
 WriteAll;  

Modified: Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Todo
===================================================================
--- Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Todo	2008-09-29 23:21:20 UTC (rev 8478)
+++ Catalyst-Authentication-Store-Htpasswd/1.000/trunk/Todo	2008-09-30 08:05:47 UTC (rev 8479)
@@ -1,4 +1,5 @@
-. Paths to htpasswd which start with / should be taken from root, not the app root
+. Test Paths to htpasswd which start with / should be taken from root, not the app root.
 . Better docs
-. Configurable user class
-. Configurable username/password fields.
\ No newline at end of file
+. Test configurable user class
+. Test configurable username field.
+. Configurable password field.
\ No newline at end of file

Modified: Catalyst-Authentication-Store-Htpasswd/1.000/trunk/lib/Catalyst/Authentication/Store/Htpasswd.pm
===================================================================
--- Catalyst-Authentication-Store-Htpasswd/1.000/trunk/lib/Catalyst/Authentication/Store/Htpasswd.pm	2008-09-29 23:21:20 UTC (rev 8478)
+++ Catalyst-Authentication-Store-Htpasswd/1.000/trunk/lib/Catalyst/Authentication/Store/Htpasswd.pm	2008-09-30 08:05:47 UTC (rev 8479)
@@ -11,34 +11,37 @@
 
 our $VERSION = '1.001';
 
-BEGIN { __PACKAGE__->mk_accessors(qw/file/) }
+BEGIN { __PACKAGE__->mk_accessors(qw/file user_field user_class/) }
 
 sub new {
     my ($class, $config, $app, $realm) = @_;
     
     my $file = delete $config->{file};
-    unless (ref $file) { # FIXME - file not in app..
-        my $filename = $app->path_to($file)->stringify;
+    unless (ref $file) {
+        my $filename = ($file =~ m|^/|) ? $file : $app->path_to($file)->stringify;
         die("Cannot find htpasswd file: $filename\n") unless (-r $filename);
         $file = Authen::Htpasswd->new($filename);
     }
     $config->{file} = $file;
+    $config->{user_class} ||= __PACKAGE__ . '::User';
+    $config->{user_field} ||= 'username';
     
     bless { %$config }, $class;
 }
 
 sub find_user {
     my ($self, $authinfo, $c) = @_;
-    # FIXME - change username
-    my $htpasswd_user = $self->file->lookup_user($authinfo->{username});
-    Catalyst::Authentication::Store::Htpasswd::User->new( $self, $htpasswd_user );
+    my $htpasswd_user = $self->file->lookup_user($authinfo->{$self->user_field});
+    $self->user_class->new( $self, $htpasswd_user );
 }
 
 sub user_supports {
     my $self = shift;
 
-    # this can work as a class method
-    Catalyst::Authentication::Store::Htpasswd::User->supports(@_);
+    # this can work as a class method, but in that case you can't have 
+    # a custom user class
+    ref($self) ? $self->user_class->supports(@_)
+        : Catalyst::Authentication::Store::Htpasswd::User->supports(@_);
 }
 
 sub from_session {
@@ -54,7 +57,7 @@
 
 =head1 NAME
 
-Catalyst::Authentication::Store::Htpasswd - L<Authen::Htpasswd> based
+Catalyst::Authentication::Store::Htpasswd - Authen::Htpasswd based
 user storage/authentication.
 
 =head1 SYNOPSIS
@@ -115,8 +118,37 @@
 
 =head2 file
 
-The path to the htpasswd file, this is taken from the application root.
+The path to the htpasswd file. If the path starts with a slash, then it is assumed to be a fully
+qualified path, otherwise the path is fed through C< $c->path_to > and so normalised to the 
+application root.
 
+Alternatively, it is possible to pass in an L< Authen::Htpasswd > object here, and this will be
+used as the htpasswd file.
+
+=head2 user_class
+
+Change the user class which this store returns. Defaults to L< Catalyst::Authentication::Store::Htpasswd::User >.
+This can be used to add additional functionality to the user class by sub-classing it, but will not normally be
+needed.
+
+=head2 user_field
+
+Change the field that the username is found in in the information passed into the call to C< $c->authenticate() >.
+
+This defaults to I< username >, and generally you should be able to use the module as shown in the synopsis, however
+if you need a different field name then this setting can change the default.
+
+Example:
+
+    __PACKAGE__->config( authentication => { realms => { test => {
+                    store => {
+                        class => 'Htpasswd',
+                        user_field => 'email_address',
+                    },
+    }}});
+    # Later in your code
+    $c->authenticate({ email_address => $c->req->param("email"), password => $c->req->param("password") });
+
 =head1 AUTHORS
 
 Yuval Kogman C<nothingmuch at woobling.org>




More information about the Catalyst-commits mailing list