| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package KiokuX::User; |
|
4
|
2
|
|
|
2
|
|
387938
|
use MooseX::Role::Parameterized; |
|
|
2
|
|
|
|
|
818279
|
|
|
|
2
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
79047
|
use namespace::clean -except => 'meta'; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
23
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
parameter id => ( |
|
11
|
|
|
|
|
|
|
isa => 'HashRef', |
|
12
|
|
|
|
|
|
|
default => sub { +{} }, |
|
13
|
|
|
|
|
|
|
); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
parameter password => ( |
|
16
|
|
|
|
|
|
|
isa => 'HashRef', |
|
17
|
|
|
|
|
|
|
default => sub { +{} }, |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
role { |
|
21
|
|
|
|
|
|
|
my ($p) = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
with 'KiokuX::User::ID' => $p->id, |
|
24
|
|
|
|
|
|
|
'KiokuX::User::Password' => $p->password; |
|
25
|
|
|
|
|
|
|
}; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__PACKAGE__ |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
__END__ |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=pod |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
KiokuX::User - A generic role for user objects stored in L<KiokuDB> |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
package MyFoo::Schema::User; |
|
40
|
|
|
|
|
|
|
use Moose; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
use KiokuX::User::Util qw(crypt_password); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
with qw(KiokuX::User); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $user = MyFoo::Schema::User->new( |
|
47
|
|
|
|
|
|
|
id => $user_id, |
|
48
|
|
|
|
|
|
|
password => crypt_password($password), |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$user->kiokudb_object_id; # "user:$user_id" |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
if ( $user->check_password($read_password) ) { |
|
54
|
|
|
|
|
|
|
warn "Login successful"; |
|
55
|
|
|
|
|
|
|
} else { |
|
56
|
|
|
|
|
|
|
warn "Login failed"; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This role provides a fairly trivial set of attributes and methods designed to |
|
62
|
|
|
|
|
|
|
ease the storage of objects representing users in a KiokuDB database. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
It consumes L<KiokuX::User::ID> which provides the C<id> attribute and related |
|
65
|
|
|
|
|
|
|
methods as well as L<KiokuDB::Role::ID> integration, and |
|
66
|
|
|
|
|
|
|
L<KiokuX::User::Password> which provides an L<Authen::Passphrase> based |
|
67
|
|
|
|
|
|
|
C<password> attribute and a C<check_password> method. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 USE AS A DELEGATE |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
This role strictly implements a notion of an authenticatable identity, not of a |
|
72
|
|
|
|
|
|
|
user. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
If you want to support renaming, multiple authentication methods (e.g. a |
|
75
|
|
|
|
|
|
|
password and/or an openid), it's best to create identity delegates that consume |
|
76
|
|
|
|
|
|
|
this role, and have them point at the actual user object: |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
package MyFoo::Schema::Identity; |
|
79
|
|
|
|
|
|
|
use Moose::Role; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
has user => ( |
|
82
|
|
|
|
|
|
|
isa => "MyFoo::Schema::User", |
|
83
|
|
|
|
|
|
|
is => "ro", |
|
84
|
|
|
|
|
|
|
required => 1, |
|
85
|
|
|
|
|
|
|
); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
And here's an example username identity: |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
package MyFoo::Schema::Identity::Username; |
|
90
|
|
|
|
|
|
|
use Moose; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
with qw( |
|
93
|
|
|
|
|
|
|
MyFoo::Schema::Identity |
|
94
|
|
|
|
|
|
|
KiokuX::User |
|
95
|
|
|
|
|
|
|
); |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
and then point back to these identities from the user: |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
has identities => ( |
|
100
|
|
|
|
|
|
|
isa => "ArrayRef[MyFoo::Schema::Identity]", |
|
101
|
|
|
|
|
|
|
is => "rw", |
|
102
|
|
|
|
|
|
|
required => 1, |
|
103
|
|
|
|
|
|
|
); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Since the identity is part of the objects' ID uniqueness is enforced in a |
|
106
|
|
|
|
|
|
|
portable way (you don't need to use the DBI backend and a custom unique |
|
107
|
|
|
|
|
|
|
constraint). |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This also allows you to easily add additional authentication schemes, change |
|
110
|
|
|
|
|
|
|
them, provide namespacing support and so on without affecting the high level |
|
111
|
|
|
|
|
|
|
user object, which represents the actual account holder regardless of the |
|
112
|
|
|
|
|
|
|
authentication scheme they used. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 VERSION CONTROL |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
L<http://github.com/nothingmuch/kiokux-user/> |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Yuval Kogman E<lt>nothingmuch@woobling.orgE<gt> |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Copyright (c) 2008, 2009 Yuval Kogman, Infinity Interactive. All |
|
125
|
|
|
|
|
|
|
rights reserved This program is free software; you can redistribute |
|
126
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# ex: set sw=4 et: |
|
131
|
|
|
|
|
|
|
|