oh wait, it was already resolved
[catagits/Catalyst-Authentication-Store-Htpasswd.git] / lib / Catalyst / Plugin / Authentication / Store / Htpasswd / User.pm
1 #!/usr/bin/perl
2
3 package Catalyst::Plugin::Authentication::Store::Htpasswd::User;
4 use base qw/Catalyst::Plugin::Authentication::User Class::Accessor::Fast/;
5
6 use strict;
7 use warnings;
8
9 BEGIN { __PACKAGE__->mk_accessors(qw/user store/) }
10
11 use overload '""' => sub { shift->id }, fallback => 1;
12
13 sub new {
14         my ( $class, $store, $user ) = @_;
15
16         return unless $user;
17
18         bless { store => $store, user => $user }, $class;
19 }
20
21 sub id {
22     my $self = shift;
23     return $self->user->username;
24 }
25
26 sub supported_features {
27         return {
28                 password => {
29                         self_check => 1,
30                 },
31                 session => 1,
32         roles => 1,
33         };
34 }
35
36 sub check_password {
37         my ( $self, $password ) = @_;
38         return $self->user->check_password( $password );
39 }
40
41 sub roles {
42         my $self = shift;
43         my $field = $self->user->extra_info->[0];
44         return defined $field ? split /,/, $field : ();
45 }
46
47 sub for_session {
48     my $self = shift;
49     return $self->id;
50 }
51
52 sub AUTOLOAD {
53         my $self = shift;
54         
55         ( my $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ );
56
57         return if $method eq "DESTROY";
58         
59         $self->user->$method;
60 }
61
62 __PACKAGE__;
63
64 __END__
65
66 =pod
67
68 =head1 NAME
69
70 Catalyst::Plugin::Authentication::Store::Htpasswd::User - A user object
71 representing an entry in an htpasswd file.
72
73 =head1 DESCRIPTION
74
75 This object wraps an L<Authen::Htpasswd::User> object. An instance of it will be returned
76 by C<< $c->user >> when using L<Catalyst::Plugin::Authentication::Store::Htpasswd>. Methods 
77 not defined in this module are passed through to the L<Authen::Htpasswd::User> object. The
78 object stringifies to the username.
79
80 =head1 METHODS
81
82 =head2 new($store,$user)
83
84 Creates a new object from a store object, normally an instance of 
85 L<Catalyst::Plugin::Authentication::Store::Htpasswd::Backend>, and a user object,
86 normally an instance of L<Authen::Htpasswd::User>.
87
88 =head2 id
89
90 Returns the username.
91
92 =head2 check_password($password)
93
94 Returns whether the password is valid.
95
96 =head2 roles
97
98 Returns an array of roles, which is extracted from a comma-separated list in the
99 third field of the htpasswd file.
100
101 =head1 COPYRIGHT & LICENSE
102
103         Copyright (c) 2005 the aforementioned authors. All rights
104         reserved. This program is free software; you can redistribute
105         it and/or modify it under the same terms as Perl itself.
106
107 =cut
108
109