Update htpasswd store for registered stores
Yuval Kogman [Mon, 21 Nov 2005 13:37:26 +0000 (13:37 +0000)]
lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm
lib/Catalyst/Plugin/Authentication/Store/Htpasswd/User.pm
t/backend.t

index c048347..c5213b0 100644 (file)
@@ -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__
index a242ba5..ce4388a 100644 (file)
@@ -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__;
index 6834718..2eb77ca 100644 (file)
@@ -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");