Catalyst::Authentication::Store::Htpasswd::User - A user object


Catalyst-Authentication-Store-Htpasswd documentation Contained in the Catalyst-Authentication-Store-Htpasswd distribution.

Index


Code Index:

NAME

Top

Catalyst::Authentication::Store::Htpasswd::User - A user object representing an entry in an htpasswd file.

DESCRIPTION

Top

This object wraps an Authen::Htpasswd::User object. An instance of it will be returned by $c->user when using Catalyst::Authentication::Store::Htpasswd. Methods not defined in this module are passed through to the Authen::Htpasswd::User object. The object stringifies to the username.

METHODS

Top

new($store,$user)

Creates a new object from a store object, normally an instance of Catalyst::Authentication::Store::Htpasswd::Backend, and a user object, normally an instance of Authen::Htpasswd::User.

id

Returns the username.

check_password($password)

Returns whether the password is valid.

roles

Returns an array of roles, which is extracted from a comma-separated list in the third field of the htpasswd file.

for_session

Returns the username, which is then stored in the session.

supported_features

Returns data about which featurs this user module supports.

get_object

Returns the underlieing Authen::Htpasswd::User object for this user

AUTHORS

Top

Yuval Kogman nothingmuch@woobling.org

David Kamholz dkamholz@cpan.org

Tomas Doran bobtfish@bobtfish.net

COPYRIGHT & LICENSE

Top


Catalyst-Authentication-Store-Htpasswd documentation Contained in the Catalyst-Authentication-Store-Htpasswd distribution.

#!/usr/bin/perl

package Catalyst::Authentication::Store::Htpasswd::User;
use base qw/Catalyst::Authentication::User Class::Accessor::Fast/;

use strict;
use warnings;

BEGIN { __PACKAGE__->mk_accessors(qw/_user _store/) }

use overload '""' => sub { shift->id }, fallback => 1;

sub new {
	my ( $class, $store, $user ) = @_;

	return unless $user;

	bless { _store => $store, _user => $user }, $class;
}

sub id {
    my $self = shift;
    return $self->_user->username;
}

sub supported_features {
	return {
        password => {
            self_check => 1,
		},
        session => 1,
        roles => 1,
	};
}

sub check_password {
	my ( $self, $password ) = @_;
	return $self->_user->check_password( $password );
}

sub roles {
	my $self = shift;
	my $field = $self->_user->extra_info->[0];
	return defined $field ? split /,/, $field : ();
}

*for_session = \&id;

*get_object = \&_user;

sub AUTOLOAD {
	my $self = shift;
	
	( my $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ );

	return if $method eq "DESTROY";
	
	$self->_user->$method;
}

1;

__END__