From 059d5320cb4caecad56f0acc866116163c05d88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20OUDOT?= Date: Thu, 31 Jan 2019 15:38:58 +0100 Subject: [PATCH] Clean code that manages templates parameters (#1634, #1631) --- .../lib/Lemonldap/NG/Portal/Main/Display.pm | 12 --------- .../lib/Lemonldap/NG/Portal/Main/Run.pm | 26 ++++++++++++++----- .../NG/Portal/Plugins/MailPasswordReset.pm | 11 -------- .../Lemonldap/NG/Portal/Plugins/Register.pm | 4 --- 4 files changed, 20 insertions(+), 33 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm index 34e2074f6..3223a832a 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm @@ -418,18 +418,6 @@ sub display { } - # Additional $req param - %templateParams = ( %templateParams, %{ $req->{customParameters} // {} }, ); - - for my $session_key ( keys %{ $req->{sessionInfo} } ) { - $templateParams{ "session_" . $session_key } = - $req->{sessionInfo}->{$session_key}; - } - - for my $env_key ( keys %{ $req->env } ) { - $templateParams{ "env_" . $env_key } = $req->env->{$env_key}; - } - $self->logger->debug("Skin returned: $skinfile"); return ( $skinfile, \%templateParams ); } 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 f27c18f7e..1dacfd618 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -843,16 +843,30 @@ sub rebuildCookies { } sub tplParams { - my $portalPath = $_[0]->conf->{portal}; + my ( $self, $req ) = @_; + my %templateParams; + + my $portalPath = $self->conf->{portal}; $portalPath =~ s#^https?://[^/]+/?#/#; $portalPath =~ s#[^/]+\.fcgi$##; + + for my $session_key ( keys %{ $req->{sessionInfo} } ) { + $templateParams{ "session_" . $session_key } = + $req->{sessionInfo}->{$session_key}; + } + + for my $env_key ( keys %{ $req->env } ) { + $templateParams{ "env_" . $env_key } = $req->env->{$env_key}; + } + return ( - SKIN => $_[0]->getSkin( $_[1] ), - PORTAL_URL => $_[0]->conf->{portal}, + SKIN => $self->getSkin( $req ), + PORTAL_URL => $self->conf->{portal}, SKIN_PATH => $portalPath . "skins", - ANTIFRAME => $_[0]->conf->{portalAntiFrame}, - SKIN_BG => $_[0]->conf->{portalSkinBackground}, - ( $_[0]->customParameters ? ( %{ $_[0]->customParameters } ) : () ), + ANTIFRAME => $self->conf->{portalAntiFrame}, + SKIN_BG => $self->conf->{portalSkinBackground}, + ( $self->customParameters ? ( %{ $self->customParameters } ) : () ), + %templateParams ); } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/MailPasswordReset.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/MailPasswordReset.pm index 6217a7337..519832639 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/MailPasswordReset.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/MailPasswordReset.pm @@ -594,17 +594,6 @@ sub display { $tplPrm{DISPLAY_PASSWORD_FORM} = $req->sessionInfo->{pwdAllowed}; } - # Custom template parameters - if ( my $customParams = $self->p->customParameters ) { - foreach ( keys %$customParams ) { - $tplPrm{$_} = $customParams->{$_}; - } - } - - for my $env_key ( keys %{ $req->env } ) { - $tplPrm{ "env_" . $env_key } = $req->env->{$env_key}; - } - return 'mail', \%tplPrm; } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Register.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Register.pm index 51e3b90c8..f782cc057 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Register.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Register.pm @@ -522,10 +522,6 @@ sub display { ); } - for my $env_key ( keys %{ $req->env } ) { - $templateParams{ "env_" . $env_key } = $req->env->{$env_key}; - } - return ( 'register', \%templateParams ); }