Move some HTML fragments to templates (#1302)

This commit is contained in:
Xavier Guimard 2017-10-10 11:04:40 +00:00
parent 76769f8166
commit 46364da414
22 changed files with 216 additions and 102 deletions

View File

@ -255,6 +255,7 @@ site/htdocs/static/languages/nl.json
site/htdocs/static/languages/pt.json
site/htdocs/static/languages/ro.json
site/htdocs/static/languages/vi.json
site/templates/bootstrap/casBack2Url.tpl
site/templates/bootstrap/checklogins.tpl
site/templates/bootstrap/confirm.tpl
site/templates/bootstrap/customfooter.tpl
@ -265,16 +266,24 @@ site/templates/bootstrap/ext2fcheck.tpl
site/templates/bootstrap/footer.tpl
site/templates/bootstrap/header.tpl
site/templates/bootstrap/info.tpl
site/templates/bootstrap/ldapPpGrace.tpl
site/templates/bootstrap/login.tpl
site/templates/bootstrap/mail.tpl
site/templates/bootstrap/menu.tpl
site/templates/bootstrap/noHistory.tpl
site/templates/bootstrap/notification.tpl
site/templates/bootstrap/oidcConsents.tpl
site/templates/bootstrap/openid.tpl
site/templates/bootstrap/openidform.tpl
site/templates/bootstrap/password.tpl
site/templates/bootstrap/public/test.tpl
site/templates/bootstrap/pwdWillExpire.tpl
site/templates/bootstrap/redirect.tpl
site/templates/bootstrap/register.tpl
site/templates/bootstrap/removeOther.tpl
site/templates/bootstrap/samlRedirectToIdp.tpl
site/templates/bootstrap/sessionArray.tpl
site/templates/bootstrap/simpleInfo.tpl
site/templates/bootstrap/sslform.tpl
site/templates/bootstrap/standardform.tpl
site/templates/bootstrap/u2fcheck.tpl

View File

@ -112,14 +112,20 @@ sub authenticate {
# calculating remaining time before password expiration
my $remainingTime = $_pwdExpire - $timestamp;
$req->info(
'<h3 trspan="pwdWillExpire,'
. join(
',',
$self->ldap->convertSec(
substr( $remainingTime, 0, length($remainingTime) - 7 )
)
)
. '"></h3>'
$self->loadTemplate(
'pwdWillExpire',
params => {
time => join(
',',
$self->ldap->convertSec(
substr(
$remainingTime, 0,
length($remainingTime) - 7
)
)
)
}
)
);
}

View File

@ -853,21 +853,16 @@ sub extractFormInfo {
return $urlcheck unless ( $urlcheck == PE_OK );
# Choosen IDP
my $html =
'<h3 trspan="redirectionToIdp">Redirection to your Identity Provider</h3><h4>'
. $self->idpList->{$idp}->{name}
. "</h4>\n"
. "<p><i>"
. $idp
. "</i></p>\n"
. (
$req->param("url")
? "<input type=\"hidden\" name=\"url\" value=\""
. $req->param("url") . "\" />"
: ''
) . "<input type=\"hidden\" name=\"idp\" value=\"$idp\" />\n";
$req->info($html);
$req->info(
$self->loadTemplate(
'samlRedirectToIdp',
params => {
name => $self->idpList->{$idp}->{name},
idp => $idp,
( $req->param("url") ? ( url => $req->param("url") ) : () ),
}
)
);
$req->datas->{login} = 1;
return PE_CONFIRM;

View File

@ -231,9 +231,10 @@ sub run {
"Logout URL $logout_url will be displayed");
$req->info(
'<h3 trmsg="back2CasUrl">The application you just logged out of has provided a link it would like you to follow</h3>'
$self->loadTemplate(
'casBack2Url', params => { url => $logout_url }
)
);
$req->info("<p><a href=\"$logout_url\">$logout_url</a></p>");
$req->datas->{activeTimer} = 0;
return PE_CONFIRM;

View File

@ -209,7 +209,12 @@ sub _openIDResponse {
{
# TODO
$req->info('<h3 trspan="openidExchange,$data->{trust_root}"></h3>');
$req->info(
$self->loadTemplate(
'simpleInfo',
params => { trspan => "openidExchange,$data->{trust_root}" }
)
);
$req->info( $req->datas->{_openIdTrustExtMsg} )
if ( $req->datas->{_openIdTrustExtMsg} );
$self->logger->debug('OpenID confirmation');

View File

@ -857,8 +857,10 @@ sub run {
. ' width="0" height="0" frameborder="0"></iframe>';
$req->info(
'<h3 trspan="updateCdc">Update Common Domain Cookie</h3>'
. $cdc_iframe );
$self->loadTemplate( 'simpleInfo',
params => { trspan => 'updateCdc' } )
. $cdc_iframe
);
}
# HTTP-POST

View File

@ -206,16 +206,28 @@ sub userBind {
if ( $resp->grace_authentications_remaining ) {
# TODO
$req->info( '<h3>'
. $resp->grace_authentications_remaining
. ' <span trmsg="ppGrace">authentications remaining, change your password!</span></h3>'
$self->info(
$self->loadTemplate(
'ldapPpGrace',
params => {
number => $resp->grace_authentications_remaining
}
)
);
}
if ( $resp->time_before_expiration ) {
$req->info( '<h3 trspan="authRemaining,'
. $self->convertSec( $resp->time_before_expiration )
. '"></h3>' );
$req->info(
$self->loadTemplate(
'simpleInfo',
params => {
trspan => 'authRemaining,'
. $self->convertSec(
$resp->time_before_expiration
)
}
)
);
}
return PE_OK;

View File

@ -437,49 +437,45 @@ sub mkSessionArray {
return "" unless ( ref $sessions eq "ARRAY" and @$sessions );
my $tmp = $title ? qq'<h3 trspan="$title">$title</h3>' : '';
$tmp .=
'<table class="info"><tbody><tr>'
. ( $displayUser ? '<th trspan="user">User</th>' : '' )
. '<th trspan="date">Date</th><th trspan="ipAddr">IP address</th>';
$tmp .= "<th>" . $self->conf->{sessionDataToRemember}->{$_} . "</th>"
foreach ( keys %{ $self->conf->{sessionDataToRemember} } );
$tmp .= '<th trspan="errorMsg">Error message</th>'
if ($displayError);
$tmp .= '</tr>';
foreach my $session (@$sessions) {
$tmp .= "<tr>"
. ( $displayUser ? "<td>$session->{user}</td>" : '' )
. qq'<td class="localeDate" val="$session->{_utime}"></td>'
. "<td>$session->{ipAddr}</td>";
$tmp .= "<td>" . ( $session->{$_} || "" ) . "</td>"
foreach ( keys %{ $self->conf->{sessionDataToRemember} } );
$tmp .= "<td>$session->{error}</td>" if ($displayError);
$tmp .= "</tr>";
}
$tmp .= '</tbody></table>';
return $tmp;
my @fields = sort keys %{ $self->conf->{sessionDataToRemember} };
return $self->loadTemplate(
'sessionArray',
params => {
title => $title,
displayUser => $displayUser,
displayError => $displayError,
fields => [
map { { name => $self->conf->{sessionDataToRemember}->{$_} } }
@fields
],
sessions => [
map {
my $session = $_;
{
user => $session->{user},
utime => $session->{_utime},
ip => $session->{ipAddr},
values => [ map { { v => $session->{$_} } } @fields ],
error => $session->{error},
}
} @$sessions
],
}
);
}
sub mkOidcConsent {
my ( $self, $session ) = @_;
my $tmp .=
'<table class="info"><thead><tr><th trspan="service"></th></tr></thead>'
. '<tbody><tr>';
# TODO: add JS to remove consent
if ( $session->{_oidcConnectedRP} ) {
$tmp .=
qq'<tr partner="$_"><td>$_ <a partner="$_" class="oidcConsent link text-danger glyphicon glyphicon-minus-sign"></a></td></tr>'
foreach ( split /,/, $session->{_oidcConnectedRP} );
$tmp .= qq'</tbody></table><script type="application/init">
{
"oidcConsents":"$session->{_oidcConnectedRP}"
}
</script>';
}
return $tmp;
return $self->loadTemplate(
'oidcConsents',
params => {
partners => [
map { { name => $_ } }
( split /,/, $session->{_oidcConnectedRP} )
],
consents => $session->{_oidcConnectedRP},
}
);
}
1;

View File

@ -52,28 +52,8 @@ sub _addRoute {
}
sub loadTemplate {
my ( $self, $name, %prm ) = @_;
$name .= '.tpl';
my $file =
$self->conf->{templateDir} . '/'
. $self->conf->{portalSkin} . '/'
. $name;
$file = $self->conf->{templateDir} . '/common/' . $name unless ( -e $file );
unless ( -e $file ) {
die "Unable to find $name in $self->conf->{templateDir}";
}
my $tpl = HTML::Template->new(
filename => $file,
die_on_bad_params => 0,
die_on_missing_include => 1,
cache => 1,
global_vars => 0,
($prm{filter} ? (filter => $prm{filter}) : () ),
);
if ( $prm{params} ) {
$tpl->param( %{ $prm{params} } );
}
return $tpl->output;
my $self = shift;
return $self->p->loadTemplate(@_);
}
1;

View File

@ -172,7 +172,11 @@ sub deleteSession {
$self->logger->debug("Create iFrames to forward logout to services");
$req->info('<h3 trmsg="logoutFromOtherApp"></h3>');
$req->info(
$self->loadTemplate(
'simpleInfo', params => { trspan => 'logoutFromOtherApp' }
)
);
foreach ( keys %{ $req->datas->{logoutServices} } ) {
my $logoutServiceName = $_;

View File

@ -133,7 +133,9 @@ sub refresh {
my $res = $req->error( $self->process($req) );
if ($res) {
$req->info(
'<h3 trspan="rightsReloadNeedsLogout">Rights reloads need to logout and login again</h3>'
$self->loadTemplate(
'simpleInfo', params => { trspan => 'rightsReloadNeedsLogout' }
)
);
$req->urldc( $self->conf->{portal} );
return $self->do( $req, [ sub { PE_INFO } ] );
@ -827,4 +829,30 @@ sub _sumUpSession {
return $res;
}
# Temlate loader
sub loadTemplate {
my ( $self, $name, %prm ) = @_;
$name .= '.tpl';
my $file =
$self->conf->{templateDir} . '/'
. $self->conf->{portalSkin} . '/'
. $name;
$file = $self->conf->{templateDir} . '/common/' . $name unless ( -e $file );
unless ( -e $file ) {
die "Unable to find $name in $self->conf->{templateDir}";
}
my $tpl = HTML::Template->new(
filename => $file,
die_on_bad_params => 0,
die_on_missing_include => 1,
cache => 1,
global_vars => 0,
( $prm{filter} ? ( filter => $prm{filter} ) : () ),
);
if ( $prm{params} ) {
$tpl->param( %{ $prm{params} } );
}
return $tpl->output;
}
1;

View File

@ -38,7 +38,7 @@ sub run {
)
);
unless ( $req->info ) {
$req->info('<p trspan="noHistory"></p>');
$req->info( $self->loadTemplate('noHistory') );
}
return PE_INFO;
}

View File

@ -72,11 +72,13 @@ sub run {
sub _mkRemoveOtherLink {
my $self = shift;
my $link = $self->conf->{portal} . "?removeOther=1";
# TODO: remove this
return
qq'<p class="removeOther"><a href="$link" onclick="_go=0" trspan="removeOtherSessions></a></p>';
return $self->loadTemplate(
'removeOther',
params => {
link => $self->conf->{portal} . "?removeOther=1"
}
);
}
1;

View File

@ -0,0 +1,2 @@
<h3 trmsg="back2CasUrl">The application you just logged out of has provided a link it would like you to follow</h3>
<p><a href="<TMPL_VAR NAME="url">"><TMPL_VAR NAME="url"></a></p>

View File

@ -0,0 +1 @@
<h3><TMPL_VAR NAME="number"> <span trmsg="ppGrace">authentications remaining, change your password!</span></h3>

View File

@ -0,0 +1 @@
<p trspan="noHistory"></p>

View File

@ -0,0 +1,21 @@
<table class="info">
<thead>
<tr>
<th trspan="service"></th>
</tr>
</thead>
<tbody>
<TMPL_LOOP NAME="partners">
<tr partner="<TMPL_VAR NAME="name">">
<td><TMPL_VAR NAME="name">
<a partner="<TMPL_VAR NAME="name">" class="oidcConsent link text-danger glyphicon glyphicon-minus-sign"></a>
</td>
</tr>
</TMPL_LOOP>
</tbody>
</table>
<script type="application/init">
{
"oidcConsents":"<TMPL_VAR NAME="consents">"
}
</script>

View File

@ -0,0 +1 @@
<h3 trspan="pwdWillExpire,<TMPL_VAR NAME="time">"></h3>

View File

@ -0,0 +1,3 @@
<p class="removeOther">
<a href="<TMPL_VAR NAME="link">" onclick="_go=0" trspan="removeOtherSessions></a>
</p>

View File

@ -0,0 +1,7 @@
<h3 trspan="redirectionToIdp">Redirection to your Identity Provider</h3>
<h4><TMPL_VAR NAME="name"></h4>
<p><i><TMPL_VAR NAME="idp"></i></p>
<TMPL_IF NAME="url">
<input type="hidden" name="url" value="<TMPL_VAR NAME="url">" />
</TMPL_IF>
<input type="hidden" name="idp" value="<TMPL_VAR NAME="idp">" />

View File

@ -0,0 +1,37 @@
<TMPL_IF NAME="title">
<h3 trspan="<TMPL_VAR NAME="title">">
</TMPL_IF>
<table class="info">
<thead>
<tr>
<TMPL_IF NAME="displayUser">
<th trspan="user">User</th>
</TMPL_IF>
<th trspan="date">Date</th>
<th trspan="ipAddr">IP address</th>
<TMPL_LOOP NAME="fields">
<th><TMPL_VAR NAME="name"></th>
</TMPL_LOOP>
<TMPL_IF NAME="displayError">
<th trspan="errorMsg">Error message</th>
</TMPL_IF>
</tr>
</thead>
<tbody>
<TMPL_LOOP NAME="sessions">
<tr>
<TMPL_IF NAME="displayUser">
<td><TMPL_VAR NAME="user"></td>
</TMPL_IF>
<td class="localeDate" val="<TMPL_VAR NAME="utime">"></td>
<td><TMPL_VAR NAME="ip"></td>
<TMPL_LOOP NAME="values">
<td><TMPL_VAR NAME="v"></td>
</TMPL_LOOP>
<TMPL_IF NAME="displayError">
<td><TMPL_VAR NAME="error"></td>
</TMPL_IF>
</tr>
</TMPL_LOOP>
</tbody>
</table>

View File

@ -0,0 +1 @@
<h3 trspan="<TMPL_VAR NAME="trspan">"><TMPL_VAR NAME="trspan"></h3>