| 1 | package Yukki::Model::User; | ||||||||||||||||||||||||||||
| 2 | 4 | $Yukki::Model::User::VERSION = '0.991_002'; # TRIAL | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | $Yukki::Model::User::VERSION = '0.991002';use v5.24; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | extends 'Yukki::Model'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Yukki::Types qw( LoginName ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Yukki::TextUtil qw( load_file ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Type::Params qw( validate ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Type::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use Types::Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use Types::Standard qw( slurpy Dict ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use Yukki::User; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 4 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # ABSTRACT: lookup users | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub set_password { | ||||||||||||||||||||||||||||
| 26 | 3 | ▶ | my ($self, $user, $clear_password) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set_password: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 3 | ▶ | $clear_password //= $user->password; | ||||||||||||||||||||||||||
|
Condition66%2/3
$clear_password //= $user->password
MC/DC0%0/2
$clear_password //= $user->password
$clear_password
$user->password
Truth table66%2/3
A //= B
A= $clear_passwordB= $user->password
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 3 | my $digest = $self->app->hasher; | |||||||||||||||||||||||||||
| 30 | 3 | $digest->add($clear_password); | |||||||||||||||||||||||||||
| 31 | 3 | $user->password($digest->generate); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | return; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub save { | ||||||||||||||||||||||||||||
| 38 | 3 | ▶ | my ($self, $user, %opt) = @_; | ||||||||||||||||||||||||||
|
Subroutine
save: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 | my $user_file = $self->locate('user_path', $user->login_name); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 3 | ▶ | if ($opt{create_only} && $user_file->exists) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt{"create_only"} and $user_file->exists
MC/DC0%0/2
$opt{"create_only"} and $user_file->exists
$opt{"create_only"}
$user_file->exists
Truth table33%1/3
A and B
A= $opt{"create_only"}B= $user_file->exists
| |||||||||||||||||||||||||||||
| 43 | 0 | die "User ", $user->login_name, " already exists."; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | $user_file->parent->mkpath; | |||||||||||||||||||||||||||
| 47 | 3 | ▶ | $user_file->chmod(0600) if $user_file->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 3 | $user_file->spew_utf8($user->dump_yaml); | |||||||||||||||||||||||||||
| 49 | 3 | $user_file->chmod(0400); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 3 | return; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub delete { | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my ($self, $user) = @_; | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | my $user_file = $self->locate('user_path', $user->login_name); | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | $user_file->remove if $user_file->is_file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | return; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub find { | ||||||||||||||||||||||||||||
| 66 | 1 | ▶ | my ($self, $opt) | ||||||||||||||||||||||||||
|
Subroutine
find: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | = validate(\@_, class_type(__PACKAGE__), | ||||||||||||||||||||||||||||
| 68 | slurpy Dict[ | ||||||||||||||||||||||||||||
| 69 | login_name => LoginName | ||||||||||||||||||||||||||||
| 70 | ], | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | 1 | my $login_name = $opt->{login_name}; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | my $user_file = $self->locate('user_path', $login_name); | |||||||||||||||||||||||||||
| 75 | 1 | ▶ | if ($user_file->exists) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 1 | return Yukki::User->load_yaml($user_file->slurp_utf8); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | return; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | sub list { | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | my $user_dir = $self->locate('user_path'); | |||||||||||||||||||||||||||
| 87 | 0 | return map { $_->basename } $user_dir->children; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 4 | 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 | ||||||||||||||||||||||||||||