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
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
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',
use warnings;
use base qw/Class::Accessor::Fast/;
-our $VERSION= "0.107";
+our $VERSION= "0.108";
BEGIN {
},
store => {
class => 'DBIx::Class',
- user_class => 'MyApp::User',
+ user_model => 'MyApp::User',
role_relation => 'roles',
role_field => 'rolename',
}
=head1 CONFIGURATION
The DBIx::Class authentication store is activated by setting the store
-config's B<class> element to DBIx::Class as shown above. See the
-L<Catalyst::Plugin::Authentication> documentation for more details on
-configuring the store.
+config's B<class> element to DBIx::Class as shown above. See the
+L<Catalyst::Plugin::Authentication> documentation for more details on
+configuring the store. You can also use
+L<Catalyst::Authentication::Realm::SimpleDB> for a simplified setup.
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' ],
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<REQUIRED>.
+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<REQUIRED>.
+(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
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
}
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
use strict;
use warnings;
-use Data::Dumper;
use base qw/Catalyst::Authentication::User/;
use base qw/Class::Accessor::Fast/;
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;
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!");
}
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");
}
}
} else {
return undef;
}
- #$c->log->debug(dumper($self->{'user'}));
}
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' });
},
store => {
'class' => 'DBIx::Class',
- 'user_class' => 'TestApp::User',
+ 'user_model' => 'TestApp::User',
},
},
},
}
{
- $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' );
}
},
store => {
'class' => 'DBIx::Class',
- 'user_class' => 'TestApp::User',
+ 'user_model' => 'TestApp::User',
'use_userdata_from_session' => 0,
},
},
},
store => {
'class' => 'DBIx::Class',
- 'user_class' => 'TestApp::User',
+ 'user_model' => 'TestApp::User',
'role_relation' => 'roles',
'role_field' => 'role'
},
},
store => {
'class' => 'DBIx::Class',
- 'user_class' => 'TestApp::User',
+ 'user_model' => 'TestApp::User',
'role_column' => 'role_text'
},
},
},
store => {
'class' => 'DBIx::Class',
- 'user_class' => 'TestApp::User',
+ 'user_model' => 'TestApp::User',
'use_userdata_from_session' => 1,
},
},