implement id() in Auth::Store::Htpasswd and change other methods to use it
[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;
7efcea1c 40 split( /,/, $self->user->extra_info );
e8a7c384 41}
42
47fb088e 43sub for_session {
44 my $self = shift;
7efcea1c 45 return $self->id;
47fb088e 46}
47
039544ff 48sub AUTOLOAD {
49 my $self = shift;
50
51 ( my $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ );
52
53 return if $method eq "DESTROY";
54
55 $self->user->$method;
47fb088e 56}
57
e8a7c384 58__PACKAGE__;
59
60__END__
61
62=pod
63
64=head1 NAME
65
66Catalyst::Plugin::Authentication::Store::Htpasswd::User - A user object
67representing an entry in an htpasswd file.
68
69=head1 SYNOPSIS
70
71 use Catalyst::Plugin::Authentication::Store::Htpasswd::User;
72
73=head1 DESCRIPTION
74
75=cut
76
77