Commit | Line | Data |
e8a7c384 |
1 | #!/usr/bin/perl |
2 | |
16585083 |
3 | package Catalyst::Authentication::Store::Htpasswd::User; |
d2924b3f |
4 | # ABSTRACT: A user object representing an entry in an htpasswd file. |
5 | |
16585083 |
6 | use base qw/Catalyst::Authentication::User Class::Accessor::Fast/; |
e8a7c384 |
7 | |
8 | use strict; |
9 | use warnings; |
10 | |
66a5688d |
11 | our $VERSION = '1.005'; |
12 | |
8ba206fe |
13 | BEGIN { __PACKAGE__->mk_accessors(qw/_user _store/) } |
e8a7c384 |
14 | |
7efcea1c |
15 | use overload '""' => sub { shift->id }, fallback => 1; |
47fb088e |
16 | |
e8a7c384 |
17 | sub new { |
039544ff |
18 | my ( $class, $store, $user ) = @_; |
e8a7c384 |
19 | |
ad94190e |
20 | return unless $user; |
21 | |
8ba206fe |
22 | bless { _store => $store, _user => $user }, $class; |
e8a7c384 |
23 | } |
24 | |
7efcea1c |
25 | sub id { |
26 | my $self = shift; |
8ba206fe |
27 | return $self->_user->username; |
7efcea1c |
28 | } |
29 | |
e8a7c384 |
30 | sub supported_features { |
31 | return { |
3e35965a |
32 | password => { |
33 | self_check => 1, |
47fb088e |
34 | }, |
3e35965a |
35 | session => 1, |
8fade176 |
36 | roles => 1, |
e8a7c384 |
37 | }; |
38 | } |
39 | |
40 | sub check_password { |
41 | my ( $self, $password ) = @_; |
8ba206fe |
42 | return $self->_user->check_password( $password ); |
e8a7c384 |
43 | } |
44 | |
45 | sub roles { |
46 | my $self = shift; |
8ba206fe |
47 | my $field = $self->_user->extra_info->[0]; |
cedb9fb4 |
48 | return defined $field ? split /,/, $field : (); |
e8a7c384 |
49 | } |
50 | |
8ba206fe |
51 | *for_session = \&id; |
52 | |
53 | *get_object = \&_user; |
47fb088e |
54 | |
039544ff |
55 | sub AUTOLOAD { |
56 | my $self = shift; |
57 | |
58 | ( my $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ ); |
59 | |
60 | return if $method eq "DESTROY"; |
61 | |
8ba206fe |
62 | $self->_user->$method; |
47fb088e |
63 | } |
64 | |
16585083 |
65 | 1; |
e8a7c384 |
66 | |
67 | __END__ |
68 | |
69 | =pod |
70 | |
cedb9fb4 |
71 | =head1 DESCRIPTION |
e8a7c384 |
72 | |
cedb9fb4 |
73 | This object wraps an L<Authen::Htpasswd::User> object. An instance of it will be returned |
16585083 |
74 | by C<< $c->user >> when using L<Catalyst::Authentication::Store::Htpasswd>. Methods |
cedb9fb4 |
75 | not defined in this module are passed through to the L<Authen::Htpasswd::User> object. The |
76 | object stringifies to the username. |
e8a7c384 |
77 | |
cedb9fb4 |
78 | =head1 METHODS |
79 | |
80 | =head2 new($store,$user) |
81 | |
82 | Creates a new object from a store object, normally an instance of |
16585083 |
83 | L<Catalyst::Authentication::Store::Htpasswd::Backend>, and a user object, |
cedb9fb4 |
84 | normally an instance of L<Authen::Htpasswd::User>. |
85 | |
86 | =head2 id |
87 | |
88 | Returns the username. |
89 | |
90 | =head2 check_password($password) |
91 | |
92 | Returns whether the password is valid. |
93 | |
94 | =head2 roles |
95 | |
96 | Returns an array of roles, which is extracted from a comma-separated list in the |
97 | third field of the htpasswd file. |
98 | |
16585083 |
99 | =head2 for_session |
100 | |
101 | Returns the username, which is then stored in the session. |
102 | |
103 | =head2 supported_features |
104 | |
105 | Returns data about which featurs this user module supports. |
106 | |
8ba206fe |
107 | =head2 get_object |
108 | |
109 | Returns the underlieing L<Authen::Htpasswd::User> object for this user |
110 | |
e8a7c384 |
111 | =cut |