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