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'}),
26 ## if we have lazyloading turned on - we should not query the DB unless something gets read.
27 ## that's the idea anyway - still have to work out how to manage that - so for now we always force
29 $self->config->{lazyload} = 0;
31 # if (!$self->config->{lazyload}) {
32 # return $self->load_user($authinfo, $c);
34 # ## what do we do with a lazyload?
35 # ## presumably this is coming out of session storage.
36 # ## use $authinfo to fill in the user in that case?
44 my ($self, $authinfo, $c) = @_;
46 my $dbix_class_config = 0;
48 if (exists($authinfo->{'dbix_class'})) {
49 $authinfo = $authinfo->{'dbix_class'};
50 $dbix_class_config = 1;
53 ## User can provide an arrayref containing the arguments to search on the user class.
54 ## or even provide a prepared resultset, allowing maximum flexibility for user retreival.
55 ## these options are only available when using the dbix_class authinfo hash.
56 if ($dbix_class_config && exists($authinfo->{'resultset'})) {
57 $self->_user($authinfo->{'resultset'}->first);
58 } elsif ($dbix_class_config && exists($authinfo->{'searchargs'})) {
59 $self->_user($self->resultset->search(@{$authinfo->{'searchargs'}})->first);
61 ## merge the ignore fields array into a hash - so we can do an easy check while building the query
62 my %ignorefields = map { $_ => 1} @{$self->config->{'ignore_fields_in_find'}};
65 # now we walk all the fields passed in, and build up a search hash.
66 foreach my $key (grep {!$ignorefields{$_}} keys %{$authinfo}) {
67 if ($self->resultset->result_source->has_column($key)) {
68 $searchargs->{$key} = $authinfo->{$key};
71 $self->_user($self->resultset->search($searchargs)->first);
74 if ($self->get_object) {
79 #$c->log->debug(dumper($self->{'user'}));
83 sub supported_features {
95 ## this used to load @wantedroles - but that doesn't seem to be used by the roles plugin, so I dropped it.
97 ## shortcut if we have already retrieved them
98 if (ref $self->_roles eq 'ARRAY') {
99 return(@{$self->_roles});
103 if (exists($self->config->{'role_column'})) {
104 @roles = split /[ ,\|]/, $self->get($self->config->{'role_column'});
105 $self->_roles(\@roles);
106 } elsif (exists($self->config->{'role_relation'})) {
107 my $relation = $self->config->{'role_relation'};
108 if ($self->_user->$relation->result_source->has_column($self->config->{'role_field'})) {
109 @roles = map { $_->get_column($self->config->{'role_field'}) } $self->_user->$relation->search(undef, { columns => [ $self->config->{'role_field'}]})->all();
110 $self->_roles(\@roles);
112 Catalyst::Exception->throw("role table does not have a column called " . $self->config->{'role_field'});
115 Catalyst::Exception->throw("user->roles accessed, but no role configuration found");
118 return @{$self->_roles};
124 return $self->get('id');
128 my ($self, $frozenuser, $c) = @_;
130 # this could be a lot better. But for now it just assumes $frozenuser is an id and uses find_user
131 # XXX: hits the database on every request? Not good...
132 return $self->load( { id => $frozenuser }, $c);
136 my ($self, $field) = @_;
138 if ($self->_user->can($field)) {
139 return $self->_user->$field;
148 return $self->get_object;
159 (my $method) = (our $AUTOLOAD =~ /([^:]+)$/);
160 return if $method eq "DESTROY";
162 $self->_user->$method(@_);
170 Catalyst::Plugin::Authentication::Store::DBIx::Class::User - A class to ...
174 This documentation refers to version 0.01.
178 use Catalyst::Plugin::Authentication::Store::DBIx::Class::User;
182 The Catalyst::Plugin::Authentication::Store::DBIx::Class::User class implements ...
184 =head1 SUBROUTINES / METHODS
186 =head2 new (constructor)
195 Insert description of constructor here...
197 =head2 load_user (method)
203 Insert description of method here...
205 =head2 supported_features (method)
210 Insert description of method here...
217 Insert description of subroutine here...
224 Insert description of subroutine here...
231 Insert description of method here...
238 Insert description of method here...
240 =head2 get_object (method)
245 Insert description of method here...
247 =head2 AUTOLOAD (method)
252 Insert description of method here...
256 Modules used, version dependencies, core yes/no
266 =head1 BUGS AND LIMITATIONS
268 None known currently, please email the author if you find any.
272 Jason Kuri (jk@domain.tld)
276 Copyright 2006 by Jason Kuri.
278 This software is free. It is licensed under the same terms as Perl itself.