| 1 | package Catalyst::Authentication::User::KiokuDB; | ||
| 2 | |||
| 3 | use Moose; | ||
| 4 | use base qw/Catalyst::Authentication::User/; | ||
| 5 | |||
| 6 | has id => ( | ||
| 7 | isa => 'Str', | ||
| 8 | is => 'rw', | ||
| 9 | ); | ||
| 10 | |||
| 11 | has username => ( | ||
| 12 | isa => 'Str', | ||
| 13 | is => 'rw', | ||
| 14 | ); | ||
| 15 | |||
| 16 | has password => ( | ||
| 17 | isa => 'Str', | ||
| 18 | is => 'rw', | ||
| 19 | ); | ||
| 20 | |||
| 21 | has crypted_password => ( | ||
| 22 | isa => 'Str', | ||
| 23 | is => 'rw', | ||
| 24 | ); | ||
| 25 | |||
| 26 | has hashed_password => ( | ||
| 27 | isa => 'Str', | ||
| 28 | is => 'rw', | ||
| 29 | ); | ||
| 30 | |||
| 31 | has hash_algorithm => ( | ||
| 32 | isa => 'Str', | ||
| 33 | is => 'rw', | ||
| 34 | ); | ||
| 35 | |||
| 36 | has roles => ( | ||
| 37 | isa => 'ArrayRef', | ||
| 38 | is => 'rw', | ||
| 39 | auto_deref => 1, | ||
| 40 | ); | ||
| 41 | |||
| 42 | sub TO_JSON { | ||
| 43 | my $self = shift; | ||
| 44 | my %ret; | ||
| 45 | for my $k (qw/id username password crypted_password hashed_password hash_algorithm roles/) { | ||
| 46 | my $v = $self->$k; | ||
| 47 | $ret{$k} = $v if defined $v; | ||
| 48 | } | ||
| 49 | return \%ret; | ||
| 50 | } | ||
| 51 | |||
| 52 | |||
| 53 | # all hail the gods of cut and paste | ||
| 54 | my %features = ( | ||
| 55 | password => { | ||
| 56 | clear => ["password"], | ||
| 57 | crypted => ["crypted_password"], | ||
| 58 | hashed => [qw/hashed_password hash_algorithm/], | ||
| 59 | self_check => undef, | ||
| 60 | }, | ||
| 61 | roles => ["roles"], | ||
| 62 | session => 1, | ||
| 63 | ); | ||
| 64 | |||
| 65 | sub supports { | ||
| 66 | my ($self, @spec) = @_; | ||
| 67 | |||
| 68 | my $cursor = \%features; | ||
| 69 | |||
| 70 | return 1 if @spec == 1 and $self->can($spec[0]); | ||
| 71 | |||
| 72 | # XXX is this correct? | ||
| 73 | for (@spec) { | ||
| 74 | return if ref($cursor) ne "HASH"; | ||
| 75 | $cursor = $cursor->{$_}; | ||
| 76 | } | ||
| 77 | |||
| 78 | if (ref $cursor) { | ||
| 79 | die "Bad feature spec: '@spec'" unless ref $cursor eq "ARRAY"; | ||
| 80 | foreach my $key (@$cursor) { | ||
| 81 | return undef unless $self->can($key); | ||
| 82 | } | ||
| 83 | return 1; | ||
| 84 | } | ||
| 85 | else { | ||
| 86 | return $cursor; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | sub for_session { | ||
| 91 | my $self = shift; | ||
| 92 | return $self; # KiokuDB should be fine with storing objects in the session | ||
| 93 | } | ||
| 94 | |||
| 95 | sub from_session { | ||
| 96 | my ($self, $c, $user) = @_; | ||
| 97 | return $user; # normally we should have gotten ourselves back | ||
| 98 | } | ||
| 99 | |||
| 100 | |||
| 101 | no Moose; | ||
| 102 | 1; | ||
| 103 | |||
| 104 | =pod | ||
| 105 | |||
| 106 | =head1 NAME | ||
| 107 | |||
| 108 | Catalyst::Authentication::User::KiokuDB - User object for KiokuDB | ||
| 109 | |||
| 110 | =head1 SYNOPSIS | ||
| 111 | |||
| 112 | use Catalyst::Authentication::User::KiokuDB; | ||
| 113 | |||
| 114 | Catalyst::Authentication::User::KiokuDB->new( | ||
| 115 | username => "kitteh", | ||
| 116 | password => "baddog", | ||
| 117 | roles => [qw/sleep eat play purr/], | ||
| 118 | ); | ||
| 119 | |||
| 120 | =head1 DESCRIPTION | ||
| 121 | |||
| 122 | This implementation of authentication user object is intended to go hand in | ||
| 123 | hand with L<Catalyst::Authentication::Store::KiokuDB>. | ||
| 124 | |||
| 125 | =head1 METHODS | ||
| 126 | |||
| 127 | Implements nothing beyond the requisite interface from its superclass | ||
| 128 | |||
| 129 | =head1 AUTHOR | ||
| 130 | |||
| 131 | Robin Berjon, <robin@berjon.com>, L<http://robineko.com/> | ||
| 132 | |||
| 133 | =head1 COPYRIGHT | ||
| 134 | |||
| 135 | This program is free software, you can redistribute it and/or modify it | ||
| 136 | under the same terms as Perl itself. | ||
| 137 | |||
| 138 | =cut |