Check JSON structure (#1595)

This commit is contained in:
Christophe Maudoux 2019-02-21 16:25:02 +01:00
parent 9fafa1d8d5
commit b57a0788c2

View File

@ -15,6 +15,7 @@ package Lemonldap::NG::Portal::Main;
use strict; use strict;
use URI::Escape; use URI::Escape;
use JSON;
# List constants # List constants
sub authProcess {qw(extractFormInfo getUser authenticate)} sub authProcess {qw(extractFormInfo getUser authenticate)}
@ -729,17 +730,25 @@ sub sendHtml {
$troverJson = $args{templateDir} . "/$template.json"; $troverJson = $args{templateDir} . "/$template.json";
$self->logger->debug("-> Trying to load $tmpl"); $self->logger->debug("-> Trying to load $tmpl");
} }
if ( -r $troverJson ) { if ( -r $troverJson ) {
open my $tr_file, '<', $troverJson open my $tr_file, '<', $troverJson
or die "Can't open" or die "Can't open" . $troverJson . " : $!";
. $troverJson . " : $!";
while (<$tr_file>) { while (<$tr_file>) {
chomp; chomp;
$args{params}->{TROVERbyJSON} .= $_; $args{params}->{TROVERbyJSON} .= $_;
} }
close $tr_file or die "Can't close $tr_file : $!"; close $tr_file or die "Can't close $tr_file : $!";
$self->logger->debug(" -> Overriding messages with $troverJson"); eval { decode_json( $args{params}->{TROVERbyJSON} ) };
$self->logger->debug(" -> File content : $args{params}->{TROVERbyJSON}"); if ($@) {
$self->logger->debug("$troverJson is NOT a regular JSON file!!!");
$args{params}->{TROVERbyJSON} = '';
}
else {
$self->logger->debug(" -> Overriding messages with $troverJson");
$self->logger->debug(
" -> File content : $args{params}->{TROVERbyJSON}");
}
} }
my $res = $self->SUPER::sendHtml( $req, $template, %args ); my $res = $self->SUPER::sendHtml( $req, $template, %args );
push @{ $res->[1] }, push @{ $res->[1] },