From: Yuval Kogman Date: Mon, 21 Nov 2005 13:37:26 +0000 (+0000) Subject: Update htpasswd store for registered stores X-Git-Tag: v0.02~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=039544ff7e03ea53d05dab5e7dcf6cdb3122f886;hp=ec31fe73dbbe0ab07357ea5959f29aed83d03c81;p=catagits%2FCatalyst-Authentication-Store-Htpasswd.git Update htpasswd store for registered stores --- diff --git a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm index c048347..c5213b0 100644 --- a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm +++ b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm @@ -19,7 +19,7 @@ sub new { sub get_user { my ( $self, $id ) = @_; - Catalyst::Plugin::Authentication::Store::Htpasswd::User->new( $self->file->lookup_user($id) ); + Catalyst::Plugin::Authentication::Store::Htpasswd::User->new( $self, $self->file->lookup_user($id) ); } sub user_supports { @@ -29,6 +29,11 @@ sub user_supports { Catalyst::Plugin::Authentication::Store::Htpasswd::User->supports(@_); } +sub from_session { + my ( $self, $c, $id ) = @_; + $self->get_user( $id ); +} + __PACKAGE__; __END__ diff --git a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm index a242ba5..ce4388a 100644 --- a/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm +++ b/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm @@ -6,14 +6,14 @@ 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 }; sub new { - my ( $class, $user ) = @_; + my ( $class, $store, $user ) = @_; - bless { user => $user }, $class; + bless { store => $store, user => $user }, $class; } sub supported_features { @@ -41,9 +41,14 @@ sub for_session { return $self->user->username; } -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__; diff --git a/t/backend.t b/t/backend.t index 6834718..2eb77ca 100644 --- a/t/backend.t +++ b/t/backend.t @@ -38,3 +38,13 @@ can_ok( $u, "check_password"); ok( $u->check_password( "s3cr3t" ), "password is s3cr3t"); +ok( $m->user_supports(qw/session/), "user_supports session"); + +is( $u->store, $o, "can get store"); + +can_ok( $m, "from_session" ); +can_ok( $u, "for_session" ); + +my $recovered = $u->store->from_session( undef, $u->for_session ); + +is( $recovered->username, $u->username, "recovery from session works");