2017-03-23 13:41:53 +01:00
|
|
|
package Lemonldap::NG::Portal::Plugins::Upgrade;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2017-03-23 19:22:40 +01:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(
|
|
|
|
PE_CONFIRM
|
|
|
|
PE_OK
|
|
|
|
PE_TOKENEXPIRED
|
|
|
|
);
|
2017-03-23 13:41:53 +01:00
|
|
|
|
2019-04-05 09:54:43 +02:00
|
|
|
our $VERSION = '2.0.3';
|
2017-03-23 13:41:53 +01:00
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Portal::Main::Plugin';
|
|
|
|
|
|
|
|
# INITIALIZATION
|
|
|
|
|
2017-03-23 19:22:40 +01:00
|
|
|
has ott => (
|
|
|
|
is => 'rw',
|
2017-03-27 18:51:18 +02:00
|
|
|
lazy => 1,
|
2017-03-23 19:22:40 +01:00
|
|
|
default => sub {
|
|
|
|
my $ott =
|
|
|
|
$_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken');
|
|
|
|
$ott->timeout( $_[0]->{conf}->{formTimeout} );
|
|
|
|
return $ott;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2017-03-23 13:41:53 +01:00
|
|
|
sub init {
|
|
|
|
my ($self) = @_;
|
2017-03-23 19:22:40 +01:00
|
|
|
$self->addAuthRoute( upgradesession => 'ask', ['GET'] );
|
|
|
|
$self->addAuthRoute( upgradesession => 'confirm', ['POST'] );
|
2017-03-23 13:41:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# RUNNING METHOD
|
|
|
|
|
|
|
|
sub ask {
|
|
|
|
my ( $self, $req ) = @_;
|
2017-03-23 19:22:40 +01:00
|
|
|
|
|
|
|
# Check if auth is already running
|
|
|
|
if ( $req->param('upgrading') ) {
|
|
|
|
|
2017-03-23 13:41:53 +01:00
|
|
|
# verify token
|
|
|
|
return $self->confirm($req);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display form
|
2017-03-23 19:22:40 +01:00
|
|
|
return $self->p->sendHtml(
|
|
|
|
$req,
|
|
|
|
'upgradesession',
|
|
|
|
params => {
|
2017-03-23 21:49:52 +01:00
|
|
|
MSG => 'askToUpgrade',
|
2017-03-23 19:22:40 +01:00
|
|
|
CONFIRMKEY => $self->p->stamp,
|
|
|
|
PORTAL => $self->conf->{portal},
|
|
|
|
URL => $req->param('url'),
|
|
|
|
}
|
|
|
|
);
|
2017-03-23 13:41:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub confirm {
|
|
|
|
my ( $self, $req ) = @_;
|
2018-07-05 18:45:29 +02:00
|
|
|
$req->pdata->{keepPdata} = 1;
|
2017-03-23 19:22:40 +01:00
|
|
|
my $upg;
|
|
|
|
if ( my $t = $req->param('upgrading') ) {
|
|
|
|
if ( $self->ott->getToken($t) ) {
|
|
|
|
$upg = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $self->p->do( $req, [ sub { PE_TOKENEXPIRED } ] );
|
|
|
|
}
|
2017-03-23 13:41:53 +01:00
|
|
|
}
|
2017-03-27 18:51:18 +02:00
|
|
|
$req->steps( ['controlUrl'] );
|
2017-03-23 19:22:40 +01:00
|
|
|
my $res = $self->p->process($req);
|
2017-03-27 18:51:18 +02:00
|
|
|
return $self->p->do( $req, [ sub { $res } ] ) if ($res);
|
2017-03-23 19:22:40 +01:00
|
|
|
if ( $upg or $req->param('confirm') == 1 ) {
|
2018-07-05 22:56:16 +02:00
|
|
|
$req->data->{noerror} = 1;
|
2017-03-23 19:22:40 +01:00
|
|
|
$self->p->setHiddenFormValue(
|
|
|
|
$req,
|
|
|
|
upgrading => $self->ott->createToken,
|
2019-04-03 17:54:58 +02:00
|
|
|
'', 0
|
2017-03-23 19:22:40 +01:00
|
|
|
); # Insert token
|
2017-03-23 13:41:53 +01:00
|
|
|
return $self->p->login($req);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# Go to portal
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|