Prepare cookie storage for #1461

This commit is contained in:
Xavier Guimard 2018-07-04 13:33:20 +02:00
parent 60d05c48a5
commit 8de024ddb6
2 changed files with 27 additions and 2 deletions

View File

@ -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));
}

View File

@ -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)