Skip to content
Snippets Groups Projects
Commit 8c743676 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

don't depend on input paramer to select template

parent 7b5cb8e3
No related branches found
No related tags found
No related merge requests found
...@@ -93,7 +93,12 @@ sub run { ...@@ -93,7 +93,12 @@ sub run {
$self->{logger}->error( $self->{logger}->error(
"Incorrect parameter format : $parameter" "Incorrect parameter format : $parameter"
); );
$self->respond({ errors => [ "format_$parameter" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "format_$parameter" ]
}
);
} }
} }
...@@ -105,7 +110,6 @@ sub run { ...@@ -105,7 +110,6 @@ sub run {
# register needed parameters # register needed parameters
$self->{in} = { $self->{in} = {
email => $parameters{email}, email => $parameters{email},
style => $parameters{style},
entityid => $parameters{entityid}, entityid => $parameters{entityid},
token => $parameters{token}, token => $parameters{token},
key => $parameters{key}, key => $parameters{key},
...@@ -120,7 +124,12 @@ sub run { ...@@ -120,7 +124,12 @@ sub run {
} else { } else {
## unknown action ## unknown action
$self->{logger}->error( "Unknown action '$action'"); $self->{logger}->error( "Unknown action '$action'");
$self->respond({ errors => [ "Unknown action '$action'" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "Unknown action '$action'" ]
}
);
} }
return 1; return 1;
...@@ -128,9 +137,9 @@ sub run { ...@@ -128,9 +137,9 @@ sub run {
## Return HTML content ## Return HTML content
sub respond { sub respond {
my ($self, $data) = @_; my ($self, %in) = @_;
$data->{app} = { $in{data}->{app} = {
name => $self->{configuration}->{app}->{name}, name => $self->{configuration}->{app}->{name},
url => $self->{configuration}->{app}->{url}, url => $self->{configuration}->{app}->{url},
support_email => $self->{configuration}->{app}->{support_email}, support_email => $self->{configuration}->{app}->{support_email},
...@@ -147,13 +156,6 @@ sub respond { ...@@ -147,13 +156,6 @@ sub respond {
my $template; my $template;
## nobanner is used to do AJAX to get only pieces of HTML to load in the web client
if ($self->{in}->{style} && $self->{in}->{style} eq 'nobanner') {
$template = 'index-nobanner.tt2.html';
} else {
$template = 'index.tt2.html';
}
binmode(STDOUT, ":utf8"); binmode(STDOUT, ":utf8");
print $self->{cgi}->header( print $self->{cgi}->header(
...@@ -161,7 +163,7 @@ sub respond { ...@@ -161,7 +163,7 @@ sub respond {
-charset => 'utf8' -charset => 'utf8'
); );
unless ($tt2->process($template, $data, \*STDOUT)) { unless ($tt2->process($in{template}, $in{data}, \*STDOUT)) {
printf "Content-type: text/plain\n\n Error: %s", $tt2->error(); printf "Content-type: text/plain\n\n Error: %s", $tt2->error();
$self->{logger}->errorf("Web parser error : %s", $tt2->error()); $self->{logger}->errorf("Web parser error : %s", $tt2->error());
} }
...@@ -180,16 +182,24 @@ sub req_select_sp { ...@@ -180,16 +182,24 @@ sub req_select_sp {
}; };
if ($EVAL_ERROR) { if ($EVAL_ERROR) {
$self->{logger}->error("Failed to load federation metadata: $EVAL_ERROR"); $self->{logger}->error("Failed to load federation metadata: $EVAL_ERROR");
$self->respond({ errors => [ "internal" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "internal" ]
}
);
} }
$self->respond({ $self->respond(
env => { template => 'index.tt2.html',
SCRIPT_NAME => $ENV{SCRIPT_NAME} data => {
}, env => {
metadata => $metadata->parse(type => 'sp'), SCRIPT_NAME => $ENV{SCRIPT_NAME}
action => 'select_sp' },
}); metadata => $metadata->parse(type => 'sp'),
action => 'select_sp'
}
);
} }
sub req_select_email { sub req_select_email {
...@@ -197,7 +207,12 @@ sub req_select_email { ...@@ -197,7 +207,12 @@ sub req_select_email {
unless ($self->{in}->{entityid}) { unless ($self->{in}->{entityid}) {
$self->{logger}->error("Missing parameter entityid"); $self->{logger}->error("Missing parameter entityid");
$self->respond({ errors => [ "missing_entityid" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "missing_entityid" ]
}
);
} }
# Create a persistent service provider object # Create a persistent service provider object
...@@ -219,7 +234,12 @@ sub req_select_email { ...@@ -219,7 +234,12 @@ sub req_select_email {
}; };
if ($EVAL_ERROR) { if ($EVAL_ERROR) {
$self->{logger}->error("Failed to load federation metadata: $EVAL_ERROR"); $self->{logger}->error("Failed to load federation metadata: $EVAL_ERROR");
$self->respond({ errors => [ "internal" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "internal" ]
}
);
} }
my $sps = $metadata->parse(id => $self->{in}->{entityid}); my $sps = $metadata->parse(id => $self->{in}->{entityid});
...@@ -227,7 +247,12 @@ sub req_select_email { ...@@ -227,7 +247,12 @@ sub req_select_email {
$self->{logger}->errorf( $self->{logger}->errorf(
"No such SP '%s' in metadata", $self->{in}->{entityid} "No such SP '%s' in metadata", $self->{in}->{entityid}
); );
$self->respond({ errors => [ "no_such_entity" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "no_such_entity" ]
}
);
} }
my $sp = $sps->[0]; my $sp = $sps->[0];
...@@ -239,7 +264,12 @@ sub req_select_email { ...@@ -239,7 +264,12 @@ sub req_select_email {
# save in DB # save in DB
unless ($provider->save()) { unless ($provider->save()) {
$self->{logger}->error("Failed to save service provider object"); $self->{logger}->error("Failed to save service provider object");
$self->respond({ errors => [ "internal" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "internal" ]
}
);
} }
} }
...@@ -258,10 +288,13 @@ sub req_select_email { ...@@ -258,10 +288,13 @@ sub req_select_email {
} }
} }
$self->respond({ $self->respond(
provider => $provider, template => 'index-nobanner.tt2.html',
action => 'select_email' data => {
}); provider => $provider,
action => 'select_email'
}
);
} }
sub req_complete_challenge { sub req_complete_challenge {
...@@ -269,12 +302,22 @@ sub req_complete_challenge { ...@@ -269,12 +302,22 @@ sub req_complete_challenge {
unless ($self->{in}->{entityid}) { unless ($self->{in}->{entityid}) {
$self->{logger}->error("Missing parameter entityid"); $self->{logger}->error("Missing parameter entityid");
$self->respond({ errors => [ "missing_entityid" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "missing_entityid" ]
}
);
} }
unless ($self->{in}->{email}) { unless ($self->{in}->{email}) {
$self->{logger}->error("Missing parameter email"); $self->{logger}->error("Missing parameter email");
$self->respond({ errors => [ "missing_email" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "missing_email" ]
}
);
} }
my $provider = AccountManager::Service->new( my $provider = AccountManager::Service->new(
...@@ -284,7 +327,12 @@ sub req_complete_challenge { ...@@ -284,7 +327,12 @@ sub req_complete_challenge {
unless ($provider->load(speculative => 1)) { unless ($provider->load(speculative => 1)) {
$self->{logger}->errorf("No such SP '%s' in database", $self->{in}->{entityid}); $self->{logger}->errorf("No such SP '%s' in database", $self->{in}->{entityid});
$self->respond({ errors => [ "no_such_entity" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "no_such_entity" ]
}
);
} }
# override metadata contacts if needed # override metadata contacts if needed
...@@ -310,7 +358,12 @@ sub req_complete_challenge { ...@@ -310,7 +358,12 @@ sub req_complete_challenge {
$self->{in}->{entityid}, $self->{in}->{entityid},
$self->{in}->{email} $self->{in}->{email}
); );
$self->respond({ errors => [ "internal" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "internal" ]
}
);
} }
# delete any previous token for the same email/service couple # delete any previous token for the same email/service couple
...@@ -326,7 +379,12 @@ sub req_complete_challenge { ...@@ -326,7 +379,12 @@ sub req_complete_challenge {
"Failed to delete previous authentication token with ID %s", "Failed to delete previous authentication token with ID %s",
$old_token->id() $old_token->id()
); );
$self->respond({ errors => [ "internal" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "internal" ]
}
);
} }
} }
...@@ -344,7 +402,12 @@ sub req_complete_challenge { ...@@ -344,7 +402,12 @@ sub req_complete_challenge {
unless ($token->save()) { unless ($token->save()) {
$self->{logger}->error("Failed to save authentication token"); $self->{logger}->error("Failed to save authentication token");
$self->respond({ errors => [ "internal" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "internal" ]
}
);
} }
my $sender = $self->{configuration}->{_}->{notice_from}; my $sender = $self->{configuration}->{_}->{notice_from};
...@@ -354,7 +417,12 @@ sub req_complete_challenge { ...@@ -354,7 +417,12 @@ sub req_complete_challenge {
open(my $handle, '|-', "$sendmail -f $sender $recipient") or do { open(my $handle, '|-', "$sendmail -f $sender $recipient") or do {
$self->{logger}->errorf("Unable to run sendmail executable: %s", $ERRNO); $self->{logger}->errorf("Unable to run sendmail executable: %s", $ERRNO);
$self->respond({ errors => [ "mail_notification_error" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "mail_notification_error" ]
}
);
}; };
my $tt2 = Template->new({ my $tt2 = Template->new({
...@@ -379,7 +447,12 @@ sub req_complete_challenge { ...@@ -379,7 +447,12 @@ sub req_complete_challenge {
unless ($tt2->process($template, $data, $handle)) { unless ($tt2->process($template, $data, $handle)) {
$self->{logger}->errorf("Mail notification error: %s", $tt2->error()); $self->{logger}->errorf("Mail notification error: %s", $tt2->error());
$self->respond({ errors => [ "mail_notification_error" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "mail_notification_error" ]
}
);
} }
close $handle; close $handle;
...@@ -391,11 +464,14 @@ sub req_complete_challenge { ...@@ -391,11 +464,14 @@ sub req_complete_challenge {
$token->token(), $token->token(),
); );
$self->respond({ $self->respond(
email => $self->{in}->{email}, template => 'index-nobanner.tt2.html',
entityid => $self->{in}->{entityid}, data => {
action => 'complete_challenge' email => $self->{in}->{email},
}); entityid => $self->{in}->{entityid},
action => 'complete_challenge'
}
);
} }
sub req_create_accounts { sub req_create_accounts {
...@@ -403,7 +479,12 @@ sub req_create_accounts { ...@@ -403,7 +479,12 @@ sub req_create_accounts {
unless ($self->{in}->{entityid}) { unless ($self->{in}->{entityid}) {
$self->{logger}->error("Missing parameter entityid"); $self->{logger}->error("Missing parameter entityid");
$self->respond({ errors => [ "missing_entityid" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "missing_entityid" ]
}
);
} }
unless ($self->{in}->{token}) { unless ($self->{in}->{token}) {
...@@ -413,7 +494,12 @@ sub req_create_accounts { ...@@ -413,7 +494,12 @@ sub req_create_accounts {
unless ($self->{in}->{email}) { unless ($self->{in}->{email}) {
$self->{logger}->error("Missing parameter email"); $self->{logger}->error("Missing parameter email");
$self->respond({ errors => [ "missing_email" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "missing_email" ]
}
);
} }
my $token = AccountManager::Token->new( my $token = AccountManager::Token->new(
...@@ -427,7 +513,12 @@ sub req_create_accounts { ...@@ -427,7 +513,12 @@ sub req_create_accounts {
$self->{in}->{token}, $self->{in}->{token},
$self->{in}->{entityid} $self->{in}->{entityid}
); );
$self->respond({ errors => [ "wrong_token" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "wrong_token" ]
}
);
} }
if (! $token->sp_entityid() eq $self->{in}->{entityid}) { if (! $token->sp_entityid() eq $self->{in}->{entityid}) {
...@@ -436,7 +527,12 @@ sub req_create_accounts { ...@@ -436,7 +527,12 @@ sub req_create_accounts {
$self->{in}->{token}, $self->{in}->{token},
$self->{in}->{entityid} $self->{in}->{entityid}
); );
$self->respond({ errors => [ "wrong_token_for_sp" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "wrong_token_for_sp" ]
}
);
} }
## delete the token ## delete the token
...@@ -469,9 +565,13 @@ sub req_create_accounts { ...@@ -469,9 +565,13 @@ sub req_create_accounts {
); );
unless ($download_token->save()) { unless ($download_token->save()) {
push @{ $self->{out}->{errors} }, "internal";
$self->{logger}->error("Failed to save authentication token"); $self->{logger}->error("Failed to save authentication token");
$self->respond(); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "internal" ]
}
);
} }
my $key = AccountManager::Tools::generate_secret(10); my $key = AccountManager::Tools::generate_secret(10);
...@@ -499,7 +599,12 @@ sub req_create_accounts { ...@@ -499,7 +599,12 @@ sub req_create_accounts {
"Failed to create test accounts for SP with entityid %s", "Failed to create test accounts for SP with entityid %s",
$self->{in}->{entityid} $self->{in}->{entityid}
); );
$self->respond({ errors => [ "accounts_creation_failed" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "accounts_creation_failed" ]
}
);
} }
## Update simpleSAMLphp configuration to enable test accounts ## Update simpleSAMLphp configuration to enable test accounts
...@@ -519,7 +624,12 @@ sub req_create_accounts { ...@@ -519,7 +624,12 @@ sub req_create_accounts {
"Failed to create simpleSAMLphp configuration file: %s", "Failed to create simpleSAMLphp configuration file: %s",
$EVAL_ERROR $EVAL_ERROR
); );
$self->respond({ errors => [ "accounts_creation_failed" ] }); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "accounts_creation_failed" ]
}
);
} }
$self->{logger}->infof( $self->{logger}->infof(
...@@ -528,34 +638,49 @@ sub req_create_accounts { ...@@ -528,34 +638,49 @@ sub req_create_accounts {
$self->{in}->{token} $self->{in}->{token}
); );
$self->respond({ $self->respond(
accounts => \@accounts, template => 'index.tt2.html',
entityid => $self->{in}->{entityid}, data => {
key => $key, accounts => \@accounts,
token => $download_token->token(), entityid => $self->{in}->{entityid},
action => 'create_accounts' key => $key,
}); token => $download_token->token(),
action => 'create_accounts'
}
);
} }
sub req_download_accounts { sub req_download_accounts {
my ($self) = @_; my ($self) = @_;
unless ($self->{in}->{entityid}) { unless ($self->{in}->{entityid}) {
push @{ $self->{out}->{errors} }, "missing_entityid";
$self->{logger}->error("Missing parameter entityid"); $self->{logger}->error("Missing parameter entityid");
$self->respond(); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "missing_entityid" ]
}
);
} }
unless ($self->{in}->{token}) { unless ($self->{in}->{token}) {
push @{ $self->{out}->{errors} }, "missing_token";
$self->{logger}->error("Missing parameter token"); $self->{logger}->error("Missing parameter token");
$self->respond(); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "missing_token" ]
}
);
} }
unless ($self->{in}->{key}) { unless ($self->{in}->{key}) {
push @{ $self->{out}->{errors} }, "missing_key";
$self->{logger}->error("Missing parameter key"); $self->{logger}->error("Missing parameter key");
$self->respond(); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "missing_key" ]
}
);
} }
my $token = AccountManager::Token->new( my $token = AccountManager::Token->new(
...@@ -564,22 +689,30 @@ sub req_download_accounts { ...@@ -564,22 +689,30 @@ sub req_download_accounts {
); );
if (! $token->load(speculative => 1)) { if (! $token->load(speculative => 1)) {
push @{ $self->{out}->{errors} }, "wrong_token";
$self->{logger}->errorf( $self->{logger}->errorf(
"Non-existing authentication token %s", "Non-existing authentication token %s",
$self->{in}->{token}, $self->{in}->{token},
); );
$self->respond(); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "wrong_token" ]
}
);
} }
if (! $token->sp_entityid() eq $self->{in}->{entityid}) { if (! $token->sp_entityid() eq $self->{in}->{entityid}) {
push @{ $self->{out}->{errors} }, "wrong_token_for_sp";
$self->{logger}->errorf( $self->{logger}->errorf(
"Authentication token %s cannot be used for SP %s", "Authentication token %s cannot be used for SP %s",
$self->{in}->{token}, $self->{in}->{token},
$self->{in}->{entityid} $self->{in}->{entityid}
); );
$self->respond(); $self->respond(
template => 'index.tt2.html',
data => {
errors => [ "wrong_token_for_sp" ]
}
);
} }
# delete the token # delete the token
...@@ -648,9 +781,12 @@ sub req_download_accounts { ...@@ -648,9 +781,12 @@ sub req_download_accounts {
sub req_home { sub req_home {
my ($self) = @_; my ($self) = @_;
$self->respond({ $self->respond(
action => 'home' template => 'index.tt2.html',
}); data => {
action => 'home'
}
);
} }
1; 1;
...@@ -21,7 +21,7 @@ jQuery(document).ready(function($){ ...@@ -21,7 +21,7 @@ jQuery(document).ready(function($){
form.steps("insert", 1, { form.steps("insert", 1, {
title: "Select your email address", title: "Select your email address",
contentMode: "async", contentMode: "async",
contentUrl: "[% app.url %]?action=select_email&style=nobanner&entityid="+ contentUrl: "[% app.url %]?action=select_email&entityid="+
encodeURIComponent($('#entityid').val()) encodeURIComponent($('#entityid').val())
}); });
} }
...@@ -34,7 +34,7 @@ jQuery(document).ready(function($){ ...@@ -34,7 +34,7 @@ jQuery(document).ready(function($){
form.steps("insert", 2, { form.steps("insert", 2, {
title: "Complete email challenge", title: "Complete email challenge",
contentMode: "async", contentMode: "async",
contentUrl: "[% app.url %]?action=complete_challenge&style=nobanner&entityid="+ contentUrl: "[% app.url %]?action=complete_challenge&entityid="+
encodeURIComponent($('#entityid').val())+"&email="+encodeURIComponent($("input:checked[name='email']").val()) encodeURIComponent($('#entityid').val())+"&email="+encodeURIComponent($("input:checked[name='email']").val())
}); });
} }
......
...@@ -21,7 +21,7 @@ jQuery(document).ready(function($){ ...@@ -21,7 +21,7 @@ jQuery(document).ready(function($){
form.steps("insert", 1, { form.steps("insert", 1, {
title: "Select your email address", title: "Select your email address",
contentMode: "async", contentMode: "async",
contentUrl: "[% app.url %]?action=select_email&style=nobanner&entityid="+ contentUrl: "[% app.url %]?action=select_email&entityid="+
encodeURIComponent($('#entityid').val()) encodeURIComponent($('#entityid').val())
}); });
} }
...@@ -34,7 +34,7 @@ jQuery(document).ready(function($){ ...@@ -34,7 +34,7 @@ jQuery(document).ready(function($){
form.steps("insert", 2, { form.steps("insert", 2, {
title: "Complete email challenge", title: "Complete email challenge",
contentMode: "async", contentMode: "async",
contentUrl: "[% app.url %]?action=complete_challenge&style=nobanner&entityid="+ contentUrl: "[% app.url %]?action=complete_challenge&entityid="+
encodeURIComponent($('#entityid').val())+"&email="+encodeURIComponent($("input:checked[name='email']").val()) encodeURIComponent($('#entityid').val())+"&email="+encodeURIComponent($("input:checked[name='email']").val())
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment