1 package Catalyst::Plugin::Authentication::Store::DBIx::Class::User;
5 use base qw/Catalyst::Plugin::Authentication::User/;
6 use base qw/Class::Accessor::Fast/;
9 __PACKAGE__->mk_accessors(qw/config resultset _user _roles/);
13 my ( $class, $config, $c) = @_;
16 resultset => $c->model($config->{'user_class'}),
25 if (!exists($self->config->{'id_field'})) {
26 $self->config->{'id_field'} = 'id';
29 ## if we have lazyloading turned on - we should not query the DB unless something gets read.
30 ## that's the idea anyway - still have to work out how to manage that - so for now we always force
32 $self->config->{lazyload} = 0;
34 # if (!$self->config->{lazyload}) {
35 # return $self->load_user($authinfo, $c);
37 # ## what do we do with a lazyload?
38 # ## presumably this is coming out of session storage.
39 # ## use $authinfo to fill in the user in that case?
47 my ($self, $authinfo, $c) = @_;
49 my $dbix_class_config = 0;
51 if (exists($authinfo->{'dbix_class'})) {
52 $authinfo = $authinfo->{'dbix_class'};
53 $dbix_class_config = 1;
56 ## User can provide an arrayref containing the arguments to search on the user class.
57 ## or even provide a prepared resultset, allowing maximum flexibility for user retreival.
58 ## these options are only available when using the dbix_class authinfo hash.
59 if ($dbix_class_config && exists($authinfo->{'resultset'})) {
60 $self->_user($authinfo->{'resultset'}->first);
61 } elsif ($dbix_class_config && exists($authinfo->{'searchargs'})) {
62 $self->_user($self->resultset->search(@{$authinfo->{'searchargs'}})->first);
64 ## merge the ignore fields array into a hash - so we can do an easy check while building the query
65 my %ignorefields = map { $_ => 1} @{$self->config->{'ignore_fields_in_find'}};
68 # now we walk all the fields passed in, and build up a search hash.
69 foreach my $key (grep {!$ignorefields{$_}} keys %{$authinfo}) {
70 if ($self->resultset->result_source->has_column($key)) {
71 $searchargs->{$key} = $authinfo->{$key};
74 $self->_user($self->resultset->search($searchargs)->first);
77 if ($self->get_object) {
82 #$c->log->debug(dumper($self->{'user'}));
86 sub supported_features {
98 ## this used to load @wantedroles - but that doesn't seem to be used by the roles plugin, so I dropped it.
100 ## shortcut if we have already retrieved them
101 if (ref $self->_roles eq 'ARRAY') {
102 return(@{$self->_roles});
106 if (exists($self->config->{'role_column'})) {
107 @roles = split /[ ,\|]+/, $self->get($self->config->{'role_column'});
108 $self->_roles(\@roles);
109 } elsif (exists($self->config->{'role_relation'})) {
110 my $relation = $self->config->{'role_relation'};
111 if ($self->_user->$relation->result_source->has_column($self->config->{'role_field'})) {
112 @roles = map { $_->get_column($self->config->{'role_field'}) } $self->_user->$relation->search(undef, { columns => [ $self->config->{'role_field'}]})->all();
113 $self->_roles(\@roles);
115 Catalyst::Exception->throw("role table does not have a column called " . $self->config->{'role_field'});
118 Catalyst::Exception->throw("user->roles accessed, but no role configuration found");
121 return @{$self->_roles};
127 return $self->get($self->config->{'id_field'});
131 my ($self, $frozenuser, $c) = @_;
133 # this could be a lot better. But for now it just assumes $frozenuser is an id and uses find_user
134 # XXX: hits the database on every request? Not good...
135 return $self->load( { $self->config->{'id_field'} => $frozenuser }, $c);
139 my ($self, $field) = @_;
141 if ($self->_user->can($field)) {
142 return $self->_user->$field;
151 return $self->get_object;
162 (my $method) = (our $AUTOLOAD =~ /([^:]+)$/);
163 return if $method eq "DESTROY";
165 $self->_user->$method(@_);
173 Catalyst::Plugin::Authentication::Store::DBIx::Class::User - A class to ...
177 This documentation refers to version 0.01.
181 Internal - not used directly. use Catalyst::Plugin::Authentication::Store::DBIx::Class::User;
188 The Catalyst::Plugin::Authentication::Store::DBIx::Class::User class implements ...
190 =head1 SUBROUTINES / METHODS
192 =head2 new (constructor)
201 Insert description of constructor here...
203 =head2 load_user (method)
209 Insert description of method here...
211 =head2 supported_features (method)
216 Insert description of method here...
223 Insert description of subroutine here...
230 Insert description of subroutine here...
237 Insert description of method here...
244 Insert description of method here...
246 =head2 get_object (method)
251 Insert description of method here...
253 =head2 AUTOLOAD (method)
258 Insert description of method here...
262 Modules used, version dependencies, core yes/no
272 =head1 BUGS AND LIMITATIONS
274 None known currently, please email the author if you find any.
278 Jason Kuri (jk@domain.tld)
282 Copyright 2006 by Jason Kuri.
284 This software is free. It is licensed under the same terms as Perl itself.