From c921c295edae2625ab55c1dc3cf8712c72fa37f4 Mon Sep 17 00:00:00 2001 From: Xavier Date: Fri, 28 Jun 2019 13:40:56 +0200 Subject: [PATCH] Use user skin in loadTemplate (Fixes: #1828) --- .../lib/Lemonldap/NG/Portal/2F/Mail2F.pm | 1 + .../lib/Lemonldap/NG/Portal/Auth/AD.pm | 1 + .../lib/Lemonldap/NG/Portal/Issuer/CAS.pm | 3 ++- .../lib/Lemonldap/NG/Portal/Issuer/OpenID.pm | 1 + .../lib/Lemonldap/NG/Portal/Issuer/OpenIDConnect.pm | 3 ++- .../lib/Lemonldap/NG/Portal/Issuer/SAML.pm | 6 ++++-- .../lib/Lemonldap/NG/Portal/Lib/Net/LDAP.pm | 2 ++ .../lib/Lemonldap/NG/Portal/Lib/Notifications/JSON.pm | 6 +++--- .../lib/Lemonldap/NG/Portal/Lib/OpenID/SREG.pm | 5 ++++- .../lib/Lemonldap/NG/Portal/Lib/SAML.pm | 5 ++++- .../lib/Lemonldap/NG/Portal/Main/Display.pm | 6 ++++-- .../lib/Lemonldap/NG/Portal/Main/Menu.pm | 6 +++--- .../lib/Lemonldap/NG/Portal/Main/Plugin.pm | 9 ++------- .../lib/Lemonldap/NG/Portal/Main/Process.pm | 5 +++-- .../lib/Lemonldap/NG/Portal/Main/Run.pm | 5 +++-- .../lib/Lemonldap/NG/Portal/Plugins/GrantSession.pm | 2 +- .../lib/Lemonldap/NG/Portal/Plugins/History.pm | 6 +++--- .../Lemonldap/NG/Portal/Plugins/MailPasswordReset.pm | 2 ++ .../lib/Lemonldap/NG/Portal/Plugins/Register.pm | 2 ++ .../lib/Lemonldap/NG/Portal/Plugins/SingleSession.pm | 11 +++++++---- 20 files changed, 54 insertions(+), 33 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Mail2F.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Mail2F.pm index 2c4c6da80..f94222cf2 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Mail2F.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/2F/Mail2F.pm @@ -86,6 +86,7 @@ sub run { # Use HTML template $body = $self->loadTemplate( + $req, 'mail_2fcode', filter => $tr, params => \%tplPrms diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/AD.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/AD.pm index 2a2ae8fbb..32ca65609 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/AD.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/AD.pm @@ -114,6 +114,7 @@ sub authenticate { my $remainingTime = $_pwdExpire - $timestamp; $req->info( $self->loadTemplate( + $req, 'pwdWillExpire', params => { time => join( diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/CAS.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/CAS.pm index b6ea7cfa8..51a0631f0 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/CAS.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/CAS.pm @@ -308,7 +308,8 @@ sub run { $req->info( $self->loadTemplate( - 'casBack2Url', params => { url => $logout_url } + $req, 'casBack2Url', + params => { url => $logout_url } ) ); $req->data->{activeTimer} = 0; diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/OpenID.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/OpenID.pm index 4a2e57ad6..40bc83a3c 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/OpenID.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/OpenID.pm @@ -231,6 +231,7 @@ sub _openIDResponse { # TODO $req->info( $self->loadTemplate( + $req, 'simpleInfo', params => { trspan => "openidExchange,$data->{trust_root}" } ) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/OpenIDConnect.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/OpenIDConnect.pm index f8934f6ac..835f7905e 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/OpenIDConnect.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/OpenIDConnect.pm @@ -556,6 +556,7 @@ sub run { } $req->info( $self->loadTemplate( + $req, 'oidcGiveConsent', params => { displayName => $display_name, @@ -947,7 +948,7 @@ sub run { : PE_OK; } - $req->info( $self->loadTemplate('oidcLogout') ); + $req->info( $self->loadTemplate( $req, 'oidcLogout' ) ); $req->data->{activeTimer} = 0; return PE_CONFIRM; } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/SAML.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/SAML.pm index dc8b84703..e3231fb9b 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/SAML.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Issuer/SAML.pm @@ -917,8 +917,10 @@ sub run { . ' width="0" height="0" frameborder="0">'; $req->info( - $self->loadTemplate( 'simpleInfo', - params => { trspan => 'updateCdc' } ) + $self->loadTemplate( + $req, 'simpleInfo', + params => { trspan => 'updateCdc' } + ) . $cdc_iframe ); } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Net/LDAP.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Net/LDAP.pm index 484934d56..2897150fa 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Net/LDAP.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Net/LDAP.pm @@ -209,6 +209,7 @@ sub userBind { if ( $resp->grace_authentications_remaining ) { $req->info( $self->{portal}->loadTemplate( + $req, 'ldapPpGrace', params => { number => $resp->grace_authentications_remaining @@ -220,6 +221,7 @@ sub userBind { if ( $resp->time_before_expiration ) { $req->info( $self->{portal}->loadTemplate( + $req, 'simpleInfo', params => { trspan => 'authRemaining,' diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Notifications/JSON.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Notifications/JSON.pm index a5c4c69d8..6bce55c6b 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Notifications/JSON.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/Notifications/JSON.pm @@ -62,7 +62,7 @@ sub checkForNotifications { # Go to next file if no notification found next unless $j; $i++; - $form .= $self->toForm(@res); + $form .= $self->toForm( $req, @res ); } # Stop here if nothing to display @@ -192,7 +192,7 @@ sub getNotifBack { } sub toForm { - my ( $self, @notifs ) = @_; + my ( $self, $req, @notifs ) = @_; my $i = 0; @notifs = map { $i++; @@ -205,7 +205,7 @@ sub toForm { $_->{id} = "1x$i"; $_; } @notifs; - return $self->loadTemplate( 'notifinclude', + return $self->loadTemplate( $req, 'notifinclude', params => { notifications => \@notifs } ); } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/OpenID/SREG.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/OpenID/SREG.pm index 82ef247fe..7f1a0f387 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/OpenID/SREG.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/OpenID/SREG.pm @@ -73,6 +73,7 @@ sub sregHook { } } $req->data->{_openIdTrustExtMsg} .= $self->loadTemplate( + $req, 'openIdPol', params => { policies => \@pol, @@ -96,7 +97,8 @@ sub sregHook { $req->info( $self->loadTemplate( - 'simpleInfo', params => { trspan => "openidRpns,$k" } + $req, 'simpleInfo', + params => { trspan => "openidRpns,$k" } ) ); return ( 0, {} ); @@ -198,6 +200,7 @@ sub sregHook { } $req->data->{_openIdTrustExtMsg} .= $self->loadTemplate( + $req, 'openIdTrust', params => { required => \@mreq, diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SAML.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SAML.pm index d4f89ef90..d7542afa2 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SAML.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SAML.pm @@ -2547,6 +2547,7 @@ sub sendLogoutRequestToProvider { # Create iFrame $info .= $self->loadTemplate( + $req, 'samlSpLogout', params => { url => $slo_url, @@ -2582,6 +2583,7 @@ sub sendLogoutRequestToProvider { # Create iFrame $info .= $self->loadTemplate( + $req, 'samlSpLogout', params => { url => $slo_url, @@ -2620,6 +2622,7 @@ sub sendLogoutRequestToProvider { # Display information to the user $info .= $self->loadTemplate( + $req, 'samlSpSoapLogout', params => { imgUrl => $slo_url, @@ -2718,7 +2721,7 @@ sub sendLogoutRequestToProviders { # Print some information to the user. $req->info( $self->loadTemplate( - 'samlSpsLogout', params => { content => $content } + $req, 'samlSpsLogout', params => { content => $content } ) ) if $providersCount; 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 9a0c2ab77..20e1bc5cb 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Display.pm @@ -527,12 +527,13 @@ sub getSkin { # @param $displaError To display "Error" column # @return HTML string sub mkSessionArray { - my ( $self, $sessions, $title, $displayUser, $displayError ) = @_; + my ( $self, $req, $sessions, $title, $displayUser, $displayError ) = @_; return "" unless ( ref $sessions eq "ARRAY" and @$sessions ); my @fields = sort keys %{ $self->conf->{sessionDataToRemember} }; return $self->loadTemplate( + $req, 'sessionArray', params => { title => $title, @@ -560,7 +561,7 @@ sub mkSessionArray { } sub mkOidcConsent { - my ( $self, $session ) = @_; + my ( $self, $req, $session ) = @_; if ( defined( $self->conf->{oidcRPMetaDataOptions} ) and ref( $self->conf->{oidcRPMetaDataOptions} ) ) @@ -603,6 +604,7 @@ sub mkOidcConsent { # Display existing oidcConsents return $self->loadTemplate( + $req, 'oidcConsents', params => { partners => [ diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm index 6210b881a..8481e8d4b 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Menu.pm @@ -136,17 +136,17 @@ sub displayModules { } elsif ( $module->[0] eq 'LoginHistory' ) { $moduleHash->{'SUCCESS_LOGIN'} = - $self->p->mkSessionArray( + $self->p->mkSessionArray( $req, $req->{sessionInfo}->{_loginHistory}->{successLogin}, "", 0, 0 ); $moduleHash->{'FAILED_LOGIN'} = - $self->p->mkSessionArray( + $self->p->mkSessionArray( $req, $req->{sessionInfo}->{_loginHistory}->{failedLogin}, "", 0, 1 ); } elsif ( $module->[0] eq 'OidcConsents' ) { $moduleHash->{'OIDC_CONSENTS'} = - $self->p->mkOidcConsent( $req->sessionInfo ); + $self->p->mkOidcConsent( $req, $req->sessionInfo ); } push @$displayModules, $moduleHash; } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Plugin.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Plugin.pm index f511a2d4d..d1d7c30b8 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Plugin.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Plugin.pm @@ -69,11 +69,7 @@ sub loadTemplate { sub displayTemplate { my ( $self, $req, $template, $params ) = @_; $self->logger->debug("Return $template template"); - $req->info( - $self->loadTemplate( - $template, params => $params - ) - ); + $req->info( $self->loadTemplate( $req, $template, params => $params ) ); return PE_INFO; } @@ -95,8 +91,7 @@ sub createNotification { $content =~ s/_title_/$title/; $content =~ s/_msg_/$msg/; - if ( $notifEngine->module->notifObject->newNotification($content) ) - { + if ( $notifEngine->module->notifObject->newNotification($content) ) { $self->logger->debug("Notification $ref successfully created"); $self->userLogger->notice( "Notification $ref / $date successfully created for $uid"); diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm index f7bb88a63..935a4235f 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Process.pm @@ -160,7 +160,7 @@ sub authLogout { sub deleteSession { my ( $self, $req ) = @_; if ( my $id = $req->id || $req->userData->{_session_id} ) { - my $apacheSession = $self->getApacheSession( $id ); + my $apacheSession = $self->getApacheSession($id); unless ($apacheSession) { $self->logger->debug("Session $id already deleted"); return PE_OK; @@ -183,7 +183,8 @@ sub deleteSession { $req->info( $self->loadTemplate( - 'simpleInfo', params => { trspan => 'logoutFromOtherApp' } + $req, 'simpleInfo', + params => { trspan => 'logoutFromOtherApp' } ) ); 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 1c86f572b..6dad78dfb 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -176,6 +176,7 @@ sub refresh { if ($res) { $req->info( $self->loadTemplate( + $req, 'simpleInfo', params => { trspan => 'rightsReloadNeedsLogout' } ) ); @@ -1023,12 +1024,12 @@ sub _sumUpSession { # Temlate loader sub loadTemplate { - my ( $self, $name, %prm ) = @_; + my ( $self, $req, $name, %prm ) = @_; $name .= '.tpl'; my $tpl = HTML::Template->new( filename => $name, path => [ - $self->conf->{templateDir} . '/' . $self->conf->{portalSkin}, + $self->conf->{templateDir} . '/' . $self->getSkin($req), $self->conf->{templateDir} . '/bootstrap/', $self->conf->{templateDir} . '/common/' ], diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/GrantSession.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/GrantSession.pm index 9fe3c24dd..b14f58c64 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/GrantSession.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/GrantSession.pm @@ -73,7 +73,7 @@ sub run { $self->logger->debug("Transformed message -> $msg"); $req->info( $self->loadTemplate( - 'simpleInfo', params => { trspan => $msg } + $req, 'simpleInfo', params => { trspan => $msg } ) ); $self->userLogger->error( 'User ' diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/History.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/History.pm index 293dc7b40..330031611 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/History.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/History.pm @@ -23,7 +23,7 @@ sub run { $self->logger->debug('History asked'); $req->info( ( $req->sessionInfo->{_loginHistory}->{successLogin} - ? $self->p->mkSessionArray( + ? $self->p->mkSessionArray( $req, $req->sessionInfo->{_loginHistory}->{successLogin}, 'lastLogins', 0, 0 ) : "" @@ -31,14 +31,14 @@ sub run { . ("
") . ( $req->sessionInfo->{_loginHistory}->{failedLogin} - ? $self->p->mkSessionArray( + ? $self->p->mkSessionArray( $req, $req->sessionInfo->{_loginHistory}->{failedLogin}, 'lastFailedLogins', 0, 1 ) : "" ) ); unless ( $req->info ) { - $req->info( $self->loadTemplate('noHistory') ); + $req->info( $self->loadTemplate( $req, 'noHistory' ) ); } return PE_INFO; } 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 9d37067da..7bb690136 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/MailPasswordReset.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/MailPasswordReset.pm @@ -335,6 +335,7 @@ sub _reset { # Use HTML template $body = $self->loadTemplate( + $req, 'mail_confirm', filter => $tr, params => \%tplPrms @@ -473,6 +474,7 @@ sub changePwd { # Use HTML template $body = $self->loadTemplate( + $req, 'mail_password', filter => $tr, params => \%tplPrms 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 e4ee5165a..024a811dd 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Register.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Register.pm @@ -310,6 +310,7 @@ sub _register { # Use HTML template $body = $self->loadTemplate( + $req, 'mail_register_confirm', filter => $tr, params => \%tplPrms @@ -369,6 +370,7 @@ sub _register { # Use HTML template $body = $self->loadTemplate( + $req, 'mail_register_done', filter => $tr, params => \%tplPrms diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/SingleSession.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/SingleSession.pm index 18b91794b..6d0a1d9df 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/SingleSession.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/SingleSession.pm @@ -69,10 +69,12 @@ sub run { } } } - $req->info( $self->p->mkSessionArray( $deleted, 'sessionsDeleted', 1 ) ) + $req->info( + $self->p->mkSessionArray( $req, $deleted, 'sessionsDeleted', 1 ) ) if ( $self->conf->{notifyDeleted} and @$deleted ); - $req->info( $self->p->mkSessionArray( $otherSessions, 'otherSessions', 1 ) - . $self->_mkRemoveOtherLink() ) + $req->info( + $self->p->mkSessionArray( $req, $otherSessions, 'otherSessions', 1 ) + . $self->_mkRemoveOtherLink($req) ) if ( $self->conf->{notifyOther} and @$otherSessions ); PE_OK; @@ -82,10 +84,11 @@ sub run { # Last part of URL is built trough javascript # @return removeOther link in HTML code sub _mkRemoveOtherLink { - my $self = shift; + my ( $self, $req ) = @_; # TODO: remove this return $self->loadTemplate( + $req, 'removeOther', params => { link => $self->conf->{portal} . "?removeOther=1"