Clean code that manages templates parameters (#1634, #1631)

This commit is contained in:
Clément OUDOT 2019-01-31 15:38:58 +01:00
parent d7c252d554
commit 059d5320cb
4 changed files with 20 additions and 33 deletions

View File

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

View File

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

View File

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

View File

@ -522,10 +522,6 @@ sub display {
);
}
for my $env_key ( keys %{ $req->env } ) {
$templateParams{ "env_" . $env_key } = $req->env->{$env_key};
}
return ( 'register', \%templateParams );
}