Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- === Changes
- ==================================================================
- --- Changes (revision 18123)
- +++ Changes (local)
- @@ -1,5 +1,7 @@
- Revision history for Perl extension Catalyst::Plugin::Authentication::Store::DBIC
- + - Made $c->user->id return the first field of user_field, rather than whatever was passed in.
- +
- 0.07 2006-06-30 01:08:47
- - make the User class stringify to the user id
- - documentation fixes
- === lib/Catalyst/Plugin/Authentication/Store/DBIC/Backend.pm
- ==================================================================
- --- lib/Catalyst/Plugin/Authentication/Store/DBIC/Backend.pm (revision 18123)
- +++ lib/Catalyst/Plugin/Authentication/Store/DBIC/Backend.pm (local)
- @@ -23,15 +23,16 @@
- my ( $self, $c, $id ) = @_;
- return $id if ref $id;
- +
- + return $self->{auth}{catalyst_user_class}->new( $id, { %{$self} } );
- - # XXX: hits the database on every request? Not good...
- - return $self->get_user( $id );
- }
- sub get_user {
- my ( $self, $id, @rest ) = @_;
- my $user = $self->{auth}{catalyst_user_class}->new( $id, { %{$self} } );
- + $user->id($user->canonical_id);
- if ( $user ) {
- $user->store( $self );
- @@ -49,6 +50,7 @@
- }
- 1;
- +
- __END__
- =pod
- === lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm
- ==================================================================
- --- lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm (revision 18123)
- +++ lib/Catalyst/Plugin/Authentication/Store/DBIC/User.pm (local)
- @@ -4,28 +4,42 @@
- use warnings;
- use base qw/Catalyst::Plugin::Authentication::User Class::Accessor::Fast/;
- use Set::Object ();
- +use Carp qw/confess/;
- +use Data::Dumper;
- use overload '""' => sub { shift->id }, 'bool' => sub { 1 }, fallback => 1;
- -__PACKAGE__->mk_accessors(qw/id config obj store/);
- +__PACKAGE__->mk_accessors(qw/id config store _obj/);
- +
- sub new {
- my ( $class, $id, $config ) = @_;
- -
- - my $query = @{$config->{auth}{user_field}} > 1
- - ? { -or => [ map { { $_ => $id } } @{$config->{auth}{user_field}} ] }
- - : { $config->{auth}{user_field}[0] => $id };
- -
- - my $user_obj = $config->{auth}{user_class}->search($query)->first;
- - return unless $user_obj;
- -
- bless {
- id => $id,
- - config => $config,
- - obj => $user_obj,
- + config => $config
- }, $class;
- }
- +sub obj {
- + my $self=shift;
- + my $config=$self->config;
- + my $id=$self->id;
- + unless (ref $self->_obj) {
- + my $query = @{$config->{auth}{user_field}} > 1
- + ? { -or => [ map { { $_ => $id } } @{$config->{auth}{user_field}} ] }
- + : { $config->{auth}{user_field}[0] => $id };
- + $self->_obj($config->{auth}{user_class}->search($query)->first);
- + }
- + return $self->_obj;
- +}
- +
- +sub canonical_id {
- + my $self=shift;
- + return undef unless $self->obj();
- + return $self->obj->get_column($self->config->{auth}{user_field}[0]),
- +}
- +
- +
- *user = \&obj;
- *crypted_password = \&password;
- *hashed_password = \&password;
Add Comment
Please, Sign In to add comment