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