From: Jay Kuri Date: Sun, 26 Oct 2008 23:27:59 +0000 (+0000) Subject: Adding SimpleDB Realm to make basic configuration of DBIx::Class / Password X-Git-Tag: v0.1100~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Authentication-Store-DBIx-Class.git;a=commitdiff_plain;h=f55cb81e9f47bf9f679d6b2c805d715159ee6abd Adding SimpleDB Realm to make basic configuration of DBIx::Class / Password based auth configs extraordinarily simple to use. Also changed user_class to user_model - per request from mst. apparantly class confuses people, a truth I should have realized based on personal experience --- diff --git a/Changes b/Changes index d1c4186..a55f1bb 100644 --- a/Changes +++ b/Changes @@ -1,11 +1,14 @@ Revision history for Catalyst-Plugin-Authentication-Store-DBIx-Class -x.xxx 2008-09-25 - Added missing dependency on Catalyst::Model::DBIC::Schema to Makefile.PL +0.108 2008-09-25 + Adding SimpleDB realm to simplify basic auth configuration + Changing user_class to user_model, per req. by mst to avoid confusing newbies. 0.107 2008-09-29 - - Fix the typo in exception during authenticate - - Doc fixes and clarifications + Fix the typo in exception during authenticate + Doc fixes and clarifications + Added missing dependency on Catalyst::Model::DBIC::Schema to Makefile.PL + 0.105 2008-03-19 Throw an exception if no fields are provided during authenticate diff --git a/Makefile.PL b/Makefile.PL index 55174b0..eaa87f2 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -31,7 +31,7 @@ all_from 'lib/Catalyst/Authentication/Store/DBIx/Class.pm'; perl_version '5.8.1'; requires ( 'Catalyst::Runtime' => 0, - 'Catalyst::Plugin::Authentication' => '0.10005', + 'Catalyst::Plugin::Authentication' => '0.10008', 'Catalyst::Model::DBIC::Schema' => 0, 'DBIx::Class' => 0, 'Catalyst::Model::DBIC::Schema' => '0.18', diff --git a/lib/Catalyst/Authentication/Store/DBIx/Class.pm b/lib/Catalyst/Authentication/Store/DBIx/Class.pm index 0dd6ed7..a74d4ff 100644 --- a/lib/Catalyst/Authentication/Store/DBIx/Class.pm +++ b/lib/Catalyst/Authentication/Store/DBIx/Class.pm @@ -4,7 +4,7 @@ use strict; use warnings; use base qw/Class::Accessor::Fast/; -our $VERSION= "0.107"; +our $VERSION= "0.108"; BEGIN { @@ -112,7 +112,7 @@ This documentation refers to version 0.107. }, store => { class => 'DBIx::Class', - user_class => 'MyApp::User', + user_model => 'MyApp::User', role_relation => 'roles', role_field => 'rolename', } @@ -146,9 +146,10 @@ access to authentication information stored in a database via DBIx::Class. =head1 CONFIGURATION The DBIx::Class authentication store is activated by setting the store -config's B element to DBIx::Class as shown above. See the -L documentation for more details on -configuring the store. +config's B element to DBIx::Class as shown above. See the +L documentation for more details on +configuring the store. You can also use +L for a simplified setup. The DBIx::Class storage module has several configuration options @@ -163,7 +164,7 @@ The DBIx::Class storage module has several configuration options }, store => { class => 'DBIx::Class', - user_class => 'MyApp::User', + user_model => 'MyApp::User', role_relation => 'roles', role_field => 'rolename', ignore_fields_in_find => [ 'remote_name' ], @@ -180,10 +181,12 @@ The DBIx::Class storage module has several configuration options Class is part of the core Catalyst::Plugin::Authentication module; it contains the class name of the store to be used. -=item user_class +=item user_model -Contains the class name (as passed to $c->model()) of the DBIx::Class schema -to use as the source for user information. This config item is B. +Contains the model name (as passed to $c->model()) of the DBIx::Class schema +to use as the source for user information. This config item is B. +(Note that this option used to be called user_class. user_class is still +functional, but should be used only for compatibility with previous configs.) =item role_column @@ -358,7 +361,7 @@ the user. An example will probably make more sense: The above would allow authentication based on any of the three items - username, email, or clientid - and would prefetch the data related to that user from the preferences table. The searchargs array is passed directly to the -search() method associated with the user_class. +search() method associated with the user_model. =item Resultset @@ -377,7 +380,7 @@ within your login action and use it for retrieving the user. A simple example: } Be aware that the resultset method will not verify that you are passing a -resultset that is attached to the same user_class as specified in the config. +resultset that is attached to the same user_model as specified in the config. NOTE: All of these methods of user retrieval, including the resultset method, consider the first row returned to be the matching user. In most cases there diff --git a/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm b/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm index caf64af..0e397b1 100644 --- a/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm +++ b/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm @@ -2,7 +2,6 @@ package Catalyst::Authentication::Store::DBIx::Class::User; use strict; use warnings; -use Data::Dumper; use base qw/Catalyst::Authentication::User/; use base qw/Class::Accessor::Fast/; @@ -13,15 +12,25 @@ BEGIN { sub new { my ( $class, $config, $c) = @_; + if (!defined($config->{'user_model'})) { + $config->{'user_model'} = $config->{'user_class'}; + } + my $self = { - resultset => $c->model($config->{'user_class'}), + resultset => $c->model($config->{'user_model'}), config => $config, _roles => undef, _user => undef }; bless $self, $class; + + + if (not $self->{'resultset'}) { + Catalyst::Exception->throw("\$c->model('${ \$self->config->{user_model} }') did not return a resultset. Did you set user_model correctly?"); + } + ## Note to self- add handling of multiple-column primary keys. if (!exists($self->config->{'id_field'})) { my @pks = $self->{'resultset'}->result_source->primary_columns; @@ -31,9 +40,7 @@ sub new { Catalyst::Exception->throw("user table does not contain a single primary key column - please specify 'id_field' in config!"); } } - if (not $self->{'resultset'}) { - Catalyst::Exception->throw("\$c->model('${ \$self->config->{user_class} }') did not return a resultset. Did you set user_class correctly?"); - } + if (!$self->{'resultset'}->result_source->has_column($self->config->{'id_field'})) { Catalyst::Exception->throw("id_field set to " . $self->config->{'id_field'} . " but user table has no column by that name!"); } @@ -86,7 +93,7 @@ sub load { if (keys %{$searchargs}) { $self->_user($self->resultset->search($searchargs)->first); } else { - Catalyst::Exception->throw("User retrieval failed: no columns from " . $self->config->{'user_class'} . " were provided"); + Catalyst::Exception->throw("User retrieval failed: no columns from " . $self->config->{'user_model'} . " were provided"); } } @@ -95,7 +102,6 @@ sub load { } else { return undef; } - #$c->log->debug(dumper($self->{'user'})); } diff --git a/t/02-pod-coverage.t b/t/02-pod-coverage.t index 703f91d..c450a0b 100644 --- a/t/02-pod-coverage.t +++ b/t/02-pod-coverage.t @@ -3,4 +3,4 @@ use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; -all_pod_coverage_ok(); +all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::CountParents' }); diff --git a/t/03-authtest.t b/t/03-authtest.t index 3929e6a..a9ddf6d 100644 --- a/t/03-authtest.t +++ b/t/03-authtest.t @@ -34,7 +34,7 @@ BEGIN { }, store => { 'class' => 'DBIx::Class', - 'user_class' => 'TestApp::User', + 'user_model' => 'TestApp::User', }, }, }, @@ -94,9 +94,9 @@ use Catalyst::Test 'TestApp'; } { - $ENV{TESTAPP_CONFIG}->{authentication}->{realms}->{users}->{store}->{user_class} = 'Nonexistent::Class'; + $ENV{TESTAPP_CONFIG}->{authentication}->{realms}->{users}->{store}->{user_model} = 'Nonexistent::Class'; my $res = request('http://localhost/user_login?username=joeuser&password=hackme'); - like( $res->content, qr/\$\Qc->model('Nonexistent::Class') did not return a resultset. Did you set user_class correctly?/, 'test for wrong user_class' ); + like( $res->content, qr/\$\Qc->model('Nonexistent::Class') did not return a resultset. Did you set user_model correctly?/, 'test for wrong user_class' ); } diff --git a/t/04-authsessions.t b/t/04-authsessions.t index 21a0766..e383a5d 100644 --- a/t/04-authsessions.t +++ b/t/04-authsessions.t @@ -48,7 +48,7 @@ BEGIN { }, store => { 'class' => 'DBIx::Class', - 'user_class' => 'TestApp::User', + 'user_model' => 'TestApp::User', 'use_userdata_from_session' => 0, }, }, diff --git a/t/05-auth-roles-relationship.t b/t/05-auth-roles-relationship.t index e534a92..6b7b674 100644 --- a/t/05-auth-roles-relationship.t +++ b/t/05-auth-roles-relationship.t @@ -39,7 +39,7 @@ BEGIN { }, store => { 'class' => 'DBIx::Class', - 'user_class' => 'TestApp::User', + 'user_model' => 'TestApp::User', 'role_relation' => 'roles', 'role_field' => 'role' }, diff --git a/t/06-auth-roles-column.t b/t/06-auth-roles-column.t index 9911cf2..b083984 100644 --- a/t/06-auth-roles-column.t +++ b/t/06-auth-roles-column.t @@ -39,7 +39,7 @@ BEGIN { }, store => { 'class' => 'DBIx::Class', - 'user_class' => 'TestApp::User', + 'user_model' => 'TestApp::User', 'role_column' => 'role_text' }, }, diff --git a/t/07-authsessions-cached.t b/t/07-authsessions-cached.t index b498926..701bcfb 100644 --- a/t/07-authsessions-cached.t +++ b/t/07-authsessions-cached.t @@ -48,7 +48,7 @@ BEGIN { }, store => { 'class' => 'DBIx::Class', - 'user_class' => 'TestApp::User', + 'user_model' => 'TestApp::User', 'use_userdata_from_session' => 1, }, },