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