X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FAuthentication%2FStore%2FHtpasswd%2FUser.pm;h=438f31ae25eb273d63d486e66a0417d15be754a1;hb=8fade176102cab08f9ad5bd34bf435b246acb89c;hp=7c7600f5de819db6202a580e710bb33a2f1993e7;hpb=47fb088eac2f983f623062ce393a6840b4ac621e;p=catagits%2FCatalyst-Authentication-Store-Htpasswd.git diff --git a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm index 7c7600f..438f31a 100644 --- a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm +++ b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm @@ -6,14 +6,21 @@ use base qw/Catalyst::Plugin::Authentication::User Class::Accessor::Fast/; use strict; use warnings; -BEGIN { __PACKAGE__->mk_accessors(qw/user/) } +BEGIN { __PACKAGE__->mk_accessors(qw/user store/) } -use overload '""' => sub { shift->user->username }; +use overload '""' => sub { shift->id }, fallback => 1; sub new { - my ( $class, $user ) = @_; + my ( $class, $store, $user ) = @_; - bless { user => $user }, $class; + return unless $user; + + bless { store => $store, user => $user }, $class; +} + +sub id { + my $self = shift; + return $self->user->username; } sub supported_features { @@ -22,28 +29,34 @@ sub supported_features { self_check => 1, }, session => 1 + roles => 1, }; } sub check_password { my ( $self, $password ) = @_; - return $self->user->check_password( $password ); } sub roles { my $self = shift; - split( ",", $self->user->extra_info ); + my $field = $self->user->extra_info->[0]; + return defined $field ? split /,/, $field : (); } sub for_session { my $self = shift; - return $self; + return $self->id; } -sub from_session { - my ($class,$c,$user) = @_; - return $user; +sub AUTOLOAD { + my $self = shift; + + ( my $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ ); + + return if $method eq "DESTROY"; + + $self->user->$method; } __PACKAGE__; @@ -57,11 +70,39 @@ __END__ Catalyst::Plugin::Authentication::Store::Htpasswd::User - A user object representing an entry in an htpasswd file. -=head1 SYNOPSIS +=head1 DESCRIPTION - use Catalyst::Plugin::Authentication::Store::Htpasswd::User; +This object wraps an L object. An instance of it will be returned +by C<< $c->user >> when using L. Methods +not defined in this module are passed through to the L object. The +object stringifies to the username. -=head1 DESCRIPTION +=head1 METHODS + +=head2 new($store,$user) + +Creates a new object from a store object, normally an instance of +L, and a user object, +normally an instance of L. + +=head2 id + +Returns the username. + +=head2 check_password($password) + +Returns whether the password is valid. + +=head2 roles + +Returns an array of roles, which is extracted from a comma-separated list in the +third field of the htpasswd file. + +=head1 COPYRIGHT & LICENSE + + Copyright (c) 2005 the aforementioned authors. All rights + reserved. This program is free software; you can redistribute + it and/or modify it under the same terms as Perl itself. =cut