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 | |
3e0bbcff |
9 | use Authen::Htpasswd; |
e8a7c384 |
10 | use Catalyst::Plugin::Authentication::Store::Htpasswd::User; |
11 | |
12 | BEGIN { __PACKAGE__->mk_accessors(qw/file/) } |
0b5b70ba |
13 | |
14 | sub 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 | |
20 | sub get_user { |
21 | my ( $self, $id ) = @_; |
039544ff |
22 | Catalyst::Plugin::Authentication::Store::Htpasswd::User->new( $self, $self->file->lookup_user($id) ); |
0b5b70ba |
23 | } |
24 | |
25 | sub 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 |
32 | sub 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 |
45 | Catalyst::Plugin::Authentication::Store::Htpasswd::Backend - Htpasswd |
0b5b70ba |
46 | authentication 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 |
75 | You probably want L<Catalyst::Plugin::Authentication::Store::Htpasswd>, unless |
76 | you are mixing several stores in a single app and one of them is Htpasswd. |
0b5b70ba |
77 | |
78 | Otherwise, this lets you create a store manually. |
79 | |
80 | =head1 METHODS |
81 | |
cedb9fb4 |
82 | =head2 new $hash_ref |
0b5b70ba |
83 | |
84 | Constructs a new store object, which uses the supplied hash ref as it's backing |
85 | structure. |
86 | |
cedb9fb4 |
87 | =head2 get_user $id |
0b5b70ba |
88 | |
89 | Keys the hash by $id and returns the value. |
90 | |
91 | If the return value is unblessed it will be blessed as |
92 | L<Catalyst::Plugin::Authentication::User::Hash>. |
93 | |
cedb9fb4 |
94 | =head2 user_supports |
0b5b70ba |
95 | |
96 | Chooses a random user from the hash and delegates to it. |
97 | |
f3ed9b84 |
98 | =head1 COPYRIGHT & LICENSE |
cedb9fb4 |
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 | |