oh wait, it was already resolved
[catagits/Catalyst-Authentication-Store-Htpasswd.git] / lib / Catalyst / Plugin / Authentication / Store / Htpasswd / User.pm
CommitLineData
e8a7c384 1#!/usr/bin/perl
2
3package Catalyst::Plugin::Authentication::Store::Htpasswd::User;
4use base qw/Catalyst::Plugin::Authentication::User Class::Accessor::Fast/;
5
6use strict;
7use warnings;
8
039544ff 9BEGIN { __PACKAGE__->mk_accessors(qw/user store/) }
e8a7c384 10
7efcea1c 11use overload '""' => sub { shift->id }, fallback => 1;
47fb088e 12
e8a7c384 13sub 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 21sub id {
22 my $self = shift;
9f2d8669 23 return $self->user->username;
7efcea1c 24}
25
e8a7c384 26sub supported_features {
27 return {
28 password => {
29 self_check => 1,
47fb088e 30 },
0fed016a 31 session => 1,
8fade176 32 roles => 1,
e8a7c384 33 };
34}
35
36sub check_password {
37 my ( $self, $password ) = @_;
3e0bbcff 38 return $self->user->check_password( $password );
e8a7c384 39}
40
41sub roles {
42 my $self = shift;
cedb9fb4 43 my $field = $self->user->extra_info->[0];
44 return defined $field ? split /,/, $field : ();
e8a7c384 45}
46
47fb088e 47sub for_session {
48 my $self = shift;
7efcea1c 49 return $self->id;
47fb088e 50}
51
039544ff 52sub 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
e8a7c384 62__PACKAGE__;
63
64__END__
65
66=pod
67
68=head1 NAME
69
70Catalyst::Plugin::Authentication::Store::Htpasswd::User - A user object
71representing an entry in an htpasswd file.
72
cedb9fb4 73=head1 DESCRIPTION
e8a7c384 74
cedb9fb4 75This object wraps an L<Authen::Htpasswd::User> object. An instance of it will be returned
76by C<< $c->user >> when using L<Catalyst::Plugin::Authentication::Store::Htpasswd>. Methods
77not defined in this module are passed through to the L<Authen::Htpasswd::User> object. The
78object stringifies to the username.
e8a7c384 79
cedb9fb4 80=head1 METHODS
81
82=head2 new($store,$user)
83
84Creates a new object from a store object, normally an instance of
85L<Catalyst::Plugin::Authentication::Store::Htpasswd::Backend>, and a user object,
86normally an instance of L<Authen::Htpasswd::User>.
87
88=head2 id
89
90Returns the username.
91
92=head2 check_password($password)
93
94Returns whether the password is valid.
95
96=head2 roles
97
98Returns an array of roles, which is extracted from a comma-separated list in the
99third field of the htpasswd file.
100
f3ed9b84 101=head1 COPYRIGHT & LICENSE
cedb9fb4 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.
e8a7c384 106
107=cut
108
109