| 1 | package Catalyst::Authentication::Store::Fey::ORM; | ||
| 2 | BEGIN { | ||
| 3 | $Catalyst::Authentication::Store::Fey::ORM::VERSION = '0.001'; | ||
| 4 | } | ||
| 5 | # ABSTRACT: A storage class for Catalyst Authentication using L<Fey::ORM> | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | use warnings; | ||
| 9 | use Catalyst::Authentication::Store::Fey::ORM::User; | ||
| 10 | |||
| 11 | use base qw/Class::Accessor::Fast/; | ||
| 12 | |||
| 13 | BEGIN { | ||
| 14 | __PACKAGE__->mk_accessors(qw/config/); | ||
| 15 | } | ||
| 16 | |||
| 17 | sub new { | ||
| 18 | my ( $class, $config, $app ) = @_; | ||
| 19 | |||
| 20 | my $self = { | ||
| 21 | config => $config, | ||
| 22 | }; | ||
| 23 | |||
| 24 | return bless $self, $class; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub from_session { | ||
| 28 | my ( $self, $c, $frozenuser ) = @_; | ||
| 29 | |||
| 30 | my $user = Catalyst::Authentication::Store::Fey::ORM::User->new( | ||
| 31 | $self->config, | ||
| 32 | $c, | ||
| 33 | ); | ||
| 34 | |||
| 35 | return $user->from_session($frozenuser, $c); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub for_session { | ||
| 39 | my ( $self, $c, $user ) = @_; | ||
| 40 | |||
| 41 | return $user->for_session($c); | ||
| 42 | } | ||
| 43 | |||
| 44 | sub find_user { | ||
| 45 | my ( $self, $authinfo, $c ) = @_; | ||
| 46 | |||
| 47 | my $user = Catalyst::Authentication::Store::Fey::ORM::User->new( | ||
| 48 | $self->config, | ||
| 49 | $c, | ||
| 50 | ); | ||
| 51 | |||
| 52 | return $user->load($authinfo, $c); | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; | ||
| 56 | |||
| 57 | |||
| 58 | =pod | ||
| 59 | |||
| 60 | =encoding utf-8 | ||
| 61 | |||
| 62 | =head1 NAME | ||
| 63 | |||
| 64 | Catalyst::Authentication::Store::Fey::ORM - A storage class for Catalyst Authentication using L<Fey::ORM> | ||
| 65 | |||
| 66 | =head1 VERSION | ||
| 67 | |||
| 68 | version 0.001 | ||
| 69 | |||
| 70 | =head1 SYNOPSIS | ||
| 71 | |||
| 72 | use Catalyst qw( | ||
| 73 | Authentication | ||
| 74 | Authorization::Roles | ||
| 75 | ); | ||
| 76 | |||
| 77 | __PACKAGE__->config->{authentication} = { | ||
| 78 | default_realm => 'members', | ||
| 79 | realms => { | ||
| 80 | members => { | ||
| 81 | credential => { | ||
| 82 | class => 'Password', | ||
| 83 | password_field => 'password', | ||
| 84 | password_type => 'clear' | ||
| 85 | }, | ||
| 86 | store => { | ||
| 87 | class => 'Fey::ORM', | ||
| 88 | user_model => 'MyApp::User', | ||
| 89 | role_relation => 'roles', | ||
| 90 | role_field => 'rolename', | ||
| 91 | } | ||
| 92 | } | ||
| 93 | } | ||
| 94 | }; | ||
| 95 | |||
| 96 | # Log a user in: | ||
| 97 | |||
| 98 | sub login : Global { | ||
| 99 | my ( $self, $c ) = @_; | ||
| 100 | |||
| 101 | $c->authenticate( | ||
| 102 | { | ||
| 103 | user_name => $c->req->params->{username}, | ||
| 104 | password => $c->req->params->{password}, | ||
| 105 | } | ||
| 106 | ); | ||
| 107 | } | ||
| 108 | |||
| 109 | # verify a role | ||
| 110 | |||
| 111 | if ( $c->check_user_roles( 'editor' ) ) { | ||
| 112 | # do editor stuff | ||
| 113 | } | ||
| 114 | |||
| 115 | =head1 DESCRIPTION | ||
| 116 | |||
| 117 | The L<Catalyst::Authentication::Store::Fey::ORM> class provides access to | ||
| 118 | authentication information stored in a database via L<Fey::ORM>. | ||
| 119 | |||
| 120 | =head1 METHODS | ||
| 121 | |||
| 122 | =head2 new ( $config, $app ) | ||
| 123 | |||
| 124 | Constructs a new store object. | ||
| 125 | |||
| 126 | =head2 from_session ( $c, $frozenuser ) | ||
| 127 | |||
| 128 | Revives a user from the session based on the info provided in C<$frozenuser>. | ||
| 129 | Currently treats $frozenuser as an id and retrieves a user | ||
| 130 | with a matching id. | ||
| 131 | |||
| 132 | =head2 for_session ( $c, $user ) | ||
| 133 | |||
| 134 | Prepares a user to be stored in the session. | ||
| 135 | Currently returns the value of the user's id field | ||
| 136 | (as indicated by the 'id_field' config element). | ||
| 137 | |||
| 138 | =head2 find_user ( $authinfo, $c ) | ||
| 139 | |||
| 140 | Finds a user using the information provided in the C<$authinfo> hashref | ||
| 141 | and returns the user, or undef on failure. | ||
| 142 | This is usually called from the Credential. | ||
| 143 | This translates directly to a call to | ||
| 144 | L<Catalyst::Authentication::Store::Fey::ORM::User>'s load() method. | ||
| 145 | |||
| 146 | =head1 CONFIGURATION | ||
| 147 | |||
| 148 | The L<Fey::ORM> storage module has several configuration options. | ||
| 149 | |||
| 150 | =over | ||
| 151 | |||
| 152 | =item class | ||
| 153 | |||
| 154 | =item user_model | ||
| 155 | |||
| 156 | =item id_field | ||
| 157 | |||
| 158 | =item role_column | ||
| 159 | |||
| 160 | =item role_field | ||
| 161 | |||
| 162 | =item role_relation | ||
| 163 | |||
| 164 | =item use_userdata_from_session | ||
| 165 | |||
| 166 | =back | ||
| 167 | |||
| 168 | =head1 AUTHOR | ||
| 169 | |||
| 170 | Keedi Kim - κΉλν <keedi@cpan.org> | ||
| 171 | |||
| 172 | =head1 COPYRIGHT AND LICENSE | ||
| 173 | |||
| 174 | This software is copyright (c) 2011 by Keedi Kim. | ||
| 175 | |||
| 176 | This is free software; you can redistribute it and/or modify it under | ||
| 177 | the same terms as the Perl 5 programming language system itself. | ||
| 178 | |||
| 179 | =cut | ||
| 180 | |||
| 181 | |||
| 182 | __END__ |