« blib/lib/Lemonldap/NG/Portal/Lib/Wrapper.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/UserDB/Slave.pm »
| 1 | package Lemonldap::NG::Portal::2F::Mail2F; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use Mouse; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | PE_OK | ||||||||||||||||||||||||||||||||||
| 7 | PE_ERROR | ||||||||||||||||||||||||||||||||||
| 8 | PE_BADOTP | ||||||||||||||||||||||||||||||||||
| 9 | PE_FORMEMPTY | ||||||||||||||||||||||||||||||||||
| 10 | PE_MUSTHAVEMAIL | ||||||||||||||||||||||||||||||||||
| 11 | PE_SENDRESPONSE | ||||||||||||||||||||||||||||||||||
| 12 | 11 | ); | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 11 | our $VERSION = '2.0.16'; | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 11 | extends qw( | |||||||||||||||||||||||||||||||||
| 17 | Lemonldap::NG::Portal::Lib::Code2F | ||||||||||||||||||||||||||||||||||
| 18 | Lemonldap::NG::Portal::Lib::SMTP | ||||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | # INITIALIZATION | ||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | # Prefix can overriden by sfExtra and is used for routes | ||||||||||||||||||||||||||||||||||
| 24 | 11 | has prefix => ( is => 'rw', default => 'mail' ); | |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | # Used to lookup config | ||||||||||||||||||||||||||||||||||
| 27 | 11 | has conf_type => ( is => 'ro', default => 'mail' ); | |||||||||||||||||||||||||||||||||
| 28 | 11 | has legend => ( is => 'rw', default => 'enterMail2fCode' ); | |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | has ott => ( | ||||||||||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 32 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||
| 34 | my $ott = | ||||||||||||||||||||||||||||||||||
| 35 | 9 | $_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken'); | |||||||||||||||||||||||||||||||||
| 36 | $ott->timeout( $_[0]->{conf}->{mail2fTimeout} | ||||||||||||||||||||||||||||||||||
| 37 | || $_[0]->{conf}->{sfLoginTimeout} | ||||||||||||||||||||||||||||||||||
| 38 | 9 | ▶ | || $_[0]->{conf}->{formTimeout} ); | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
$_[0]{'conf'}{'mail2fTimeout'} || $_[0]{'conf'}{'sfLoginTimeout'} || $_[0]{'conf'}{'formTimeout'}
$_[0]{"conf"}{"mail2fTimeout"} or $_[0]{"conf"}{"sfLoginTimeout"}
MC/DC0%0/3
$_[0]{'conf'}{'mail2fTimeout'} || $_[0]{'conf'}{'sfLoginTimeout'} || $_[0]{'conf'}{'formTimeout'}
$_[0]{"conf"}{"mail2fTimeout"}
$_[0]{"conf"}{"sfLoginTimeout"}
$_[0]{'conf'}{'formTimeout'}
Truth table50%2/4
A or B || C
A= $_[0]{"conf"}{"mail2fTimeout"}B= $_[0]{"conf"}{"sfLoginTimeout"}C= $_[0]{'conf'}{'formTimeout'}
| |||||||||||||||||||||||||||||||||||
| 39 | 9 | return $ott; | |||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||
| 41 | 11 | ); | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | has sessionKey => ( | ||||||||||||||||||||||||||||||||||
| 44 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 45 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 46 | 14 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||
| 47 | 14 | ▶ | return "destination" if $_[0]->is_registrable; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 48 | return $_[0]->{conf}->{mail2fSessionKey} | ||||||||||||||||||||||||||||||||||
| 49 | 11 | ▶ | || $_[0]->{conf}->{mailSessionKey}; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_[0]{'conf'}{'mail2fSessionKey'} || $_[0]{'conf'}{'mailSessionKey'}
MC/DC0%0/2
$_[0]{'conf'}{'mail2fSessionKey'} || $_[0]{'conf'}{'mailSessionKey'}
$_[0]{'conf'}{'mail2fSessionKey'}
$_[0]{'conf'}{'mailSessionKey'}
Truth table66%2/3
A || B
A= $_[0]{'conf'}{'mail2fSessionKey'}B= $_[0]{'conf'}{'mailSessionKey'}
| |||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||
| 51 | 11 | ); | |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | # Mail2F always uses code generation | ||||||||||||||||||||||||||||||||||
| 54 | has code_activation => ( | ||||||||||||||||||||||||||||||||||
| 55 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 56 | lazy => 1, | ||||||||||||||||||||||||||||||||||
| 57 | 14 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 14 | ▶ | $_[0]->{conf}->{mail2fCodeRegex} || '\d{6}'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||
| 61 | 11 | ); | |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 14 | ▶ | sub init { | ||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=8.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 64 | 14 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | 14 | ▶ | unless ( $self->sessionKey ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 67 | 0 | $self->error( | |||||||||||||||||||||||||||||||||
| 68 | $self->prefix . '2f: missing session key parameter, aborting' ); | ||||||||||||||||||||||||||||||||||
| 69 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 14 | return $self->SUPER::init(); | |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | # Return custom code when no email | ||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 77 | 0 | my ( $self, $req, $token ) = @_; | |||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ( !$self->is_registrable ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | 0 | my $dest = $req->{sessionInfo}->{ $self->sessionKey }; | |||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | unless ($dest) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 82 | $self->logger->error( $self->prefix | ||||||||||||||||||||||||||||||||||
| 83 | . '2f: could not find mail attribute for login ' | ||||||||||||||||||||||||||||||||||
| 84 | 0 | . $req->{sessionInfo}->{_user} ); | |||||||||||||||||||||||||||||||||
| 85 | 0 | return PE_MUSTHAVEMAIL; | |||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | # Delegate code generation to SUPER | ||||||||||||||||||||||||||||||||||
| 90 | 0 | return $self->SUPER::run( $req, $token ); | |||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub sendCode { | ||||||||||||||||||||||||||||||||
|
Subroutine
sendCode: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 94 | 0 | my ( $self, $req, $sessionInfo, $code ) = @_; | |||||||||||||||||||||||||||||||||
| 95 | 0 | my $dest = $sessionInfo->{ $self->sessionKey }; | |||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ( !$dest ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 98 | 0 | $self->logger->error( | |||||||||||||||||||||||||||||||||
| 99 | $self->prefix . '2f: unable to find email recipient' ); | ||||||||||||||||||||||||||||||||||
| 100 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | # Template engine expects $req->sessionInfo to be populated | ||||||||||||||||||||||||||||||||||
| 104 | # which is not the case during a resend | ||||||||||||||||||||||||||||||||||
| 105 | 0 | $req->sessionInfo($sessionInfo); | |||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||
| 107 | # Send mail | ||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 109 | $self->sendEmail( | ||||||||||||||||||||||||||||||||||
| 110 | $req, | ||||||||||||||||||||||||||||||||||
| 111 | subject => $self->conf->{mail2fSubject}, | ||||||||||||||||||||||||||||||||||
| 112 | subject_trmsg => 'mail2fSubject', | ||||||||||||||||||||||||||||||||||
| 113 | body => $self->conf->{mail2fBody}, | ||||||||||||||||||||||||||||||||||
| 114 | body_template => 'mail_2fcode', | ||||||||||||||||||||||||||||||||||
| 115 | dest => $dest, | ||||||||||||||||||||||||||||||||||
| 116 | params => { | ||||||||||||||||||||||||||||||||||
| 117 | code => $code, | ||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||
| 119 | ) | ||||||||||||||||||||||||||||||||||
| 120 | ) | ||||||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||||
| 122 | 0 | return 1; | |||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | else { | ||||||||||||||||||||||||||||||||||
| 126 | 0 | $self->logger->error( | |||||||||||||||||||||||||||||||||
| 127 | $self->prefix . "2f: unable to send code to $dest" ); | ||||||||||||||||||||||||||||||||||
| 128 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub verify_external { | ||||||||||||||||||||||||||||||||
|
Subroutine
verify_external: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 133 | 0 | my ( $self, $req, $session, $usercode ) = @_; | |||||||||||||||||||||||||||||||||
| 134 | 0 | $self->logger->error( | |||||||||||||||||||||||||||||||||
| 135 | $self->prefix . '2f: verify_external is not supposed to be invoked' ); | ||||||||||||||||||||||||||||||||||
| 136 | 0 | return PE_ERROR; | |||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | 11 | 1; | |||||||||||||||||||||||||||||||||