prepare for release of C::P::Authentication::Store::Htpasswd
[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
039544ff 16 bless { store => $store, user => $user }, $class;
e8a7c384 17}
18
7efcea1c 19sub id {
20 my $self = shift;
21 return $self->user->username;
22}
23
e8a7c384 24sub supported_features {
25 return {
26 password => {
27 self_check => 1,
47fb088e 28 },
29 session => 1
e8a7c384 30 };
31}
32
33sub check_password {
34 my ( $self, $password ) = @_;
3e0bbcff 35 return $self->user->check_password( $password );
e8a7c384 36}
37
38sub roles {
39 my $self = shift;
cedb9fb4 40 my $field = $self->user->extra_info->[0];
41 return defined $field ? split /,/, $field : ();
e8a7c384 42}
43
47fb088e 44sub for_session {
45 my $self = shift;
7efcea1c 46 return $self->id;
47fb088e 47}
48
039544ff 49sub 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
67Catalyst::Plugin::Authentication::Store::Htpasswd::User - A user object
68representing an entry in an htpasswd file.
69
cedb9fb4 70=head1 DESCRIPTION
e8a7c384 71
cedb9fb4 72This object wraps an L<Authen::Htpasswd::User> object. An instance of it will be returned
73by C<< $c->user >> when using L<Catalyst::Plugin::Authentication::Store::Htpasswd>. Methods
74not defined in this module are passed through to the L<Authen::Htpasswd::User> object. The
75object stringifies to the username.
e8a7c384 76
cedb9fb4 77=head1 METHODS
78
79=head2 new($store,$user)
80
81Creates a new object from a store object, normally an instance of
82L<Catalyst::Plugin::Authentication::Store::Htpasswd::Backend>, and a user object,
83normally an instance of L<Authen::Htpasswd::User>.
84
85=head2 id
86
87Returns the username.
88
89=head2 check_password($password)
90
91Returns whether the password is valid.
92
93=head2 roles
94
95Returns an array of roles, which is extracted from a comma-separated list in the
96third 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