| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Yukki::Model::User; |
|
2
|
|
|
|
|
|
|
$Yukki::Model::User::VERSION = '0.991_002'; # TRIAL |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
997
|
$Yukki::Model::User::VERSION = '0.991002';use v5.24; |
|
|
1
|
|
|
|
|
6
|
|
|
5
|
1
|
|
|
1
|
|
9
|
use utf8; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
10
|
|
|
6
|
1
|
|
|
1
|
|
40
|
use Moo; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'Yukki::Model'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
560
|
use Yukki::Types qw( LoginName ); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
21
|
|
|
11
|
1
|
|
|
1
|
|
644
|
use Yukki::TextUtil qw( load_file ); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
16
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
424
|
use Type::Params qw( validate ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
14
|
1
|
|
|
1
|
|
228
|
use Type::Utils; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
15
|
1
|
|
|
1
|
|
1839
|
use Types::Path::Tiny; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
12
|
|
|
16
|
1
|
|
|
1
|
|
295
|
use Types::Standard qw( slurpy Dict ); |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
8
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
958
|
use Yukki::User; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
32
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
8
|
use namespace::clean; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
12
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# ABSTRACT: lookup users |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub set_password { |
|
26
|
0
|
|
|
0
|
1
|
|
my ($self, $user, $clear_password) = @_; |
|
27
|
0
|
|
0
|
|
|
|
$clear_password //= $user->password; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $digest = $self->app->hasher; |
|
30
|
0
|
|
|
|
|
|
$digest->add($clear_password); |
|
31
|
0
|
|
|
|
|
|
$user->password($digest->generate); |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
return; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub save { |
|
38
|
0
|
|
|
0
|
1
|
|
my ($self, $user, %opt) = @_; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $user_file = $self->locate('user_path', $user->login_name); |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
0
|
0
|
|
|
|
if ($opt{create_only} && $user_file->exists) { |
|
43
|
0
|
|
|
|
|
|
die "User ", $user->login_name, " already exists."; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$user_file->parent->mkpath; |
|
47
|
0
|
0
|
|
|
|
|
$user_file->chmod(0600) if $user_file->exists; |
|
48
|
0
|
|
|
|
|
|
$user_file->spew_utf8($user->dump_yaml); |
|
49
|
0
|
|
|
|
|
|
$user_file->chmod(0400); |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub delete { |
|
56
|
0
|
|
|
0
|
1
|
|
my ($self, $user) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $user_file = $self->locate('user_path', $user->login_name); |
|
59
|
0
|
0
|
|
|
|
|
$user_file->remove if $user_file->is_file; |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub find { |
|
66
|
0
|
|
|
0
|
1
|
|
my ($self, $opt) |
|
67
|
|
|
|
|
|
|
= validate(\@_, class_type(__PACKAGE__), |
|
68
|
|
|
|
|
|
|
slurpy Dict[ |
|
69
|
|
|
|
|
|
|
login_name => LoginName |
|
70
|
|
|
|
|
|
|
], |
|
71
|
|
|
|
|
|
|
); |
|
72
|
0
|
|
|
|
|
|
my $login_name = $opt->{login_name}; |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $user_file = $self->locate('user_path', $login_name); |
|
75
|
0
|
0
|
|
|
|
|
if ($user_file->exists) { |
|
76
|
0
|
|
|
|
|
|
return Yukki::User->load_yaml($user_file->slurp_utf8); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub list { |
|
84
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $user_dir = $self->locate('user_path'); |
|
87
|
0
|
|
|
|
|
|
return map { $_->basename } $user_dir->children; |
|
|
0
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=pod |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=encoding UTF-8 |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Yukki::Model::User - lookup users |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 VERSION |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
version 0.991_002 |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $users = $app->model('User'); |
|
109
|
|
|
|
|
|
|
my $user = $users->find('bob'); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $login_name = $user->login_name; |
|
112
|
|
|
|
|
|
|
my $password = $user->password; |
|
113
|
|
|
|
|
|
|
my $name = $user->name; |
|
114
|
|
|
|
|
|
|
my $email = $user->email; |
|
115
|
|
|
|
|
|
|
my @groups = $user->groups->@*; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Read access to the current list of authorized users. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 METHODS |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 set_password |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$users->set_password($user, $cleartext); |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Given a password in cleartext, this will hash the password using the application's hasher. The second argument containing the cleartext password is optional. When omitted, the value returned by the C<password> accessor of the C<$user> object will be used instead. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 save |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$users->save($user, create_only => 1); |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Writes a L<Yukki::User> object to the users database. If the C<create_only> flag is set, the method will fail with an exception when the user already exists. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 delete |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$users->delete($user); |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Given a L<Yukki::User>, this method deletes the user file for that object. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 find |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $user = $users->find(login_name => $login_name); |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Returns a hash containing the information related to a specific user named by login name. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 list |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
my @names = $users->list; |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Returns a list of login names for all users configured. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 AUTHOR |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Andrew Sterling Hanenkamp <hanenkamp@cpan.org> |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Qubling Software LLC. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
162
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |