3 package Catalyst::Plugin::Authentication::Store::Minimal::Backend;
8 use Catalyst::Plugin::Authentication::User::Hash;
12 my ( $class, $config, $app) = @_;
14 bless { hash => $config->{'users'} }, $class;
18 my ( $self, $c, $id ) = @_;
20 return $id if ref $id;
22 $self->find_user( { id => $id } );
25 ## this is not necessarily a good example of what find_user can do, since all we do is
26 ## look up with the id anyway. find_user can be used to locate a user based on other
27 ## combinations of data. See C::P::Authentication::Store::DBIx::Class for a better example
29 my ( $self, $userinfo, $c ) = @_;
31 my $id = $userinfo->{'id'};
33 return unless exists $self->{'hash'}{$id};
35 my $user = $self->{'hash'}{$id};
38 if ( Scalar::Util::blessed($user) ) {
42 elsif ( ref $user eq "HASH" ) {
44 return bless $user, "Catalyst::Plugin::Authentication::User::Hash";
47 Catalyst::Exception->throw( "The user '$id' is a reference of type "
49 . " but should be a HASH" );
53 Catalyst::Exception->throw(
54 "The user '$id' is has to be a hash reference or an object");
63 # choose a random user
64 scalar keys %{ $self->{hash} };
65 ( undef, my $user ) = each %{ $self->{hash} };
70 ## Backwards compatibility
72 # This is a backwards compatible routine. get_user is specifically for loading a user by it's unique id
73 # find_user is capable of doing the same by simply passing { id => $id }
74 # no new code should be written using get_user as it is deprecated.
76 my ( $self, $id ) = @_;
77 $self->find_user({id => $id});
90 Catalyst::Plugin::Authentication::Store::Minimal::Backend - Minimal
91 authentication storage backend.
95 # you probably just want Store::Minimal under most cases,
96 # but if you insist you can instantiate your own store:
98 use Catalyst::Plugin::Authentication::Store::Minimal::Backend;
102 Authentication::Credential::Password
106 user => { password => "s3cr3t" },
109 our $users = Catalyst::Plugin::Authentication::Store::Minimal::Backend->new(\%users);
112 my ( $self, $c ) = @_;
114 $c->login( $users->get_user( $c->req->param("login") ),
115 $c->req->param("password") );
120 You probably want L<Catalyst::Plugin::Authentication::Store::Minimal>, unless
121 you are mixing several stores in a single app and one of them is Minimal.
123 Otherwise, this lets you create a store manually.
131 Constructs a new store object, which uses the supplied hash ref as it's backing
136 Keys the hash by $id and returns the value.
138 If the return value is unblessed it will be blessed as
139 L<Catalyst::Plugin::Authentication::User::Hash>.
141 =item from_session $id
143 Delegates to C<get_user>.
147 Chooses a random user from the hash and delegates to it.