line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Articulate::Service::Login; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
2989
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
150
|
|
4
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
19
|
|
|
4
|
|
|
|
|
116
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
21
|
use Articulate::Syntax; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
31
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
6096
|
use Moo; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
25
|
|
9
|
|
|
|
|
|
|
with 'Articulate::Role::Service'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
1514
|
use Try::Tiny; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
440
|
|
13
|
4
|
|
|
4
|
|
23
|
use Scalar::Util qw(blessed); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
920
|
|
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). |
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
|
|
|
0
|
0
|
|
my $self = shift; |
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
|
0
|
|
|
|
|
if ( defined $user_id ) { |
49
|
0
|
0
|
|
|
|
|
if ( $self->authentication->login ($user_id, $password) ) { |
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
|
|
|
0
|
0
|
|
my $self = shift; |
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
|
|
|
|
|
|
|
1; |