| 1 | package Articulate::Service::Login; | ||||||||||
| 2 | |||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 6 | ▶ | use Articulate::Syntax; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 6 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 6 | with 'Articulate::Role::Service'; | |||||||||
| 10 | |||||||||||
| 11 | 6 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 6 | ▶ | use Scalar::Util qw(blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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<Articulate::FrameworkAdapter>). | ||||||||||
| 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 | 0 | ▶ | sub handle_login { | ||||||||
|
Subroutine
handle_login: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 43 | 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 | ▶ | if ( defined $user_id ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | ▶ | if ( $self->authentication->login( $user_id, $password ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | sub handle_logout { | ||||||||
|
Subroutine
handle_logout: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 66 | 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 | 6 | 1; | |||||||||