use warnings;
use base qw/Class::Accessor::Fast/;
+our $VERSION= "0.02";
+
+BEGIN {
+ __PACKAGE__->mk_accessors(qw/config/);
+}
+
+
sub new {
my ( $class, $config, $app ) = @_;
- ## figure out if we are overriding the default store user class.
- my $storeuserclass = $config->{'store_user_class'} || "Catalyst::Plugin::Authentication::Store::DBIx::Class::User";
-
- ## fields can be specified to be ignored during user location. This allows
- ## authinfo to contain the user info required to find the user, as well as the password
- ## to try to match to, for example. It can be added to by setting ignore_fields in the
- ## authinfo hashref also.
- $config->{'ignore_fields_in_find'} ||= [ 'password' ];
- push @{$config->{'ignore_fields_in_find'}}, ('searchargs', 'ignore_fields');
-
+ ## figure out if we are overriding the default store user class
+ $config->{'store_user_class'} = (exists($config->{'store_user_class'})) ? $config->{'store_user_class'} :
+ "Catalyst::Plugin::Authentication::Store::DBIx::Class::User";
+
## make sure the store class is loaded.
- Catalyst::Utils::ensure_class_loaded( $storeuserclass );
+ Catalyst::Utils::ensure_class_loaded( $config->{'store_user_class'} );
- my $self = {};
- $self->{'config'} = $config;
- $self->{'store_user_class'} = $storeuserclass;
+ ## fields can be specified to be ignored during user location. This allows
+ ## the backend to ignore certain fields in the authinfo hash.
- #$self->{'role_relation'} ||= 'roles';
- #$self->{'role_field'} ||= 'role';
+ $config->{'ignore_fields_in_find'} ||= [ ];
+
+ my $self = {
+ config => $config
+ };
bless $self, $class;
+
}
## --jk note to self:
my ( $self, $c, $frozenuser ) = @_;
return $frozenuser if ref $frozenuser;
-
- # this could be a lot better. But for now it just assumes $frozenuser is an id and uses find_user
- # XXX: hits the database on every request? Not good...
- return $self->find_user( { id => $frozenuser }, $c);
+
+ my $user = $self->config->{'store_user_class'}->new($self->{'config'}, $c);
+
+ return $user->from_session($frozenuser, $c);
}
sub for_session {
sub find_user {
my ( $self, $authinfo, $c ) = @_;
- return $self->{'store_user_class'}->new($authinfo, $self->{config}, $c);
-}
+ my $user = $self->config->{'store_user_class'}->new($self->{'config'}, $c);
+ return $user->load($authinfo, $c);
+
+}
sub user_supports {
- # this can work as a class method
- shift->{'store_user_class'}->supports( @_ );
+ my $self = shift;
+ # this can work as a class method on the user class
+ $self->config->{'store_user_class'}->supports( @_ );
}
__PACKAGE__;
=head1 AUTHOR
-Jason Kuri (jk@domain.tld)
+Jason Kuri (jayk@cpan.org)
=head1 LICENCE