Articulate/Service/Login.pm

filter: Statementstmt 57.1% 20 / 35 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 2 totaltotal 53.0% 26 / 49 SCAR 14.0
CC
3
Cov
51%
handle_login
12.0
handle_logout
2.0
BEGIN
1.0
CRAP 4.0
« Articulate/Construction/LocationBased.pm ↑ Summary Articulate/Error.pm »
1 package Articulate::Service::Login;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Articulate::Syntax;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 with 'Articulate::Role::Service';
10  
11  
12 4 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 Articulate::Service::Login - provide login, logout
18  
19 =cut
20  
21 =head1 METHODS
22  
23 =head1 handle_login
24  
25 $self->handle_login( {user_id => 'admin', password => 'secret!' } )
26  
27 Tries to authenticate a user and, if successful, sets a session var (see L<Articulate::FrameworkAdapter>).
28  
29 Returns C<< {user_id => $user_id } >> if successful, throws an error otherwise.
30  
31 =head1 handle_logout
32  
33 $self->handle_login( {user_id => 'admin', password => 'secret!' } )
34  
35 Destroys the current session.
36  
37 Returns C<< {user_id => $user_id } >>.
38  
39 =cut
40  
41 sub handle_login {
42 0 ▶ my $self = shift;
Subroutine handle_login: not called CC=3 SCAR=24.8
Pod undocumented
43 0 my $request = shift;
44  
45 0 my $user_id = $request->data->{user_id};
46 0 my $password = $request->data->{password};
47  
48 0 ▶ if ( defined $user_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $user_id) { } 0 0 0
49 0 ▶ if ( $self->authentication->login ($user_id, $password) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->authentication->login($user_id, $password)) { } 0 0 0
50 0 $self->framework->user_id( $user_id );
51 0 response success => { user_id => $user_id };
52 } # Can we handle all the exceptions with 403s?
53 else {
54 0 throw_error Forbidden => 'Incorrect credentials';
55 }
56 }
57 else {
58 # todo: see if we have email and try to identify a user and verify with that
59 0 throw_error Forbidden => 'Missing user id';
60 }
61  
62 }
63  
64 sub handle_logout {
65 0 ▶ my $self = shift;
Subroutine handle_logout: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my $request = shift;
67 0 my $user_id = $self->framework->user_id;
68 0 $self->framework->session->destroy();
69 0 response success => { user_id => $user_id };
70 }
71  
72  
73 4 1;
« Articulate/Construction/LocationBased.pm ↑ Summary Articulate/Error.pm »