Commit 5c5556a8 authored by Xavier Guimard's avatar Xavier Guimard

2F choice works (#1148)

TODO: logos
parent dc23b5e8
......@@ -3,7 +3,11 @@ package Lemonldap::NG::Portal::2F::Engines::Default;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(
PE_ERROR
PE_NOTOKEN
PE_OK
PE_SENDRESPONSE
PE_TOKENEXPIRED
);
our $VERSION = '2.0.0';
......@@ -68,7 +72,7 @@ sub init {
# Store module
push @{ $self->{ $i ? 'sfRModules' : 'sfModules' } },
{ m => $m, r => $rule };
{ p => $prefix, m => $m, r => $rule };
}
else {
$self->logger->debug(' -> not enabled');
......@@ -116,11 +120,12 @@ sub run {
$req->sessionInfo->{_2fRealSession} = $req->id;
$req->sessionInfo->{_2fUrldc} = $req->urldc;
my $token = $self->ott->createToken( $req->sessionInfo );
delete $req->{authResult};
# If only one 2F is authorizated, display it
unless ($#am) {
my $res = $am[0]->run( $req, $token );
delete $req->{authResult} if ($res);
$req->authResult($res);
return $res;
}
......@@ -135,7 +140,8 @@ sub run {
MODULES => [ map { { CODE => $_->prefix, LOGO => $_->logo } } @am ],
}
);
return PE_OK;
$req->response($tpl);
return PE_SENDRESPONSE;
# TODO:
# - 2fchoice.tpl
......@@ -143,6 +149,46 @@ sub run {
# - add logos for 2F modules
}
sub choice {
my ( $self, $req ) = @_;
my $token;
# Restore session
unless ( $token = $req->param('token') ) {
$self->userLogger->error( $self->prefix . ' 2F access without token' );
$req->mustRedirect(1);
return $self->p->do( $req, [ sub { PE_NOTOKEN } ] );
}
my $session;
unless ( $session = $self->ott->getToken($token) ) {
$self->userLogger->info('Token expired');
return $self->p->do( $req, [ sub { PE_TOKENEXPIRED } ] );
}
$req->sessionInfo($session);
# New token
$token = $self->ott->createToken($session);
my $ch = $req->param('sf');
foreach my $m ( @{ $self->sfModules } ) {
if ( $m->{m}->prefix eq $ch ) {
my $res = $m->{m}->run( $req, $token );
$req->authResult($res);
return $self->p->do(
$req,
[
sub { $res }, 'controlUrl',
'buildCookie', @{ $self->p->afterDatas },
]
);
}
}
$self->userLogger->error('Bd 2F choice');
return $self->p->lmError( $req, 500 );
}
sub _redirect {
my ( $self, $req ) = @_;
my $arg = $req->env->{QUERY_STRING};
......
......@@ -20,7 +20,7 @@ sub authProcess { qw(extractFormInfo getUser authenticate) }
sub sessionDatas {
qw(setAuthSessionInfo setSessionInfo setMacros setGroups setPersistentSessionInfo
setLocalGroups store buildCookie secondFactor);
setLocalGroups store secondFactor buildCookie);
}
# RESPONSE HANDLER
......
......@@ -30,7 +30,7 @@
</main>
<div class="buttons">
<a id="goback" href="" class="btn btn-primary" role="button">
<a id="goback" href="<TMPL_VAR NAME="PORTAL_URL"><TMPL_IF NAME="AUTH_URL">/?url=<TMPL_VAR NAME="AUTH_URL"></TMPL_IF>" class="btn btn-primary" role="button">
<span class="glyphicon glyphicon-home"></span>&nbsp;
<span trspan="goToPortal">Go to portal</span>
</a>
......
......@@ -28,6 +28,7 @@
</main>
<div class="buttons">
<a id="goback" href="<TMPL_VAR NAME="PORTAL_URL"><TMPL_IF NAME="AUTH_URL">/?url=<TMPL_VAR NAME="AUTH_URL"></TMPL_IF>" class="btn btn-primary" role="button">
<a id="goback" href="" class="btn btn-primary" role="button">
<span class="glyphicon glyphicon-home"></span>&nbsp;
<span trspan="goToPortal">Go to portal</span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment