From 5b890dd6d3732d0935c6bcb9ca252fb3220ed6cd Mon Sep 17 00:00:00 2001 From: Guillaume Rousse <guillaume.rousse@renater.fr> Date: Thu, 26 Jul 2018 11:57:54 +0200 Subject: [PATCH] sticky language preference support, through cookie Additionally, all templates now receive all needed arguments to generate a link with full current state --- lib/AccountManager/App.pm | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/AccountManager/App.pm b/lib/AccountManager/App.pm index 2456523..2838334 100644 --- a/lib/AccountManager/App.pm +++ b/lib/AccountManager/App.pm @@ -63,9 +63,21 @@ sub new { } $self->{logger} = Log::Any->get_logger(); - $self->{lh} = AccountManager::L10N->get_handle(); + $self->{cgi} = CGI->new(); - $self->{cgi} = CGI->new(); + my $lang = + $self->{cgi}->param('lang') || + $self->{cgi}->cookie('lang'); + $self->{lh} = AccountManager::L10N->get_handle($lang ? $lang: ()); + if (!$self->{lh}) { + $self->{logger}->fatal("Unable to get suitable language handle"); + $self->respond( + template => 'errors.tt2.html', + data => { + errors => [ 'internal' ] + } + ); + } if (!$self->{configuration}->{mailer}) { $self->{logger}->fatal( @@ -194,9 +206,16 @@ sub respond { binmode(STDOUT, ":utf8"); + my $cookie = $self->{cgi}->cookie( + -name => 'lang', + -value => $self->{lh}->language_tag(), + -expires => undef, + ); + print $self->{cgi}->header( -type => 'text/html', - -charset => 'utf8' + -charset => 'utf8', + -cookie => [ $cookie ] ); unless ($tt2->process($in{template}, $in{data}, \*STDOUT)) { @@ -228,6 +247,7 @@ sub req_select_federation { $self->respond( template => 'select_federation.tt2.html', data => { + action => 'select_federation', federations => \@federations } ); @@ -279,6 +299,7 @@ sub req_select_sp { $self->respond( template => 'select_sp.tt2.html', data => { + action => 'select_sp', metadata => $metadata->parse(type => 'sp'), federation => $federation, } @@ -407,8 +428,10 @@ sub req_select_email { $self->respond( template => 'select_email.tt2.html', data => { + action => 'select_email', federation => $federation, sp => $sp, + entityid => $sp->entityid(), } ); } @@ -608,6 +631,7 @@ sub req_complete_challenge { $self->respond( template => 'complete_challenge.tt2.html', data => { + action => 'complete_challenge', federation => $federation, entityid => $self->{in}->{entityid}, email => $self->{in}->{email}, @@ -787,8 +811,10 @@ sub req_create_accounts { $self->respond( template => 'create_accounts.tt2.html', data => { + action => 'create_accounts', accounts => \@accounts, entityid => $self->{in}->{entityid}, + email => $self->{in}->{email}, key => $key, token => $download_token->token(), days => $validity_period, @@ -929,6 +955,9 @@ sub req_home { $self->respond( template => 'home.tt2.html', + data => { + action => 'home' + } ); } -- GitLab