Commit | Line | Data |
e8a7c384 |
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 | |
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 | |
039544ff |
16 | bless { store => $store, user => $user }, $class; |
e8a7c384 |
17 | } |
18 | |
7efcea1c |
19 | sub id { |
20 | my $self = shift; |
21 | return $self->user->username; |
22 | } |
23 | |
e8a7c384 |
24 | sub supported_features { |
25 | return { |
26 | password => { |
27 | self_check => 1, |
47fb088e |
28 | }, |
29 | session => 1 |
e8a7c384 |
30 | }; |
31 | } |
32 | |
33 | sub check_password { |
34 | my ( $self, $password ) = @_; |
3e0bbcff |
35 | return $self->user->check_password( $password ); |
e8a7c384 |
36 | } |
37 | |
38 | sub roles { |
39 | my $self = shift; |
cedb9fb4 |
40 | my $field = $self->user->extra_info->[0]; |
41 | return defined $field ? split /,/, $field : (); |
e8a7c384 |
42 | } |
43 | |
47fb088e |
44 | sub for_session { |
45 | my $self = shift; |
7efcea1c |
46 | return $self->id; |
47fb088e |
47 | } |
48 | |
039544ff |
49 | sub AUTOLOAD { |
50 | my $self = shift; |
51 | |
52 | ( my $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ ); |
53 | |
54 | return if $method eq "DESTROY"; |
55 | |
56 | $self->user->$method; |
47fb088e |
57 | } |
58 | |
e8a7c384 |
59 | __PACKAGE__; |
60 | |
61 | __END__ |
62 | |
63 | =pod |
64 | |
65 | =head1 NAME |
66 | |
67 | Catalyst::Plugin::Authentication::Store::Htpasswd::User - A user object |
68 | representing an entry in an htpasswd file. |
69 | |
cedb9fb4 |
70 | =head1 DESCRIPTION |
e8a7c384 |
71 | |
cedb9fb4 |
72 | This object wraps an L<Authen::Htpasswd::User> object. An instance of it will be returned |
73 | by C<< $c->user >> when using L<Catalyst::Plugin::Authentication::Store::Htpasswd>. Methods |
74 | not defined in this module are passed through to the L<Authen::Htpasswd::User> object. The |
75 | object stringifies to the username. |
e8a7c384 |
76 | |
cedb9fb4 |
77 | =head1 METHODS |
78 | |
79 | =head2 new($store,$user) |
80 | |
81 | Creates a new object from a store object, normally an instance of |
82 | L<Catalyst::Plugin::Authentication::Store::Htpasswd::Backend>, and a user object, |
83 | normally an instance of L<Authen::Htpasswd::User>. |
84 | |
85 | =head2 id |
86 | |
87 | Returns the username. |
88 | |
89 | =head2 check_password($password) |
90 | |
91 | Returns whether the password is valid. |
92 | |
93 | =head2 roles |
94 | |
95 | Returns an array of roles, which is extracted from a comma-separated list in the |
96 | third field of the htpasswd file. |
97 | |
98 | =head1 COPYRIGHT & LICNESE |
99 | |
100 | Copyright (c) 2005 the aforementioned authors. All rights |
101 | reserved. This program is free software; you can redistribute |
102 | it and/or modify it under the same terms as Perl itself. |
e8a7c384 |
103 | |
104 | =cut |
105 | |
106 | |