diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Request.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Request.pm index 206f8ba06..b375ab524 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Request.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Request.pm @@ -22,6 +22,9 @@ has id => ( is => 'rw' ); has sessionInfo => ( is => 'rw' ); has user => ( is => 'rw' ); +# Persistent data (stored in cookie during auth, erased when auth is ready) +has pdata => ( is => 'rw' ); + # Response cookies (list of strings built by cookie()) has respCookies => ( is => 'rw' ); @@ -113,7 +116,7 @@ sub error_type { sub init { my ($self) = @_; - $self->{$_} = {} foreach (qw(datas customParameters sessionInfo)); + $self->{$_} = {} foreach (qw(datas customParameters sessionInfo pdata)); $self->{$_} = [] foreach (qw(respCookies)); } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm index a8e9c1ff7..14d59fe1b 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -31,9 +31,31 @@ sub sessionDatas { # - launch Lemonldap::NG::Common::PSGI::Request::handler() sub handler { my ( $self, $req ) = @_; + bless $req, 'Lemonldap::NG::Portal::Main::Request'; $req->init(); - return $self->Lemonldap::NG::Common::PSGI::Router::handler($req); + + # Restore pdata + if ( my $v = $req->cookies->{ $self->conf->{cookieName} . 'pdata' } ) { + eval { $req->pdata( JSON::from_json($v) ); }; + if ($@) { + $self->logger->error("Bad JSON content in cookie pdata"); + $req->pdata( {} ); + } + } + my $res = $self->Lemonldap::NG::Common::PSGI::Router::handler($req); + + # Save pdata + my %v = ( + name => $self->conf->{cookieName} . 'pdata', + ( + %{ $req->pdata } + ? ( value => JSON::to_json( $req->pdata ) ) + : ( value => '', expires => 'Wed, 21 Oct 2015 00:00:00 GMT' ) + ) + ); + push @{ $res->[1] }, 'Set-Cookie', $self->cookie(%v); + return $res; } # MAIN ENTRY POINTS (declared in Lemonldap::NG::Portal::Main::Init)