| 1 | package Articulate::Service::Login; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 5 | ▶ | use Articulate::Syntax; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 5 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 5 | with 'Articulate::Role::Service'; | |||||||||
| 10 | |||||||||||
| 11 | 5 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 5 | ▶ | 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 (see L<Articulate::FrameworkAdapter>). | ||||||||||
| 27 | |||||||||||
| 28 | Returns C<< {user_id => $user_id } >> if successful, throws an error otherwise. | ||||||||||
| 29 | |||||||||||
| 30 | =head1 handle_logout | ||||||||||
| 31 | |||||||||||
| 32 | $self->handle_login( {user_id => 'admin', password => 'secret!' } ) | ||||||||||
| 33 | |||||||||||
| 34 | Destroys the current session. | ||||||||||
| 35 | |||||||||||
| 36 | Returns C<< {user_id => $user_id } >>. | ||||||||||
| 37 | |||||||||||
| 38 | =cut | ||||||||||
| 39 | |||||||||||
| 40 | sub handle_login { | ||||||||||
| 41 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
handle_login: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 42 | 0 | my $request = shift; | |||||||||
| 43 | |||||||||||
| 44 | 0 | my $user_id = $request->data->{user_id}; | |||||||||
| 45 | 0 | my $password = $request->data->{password}; | |||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | if ( defined $user_id ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | ▶ | if ( $self->authentication->login( $user_id, $password ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | $self->framework->user_id($user_id); | |||||||||
| 50 | 0 | response success => { user_id => $user_id }; | |||||||||
| 51 | } # Can we handle all the exceptions with 403s? | ||||||||||
| 52 | else { | ||||||||||
| 53 | 0 | throw_error Forbidden => 'Incorrect credentials'; | |||||||||
| 54 | } | ||||||||||
| 55 | } | ||||||||||
| 56 | else { | ||||||||||
| 57 | # todo: see if we have email and try to identify a user and verify with that | ||||||||||
| 58 | 0 | throw_error Forbidden => 'Missing user id'; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | sub handle_logout { | ||||||||||
| 64 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
handle_logout: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 65 | 0 | my $request = shift; | |||||||||
| 66 | 0 | my $user_id = $self->framework->user_id; | |||||||||
| 67 | 0 | $self->framework->session->destroy(); | |||||||||
| 68 | 0 | response success => { user_id => $user_id }; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 5 | 1; | |||||||||