1 package Catalyst::Authentication::User;
3 use namespace::autoclean;
5 ## auth_realm is the realm this user came from.
6 has [qw/auth_realm store/] => ( is => 'rw' );
8 ## THIS IS NOT A COMPLETE CLASS! it is intended to provide base functionality only.
9 ## translation - it won't work if you try to use it directly.
11 ## chances are you want to override this.
12 sub id { shift->get('id'); }
14 ## this relies on 'supported_features' being implemented by the subclass..
15 ## but it is not an error if it is not. it just means you support nothing.
16 ## nihilist user objects are welcome here.
18 my ( $self, @spec ) = @_;
21 if ($self->can('supported_features')) {
22 $cursor = $self->supported_features;
24 # traverse the feature list,
26 #die "bad feature spec: @spec" if ref($cursor) ne "HASH";
27 return if ref($cursor) ne "HASH";
29 $cursor = $cursor->{$_};
37 ## get should return the value of the field specified as it's single argument from the underlying
38 ## user object. This is here to provide a simple, standard way of accessing individual elements of a user
39 ## object - ensuring no overlap between C::P::A::User methods and actual fieldnames.
40 ## this is not the most effecient method, since it uses introspection. If you have an underlying object
41 ## you most likely want to write this yourself.
43 my ($self, $field) = @_;
46 if ($object = $self->get_object and $object->can($field)) {
47 return $object->$field();
54 ## get_object should return the underlying user object. This is for when more advanced uses of the
55 ## user is required. Modifications to the existing user, etc. Changes in the object returned
56 ## by this routine may not be reflected in the C::P::A::User object - if this is required, re-authenticating
57 ## the user is probably the best route to take.
58 ## note that it is perfectly acceptable to return $self in cases where there is no underlying object.
63 ## obj is shorthand for get_object. This is originally from the DBIx::Class store, but
64 ## as it has become common usage, this makes things more compatible. Plus, it's shorter.
67 return $self->get_object(@_);
70 ## Backwards Compatibility
71 ## you probably want auth_realm, in fact. but this does work for backwards compatibility.
72 ## store should be a read-write accessor - so it was moved to mk_accessors
75 ## return $self->auth_realm->{store};
78 __PACKAGE__->meta->make_immutable;
86 Catalyst::Authentication::User - Base class for user objects.
90 package MyStore::User;
91 use base qw/Catalyst::Authentication::User/;
95 This is the base class for authenticated
101 A unique ID by which a user can be retrieved from the store.
105 Should return a class name that can be used to refetch the user using it's
110 An introspection method used to determine what features a user object has, to support credential and authorization plugins.
114 Returns the value for the $field provided.
118 Returns the underlying object storing the user data. The return value of this function will vary depending
119 on the storage module used.
123 Shorthand for get_object( )