1 package Catalyst::Plugin::Authentication::Store::DBIx::Class::User;
5 use base qw/Catalyst::Plugin::Authentication::User/;
8 my ( $class, $authinfo, $config, $c, $lazyload) = @_;
11 $self->{'resultset'} = $c->model($config->{'user_class'});
12 $self->{'config'} = $config;
13 $self->{'authinfo'} = {%{$authinfo}};
17 ## if we have lazyloading turned on - we should not query the DB unless something gets read.
18 ## that's the idea anyway - still have to work out how to manage that - so for now we always force
23 $self->load_user($authinfo, $c);
24 if (!$self->{'user'}) {
28 ## what do we do with a lazyload?
29 ## presumably this is coming out of session storage.
30 ## use $authinfo to fill in the user in that case?
38 my ($self, $authinfo, $c) = @_;
40 ## User can provide an arrayref containing the arguments to search on the user class.
41 ## allowing maximum flexibility for authentication.
42 if ($authinfo->{'searchargs'}) {
43 $self->{user} = $self->{'resultset'}->search(@{$authinfo->{'searchargs'}})->first;
45 ## merge the ignore fields array into a hash - so we can do an easy check while building the query
46 my %ignorefields = map { $_ => 1} @{$self->{'config'}{'ignore_fields_in_find'}},
47 ( ref $authinfo->{'ignore_fields'} eq 'ARRAY' ? @{$authinfo->{'ignore_fields'}} : () );
51 # now we walk all the fields passed in, and build up a search hash.
52 foreach my $key (grep {!$ignorefields{$_}} keys %{$authinfo}) {
54 if ($self->{'resultset'}->result_source->has_column($key)) {
55 $searchargs->{$key} = $authinfo->{$key};
58 $self->{user} = $self->{'resultset'}->search($searchargs)->first;
60 #$c->log->debug(dumper($self->{'user'}));
64 sub supported_features {
66 $self->{'config'}{'password_type'} = 'clear';
70 $self->{'config'}{'password_type'} => 1,
79 my ( $self, @wanted_roles ) = @_;
81 ## shortcut if we have already retrieved them
82 if (ref $self->{'roles'} eq 'ARRAY') {
83 return(@{$self->{'roles'}});
87 if (exists($self->{'config'}{'role_column'})) {
88 @roles = split /[ ,\|]/, $self->get($self->{'config'}{'role_column'});
89 $self->{'roles'} = \@roles;
90 } elsif (exists($self->{'config'}{'role_relation'})) {
91 my $relation = $self->{'config'}{'role_relation'};
92 if ($self->{'user'}->$relation->result_source->has_column($self->{'config'}{'role_field'})) {
93 @roles = $self->{'user'}->$relation->search(undef, { columns => [ $self->{'config'}{'role_field'}]})->all();
95 Catalyst::Exception->throw("role table does not have a column called " . $self->{'config'}{'role_field'});
97 my $rolefield = $self->{'config'}{'role_field'};
98 @{$self->{'roles'}} = map { $_->get_column($self->{'config'}{'role_field'}) } @roles;
100 Catalyst::Exception->throw("user->roles accessed, but no role configuration found");
103 return @{$self->{'roles'}};
111 my ($self, $field) = @_;
113 if ($self->{'user'}->can($field)) {
114 return $self->{'user'}->$field;
122 return $self->get_object;
128 return $self->{'user'};
133 (my $method) = (our $AUTOLOAD =~ /([^:]+)$/);
134 return if $method eq "DESTROY";
136 $self->{'user'}->$method(@_);
144 Catalyst::Plugin::Authentication::Store::DBIx::Class::User - A class to ...
148 This documentation refers to version 0.01.
152 use Catalyst::Plugin::Authentication::Store::DBIx::Class::User;
156 The Catalyst::Plugin::Authentication::Store::DBIx::Class::User class implements ...
158 =head1 SUBROUTINES / METHODS
160 =head2 new (constructor)
169 Insert description of constructor here...
171 =head2 load_user (method)
177 Insert description of method here...
179 =head2 supported_features (method)
184 Insert description of method here...
191 Insert description of subroutine here...
198 Insert description of subroutine here...
205 Insert description of method here...
212 Insert description of method here...
214 =head2 get_object (method)
219 Insert description of method here...
221 =head2 AUTOLOAD (method)
226 Insert description of method here...
230 Modules used, version dependencies, core yes/no
240 =head1 BUGS AND LIMITATIONS
242 None known currently, please email the author if you find any.
246 Jason Kuri (jk@domain.tld)
250 Copyright 2006 by Jason Kuri.
252 This software is free. It is licensed under the same terms as Perl itself.