prepare for release of C::P::Authentication::Store::Htpasswd
[catagits/Catalyst-Authentication-Store-Htpasswd.git] / lib / Catalyst / Plugin / Authentication / Store / Htpasswd / Backend.pm
CommitLineData
0b5b70ba 1#!/usr/bin/perl
2
e8a7c384 3package Catalyst::Plugin::Authentication::Store::Htpasswd::Backend;
4use base qw/Class::Accessor::Fast/;
0b5b70ba 5
6use strict;
7use warnings;
8
3e0bbcff 9use Authen::Htpasswd;
e8a7c384 10use Catalyst::Plugin::Authentication::Store::Htpasswd::User;
11
12BEGIN { __PACKAGE__->mk_accessors(qw/file/) }
0b5b70ba 13
14sub new {
3e0bbcff 15 my ( $class, $file, %extra ) = @_;
0b5b70ba 16
3e0bbcff 17 bless { file => ( ref $file ? $file : Authen::Htpasswd->new($file, \%extra) ) }, $class;
0b5b70ba 18}
19
20sub get_user {
21 my ( $self, $id ) = @_;
039544ff 22 Catalyst::Plugin::Authentication::Store::Htpasswd::User->new( $self, $self->file->lookup_user($id) );
0b5b70ba 23}
24
25sub user_supports {
26 my $self = shift;
27
e8a7c384 28 # this can work as a class method
29 Catalyst::Plugin::Authentication::Store::Htpasswd::User->supports(@_);
0b5b70ba 30}
31
039544ff 32sub from_session {
33 my ( $self, $c, $id ) = @_;
34 $self->get_user( $id );
35}
36
0b5b70ba 37__PACKAGE__;
38
39__END__
40
41=pod
42
43=head1 NAME
44
e8a7c384 45Catalyst::Plugin::Authentication::Store::Htpasswd::Backend - Htpasswd
0b5b70ba 46authentication storage backend.
47
48=head1 SYNOPSIS
49
e8a7c384 50 # you probably just want Store::Htpasswd under most cases,
0b5b70ba 51 # but if you insist you can instantiate your own store:
52
e8a7c384 53 use Catalyst::Plugin::Authentication::Store::Htpasswd::Backend;
0b5b70ba 54
55 use Catalyst qw/
56 Authentication
57 Authentication::Credential::Password
58 /;
59
60 my %users = (
61 user => { password => "s3cr3t" },
62 );
63
e8a7c384 64 our $users = Catalyst::Plugin::Authentication::Store::Htpasswd::Backend->new(\%users);
0b5b70ba 65
66 sub action : Local {
67 my ( $self, $c ) = @_;
68
69 $c->login( $users->get_user( $c->req->param("login") ),
70 $c->req->param("password") );
71 }
72
73=head1 DESCRIPTION
74
e8a7c384 75You probably want L<Catalyst::Plugin::Authentication::Store::Htpasswd>, unless
76you are mixing several stores in a single app and one of them is Htpasswd.
0b5b70ba 77
78Otherwise, this lets you create a store manually.
79
80=head1 METHODS
81
cedb9fb4 82=head2 new $hash_ref
0b5b70ba 83
84Constructs a new store object, which uses the supplied hash ref as it's backing
85structure.
86
cedb9fb4 87=head2 get_user $id
0b5b70ba 88
89Keys the hash by $id and returns the value.
90
91If the return value is unblessed it will be blessed as
92L<Catalyst::Plugin::Authentication::User::Hash>.
93
cedb9fb4 94=head2 user_supports
0b5b70ba 95
96Chooses a random user from the hash and delegates to it.
97
cedb9fb4 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.
0b5b70ba 103
104=cut
105
106