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 | |
039544ff |
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 | |
039544ff |
18 | bless { store => $store, user => $user }, $class; |
e8a7c384 |
19 | } |
20 | |
7efcea1c |
21 | sub id { |
22 | my $self = shift; |
9f2d8669 |
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 ) = @_; |
3e0bbcff |
38 | return $self->user->check_password( $password ); |
e8a7c384 |
39 | } |
40 | |
41 | sub roles { |
42 | my $self = shift; |
cedb9fb4 |
43 | my $field = $self->user->extra_info->[0]; |
44 | return defined $field ? split /,/, $field : (); |
e8a7c384 |
45 | } |
46 | |
47fb088e |
47 | sub for_session { |
48 | my $self = shift; |
7efcea1c |
49 | return $self->id; |
47fb088e |
50 | } |
51 | |
039544ff |
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; |
47fb088e |
60 | } |
61 | |
16585083 |
62 | 1; |
e8a7c384 |
63 | |
64 | __END__ |
65 | |
66 | =pod |
67 | |
68 | =head1 NAME |
69 | |
16585083 |
70 | Catalyst::Authentication::Store::Htpasswd::User - A user object |
e8a7c384 |
71 | representing an entry in an htpasswd file. |
72 | |
cedb9fb4 |
73 | =head1 DESCRIPTION |
e8a7c384 |
74 | |
cedb9fb4 |
75 | This object wraps an L<Authen::Htpasswd::User> object. An instance of it will be returned |
16585083 |
76 | by C<< $c->user >> when using L<Catalyst::Authentication::Store::Htpasswd>. Methods |
cedb9fb4 |
77 | not defined in this module are passed through to the L<Authen::Htpasswd::User> object. The |
78 | object stringifies to the username. |
e8a7c384 |
79 | |
cedb9fb4 |
80 | =head1 METHODS |
81 | |
82 | =head2 new($store,$user) |
83 | |
84 | Creates a new object from a store object, normally an instance of |
16585083 |
85 | L<Catalyst::Authentication::Store::Htpasswd::Backend>, and a user object, |
cedb9fb4 |
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 | |
16585083 |
101 | =head2 for_session |
102 | |
103 | Returns the username, which is then stored in the session. |
104 | |
105 | =head2 supported_features |
106 | |
107 | Returns data about which featurs this user module supports. |
108 | |
109 | =head1 AUTHORS |
110 | |
111 | Yuval Kogman C<nothingmuch@woobling.org> |
112 | |
113 | David Kamholz C<dkamholz@cpan.org> |
114 | |
115 | Tomas Doran C<bobtfish@bobtfish.net> |
116 | |
f3ed9b84 |
117 | =head1 COPYRIGHT & LICENSE |
cedb9fb4 |
118 | |
119 | Copyright (c) 2005 the aforementioned authors. All rights |
120 | reserved. This program is free software; you can redistribute |
121 | it and/or modify it under the same terms as Perl itself. |
e8a7c384 |
122 | |
123 | =cut |
124 | |
125 | |