Initial import of new DBIx::Class store. Not compatible with old-school
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / lib / Catalyst / Plugin / Authentication / Store / DBIx / Class / Backend.pm
CommitLineData
5000f545 1package Catalyst::Plugin::Authentication::Store::DBIx::Class::Backend;
2
3use strict;
4use warnings;
5use base qw/Class::Accessor::Fast/;
6
7sub new {
8 my ( $class, $config, $app ) = @_;
9
10 ## figure out if we are overriding the default store user class.
11 my $storeclass = $config->{'store_user_class'} || "Catalyst::Plugin::Authentication::Store::DBIx::Class::User";
12
13 ## fields can be specified to be ignored during user location. This allows
14 ## authinfo to contain the user info required to find the user, as well as the password
15 ## to try to match to, for example. It can be added to by setting ignore_fields in the
16 ## authinfo hashref also.
17 $config->{'ignore_fields_in_find'} ||= [ 'password' ];
18 push @{$config->{'ignore_fields_in_find'}}, ('searchargs', 'ignore_fields');
19
20 ## make sure the store class is loaded.
21 Catalyst::Utils::ensure_class_loaded( $storeclass );
22
23 my $self = {};
24 $self->{config} = $config;
25 $self->{store_user_class} = $storeclass;
26
27 #$self->{role_relation} ||= 'roles';
28 #$self->{role_field} ||= 'role';
29
30 bless $self, $class;
31}
32
33sub from_session {
34 my ( $self, $c, $frozenuser ) = @_;
35
36 return $frozenuser if ref $frozenuser;
37
38 # this could be a lot better. But for now it just assumes $frozenuser is an id and uses find_user
39 # XXX: hits the database on every request? Not good...
40 return $self->find_user( { id => $frozenuser }, $c);
41}
42
43sub for_session {
44 my ($self, $c, $user) = @_;
45
46 return $user->for_session($c);
47}
48
49sub find_user {
50 my ( $self, $authinfo, $c ) = @_;
51
52 return $self->{'store_user_class'}->new($authinfo, $self->{config}, $c);
53}
54
55
56sub user_supports {
57 # this can work as a class method
58 shift->{'store_user_class'}->supports( @_ );
59}
60
61__PACKAGE__;
62
63__END__
64
65=head1 NAME
66
67Catalyst::Plugin::Authentication::Store::DBIx::Class::Backend - A class to ...
68
69=head1 VERSION
70
71This documentation refers to version 0.01.
72
73=head1 SYNOPSIS
74
75use Catalyst::Plugin::Authentication::Store::DBIx::Class::Backend;
76
77=head1 DESCRIPTION
78
79The Catalyst::Plugin::Authentication::Store::DBIx::Class::Backend class implements ...
80
81=head1 SUBROUTINES / METHODS
82
83=head2 new (constructor)
84
85Parameters:
86 class
87 config
88 app
89
90Insert description of constructor here...
91
92=head2 from_session (method)
93
94Parameters:
95 c
96 frozenuser
97
98Insert description of method here...
99
100=head2 for_session (method)
101
102Parameters:
103 c
104 user
105
106Insert description of method here...
107
108=head2 find_user (method)
109
110Parameters:
111 authinfo
112 c
113
114Insert description of method here...
115
116=head2 user_supports
117
118Parameters:
119 none
120
121Insert description of subroutine here...
122
123=head1 DEPENDENCIES
124
125Modules used, version dependencies, core yes/no
126
127strict
128
129warnings
130
131=head1 NOTES
132
133...
134
135=head1 BUGS AND LIMITATIONS
136
137None known currently, please email the author if you find any.
138
139=head1 SEE ALSO
140
141L<Catalyst::Plugin::Authentication::Store::DBIC>, L<Catalyst::Plugin::Authentication>,
142L<Catalyst::Plugin::Authorization::Roles>
143
144=head1 AUTHOR
145
146Jason Kuri (jk@domain.tld)
147
148=head1 LICENCE
149
150Copyright 2006 by Jason Kuri.
151
152This software is free. It is licensed under the same terms as Perl itself.
153
154=cut