line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
5
|
use strictures 1; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
25
|
|
2
|
|
|
|
|
|
|
package Mojito::Auth::Mongo; |
3
|
|
|
|
|
|
|
{ |
4
|
|
|
|
|
|
|
$Mojito::Auth::Mongo::VERSION = '0.24'; |
5
|
|
|
|
|
|
|
} |
6
|
1
|
|
|
1
|
|
1131
|
use Moo; |
|
1
|
|
|
|
|
19423
|
|
|
1
|
|
|
|
|
8
|
|
7
|
1
|
|
|
1
|
|
3096
|
use Data::Dumper::Concise; |
|
1
|
|
|
|
|
13005
|
|
|
1
|
|
|
|
|
643
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with('Mojito::Role::DB::Mongo'); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 Name |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Mojito::Auth::Deep - authentication delegatee class for MongoDB |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 Methods |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 add_user |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Provide the username, realm (default Mojito) and password. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub add_user { |
24
|
0
|
|
|
0
|
|
|
my ($self, $args) = @_; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
0
|
|
|
|
my $username = $args->{username} || $self->username; |
27
|
0
|
0
|
|
|
|
|
if ($self->get_user($username)) { |
28
|
0
|
|
|
|
|
|
warn "Username '$username' already taken!"; |
29
|
0
|
|
|
|
|
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
0
|
|
|
|
|
|
my @digest_input_parts = qw/ username realm password /; |
32
|
0
|
|
|
|
|
|
my $digest_input = join ':', map { $self->$_ } @digest_input_parts; |
|
0
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $HA1 = Digest::MD5::md5_hex($digest_input); |
34
|
0
|
|
|
|
|
|
my $md5_password = Digest::MD5::md5_hex( $self->password ); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $id = $self->collection->insert( |
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
first_name => $self->first_name, |
39
|
|
|
|
|
|
|
last_name => $self->last_name, |
40
|
|
|
|
|
|
|
email => $self->email, |
41
|
|
|
|
|
|
|
username => $self->username, |
42
|
|
|
|
|
|
|
realm => $self->realm, |
43
|
|
|
|
|
|
|
HA1 => $HA1, |
44
|
|
|
|
|
|
|
password => $md5_password |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
); |
47
|
0
|
|
|
|
|
|
return $id; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 get_user |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Get a user from the database. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_user { |
57
|
0
|
|
|
0
|
|
|
my ( $self, $username ) = @_; |
58
|
0
|
|
0
|
|
|
|
$username //= $self->username; |
59
|
0
|
0
|
|
|
|
|
return if !$username; |
60
|
0
|
|
|
|
|
|
return $self->collection->find_one( { username => $username } ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 remove_user |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Remove a user from the database. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub remove_user { |
70
|
0
|
|
|
0
|
|
|
my ( $self, $username ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
0
|
|
|
|
$username //= $self->username; |
73
|
0
|
0
|
|
|
|
|
return if !$username; |
74
|
0
|
|
|
|
|
|
return $self->collection->remove({ username => $username }); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# We compose the role AFTER the required methods are defined. |
78
|
|
|
|
|
|
|
with('Mojito::Auth::Role'); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 BUILD |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Set some things post object construction, pre object use. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub BUILD { |
87
|
0
|
|
|
0
|
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# We use the users collection for Auth stuff |
90
|
0
|
|
|
|
|
|
$self->collection_name('users'); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1 |