line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Articulate::Service::Login; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
3649
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
201
|
|
4
|
6
|
|
|
6
|
|
24
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
128
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
23
|
use Articulate::Syntax; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
40
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
7766
|
use Moo; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
36
|
|
9
|
|
|
|
|
|
|
with 'Articulate::Role::Service'; |
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
1777
|
use Try::Tiny; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
313
|
|
12
|
6
|
|
|
6
|
|
26
|
use Scalar::Util qw(blessed); |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
1077
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Articulate::Service::Login - provide login, logout |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 METHODS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 handle_login |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$self->handle_login( {user_id => 'admin', password => 'secret!' } ) |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Tries to authenticate a user and, if successful, sets a session var |
27
|
|
|
|
|
|
|
(see L). |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Returns C<< {user_id => $user_id } >> if successful, throws an error |
30
|
|
|
|
|
|
|
otherwise. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 handle_logout |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$self->handle_login( {user_id => 'admin', password => 'secret!' } ) |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Destroys the current session. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Returns C<< {user_id => $user_id } >>. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub handle_login { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my $request = shift; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $user_id = $request->data->{user_id}; |
47
|
0
|
|
|
|
|
|
my $password = $request->data->{password}; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ( defined $user_id ) { |
50
|
0
|
0
|
|
|
|
|
if ( $self->authentication->login( $user_id, $password ) ) { |
51
|
0
|
|
|
|
|
|
$self->framework->user_id($user_id); |
52
|
0
|
|
|
|
|
|
return new_response success => { user_id => $user_id }; |
53
|
|
|
|
|
|
|
} # Can we handle all the exceptions with 403s? |
54
|
|
|
|
|
|
|
else { |
55
|
0
|
|
|
|
|
|
throw_error Forbidden => 'Incorrect credentials'; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else { |
59
|
|
|
|
|
|
|
# todo: see if we have email and try to identify a user and verify with that |
60
|
0
|
|
|
|
|
|
throw_error Forbidden => 'Missing user id'; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub handle_logout { |
66
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
my $request = shift; |
68
|
0
|
|
|
|
|
|
my $user_id = $self->framework->user_id; |
69
|
0
|
|
|
|
|
|
$self->framework->session->destroy(); |
70
|
0
|
|
|
|
|
|
return new_response success => { user_id => $user_id }; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |