From cd22542a119feb5640e1a4ec9c9ca5b95ea6d214 Mon Sep 17 00:00:00 2001 From: Guillaume Rousse <guillaume.rousse@renater.fr> Date: Fri, 18 Dec 2020 15:31:37 +0100 Subject: [PATCH] allow user to select list of account profiles --- lib/AccountManager/App.pm | 31 ++++++++++++++++--- lib/AccountManager/L10N/fr.pm | 4 +++ .../web/renater/complete_challenge.tt2.html | 9 ++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/AccountManager/App.pm b/lib/AccountManager/App.pm index 870b178..a73c8f5 100644 --- a/lib/AccountManager/App.pm +++ b/lib/AccountManager/App.pm @@ -491,6 +491,8 @@ sub req_complete_challenge { $token->secret(), ); + my @profiles = split(/, */, $self->{configuration}->{service}->{account_profiles}); + $self->respond( template => 'complete_challenge.tt2.html', data => { @@ -498,6 +500,7 @@ sub req_complete_challenge { entityid => $entityid, email => $email, validity => $self->{configuration}->{service}->{account_validity_period}, + profiles => \@profiles } ); } @@ -512,6 +515,7 @@ sub req_create_accounts { my $token = $self->get_parameter(name => 'token'); my $email = $self->get_parameter(name => 'email'); my $validity = $self->get_parameter(name => 'validity'); + my @profiles = $self->get_multivalued_parameter(name => 'profiles'); $self->check_token(token => $token, entityid => $entityid); @@ -527,10 +531,6 @@ sub req_create_accounts { ## create test accounts my @accounts; - my $profiles = - $self->{configuration}->{$entityid}->{account_profiles} || - $self->{configuration}->{service}->{account_profiles}; - my $creation_date = DateTime->now(); my $token_expiration_date = DateTime->now()->add( hours => $self->{configuration}->{service}->{tokens_validity_period} @@ -555,7 +555,7 @@ sub req_create_accounts { my $key = AccountManager::Tools::generate_secret(10); - foreach my $profile (split(/, */, $profiles)) { + foreach my $profile (@profiles) { my $password = AccountManager::Tools::generate_password(10); my $account = AccountManager::Account->new( db => $self->{db}, @@ -743,6 +743,27 @@ sub get_parameter { return $value; } +sub get_multivalued_parameter { + my ($self, %args) = @_; + + my $name = $args{name}; + my @values = $self->{cgi}->param($name); + + $self->abort( + log => "Missing parameter: $name", + user => "missing_$name" + ) if !@values; + + if ($patterns{$name}) { + $self->abort( + log => "Incorrect parameter format: $name", + user => "format_$name" + ) if any { $_ !~ $patterns{$name} } @values; + } + + return @values; +} + sub get_metadata_file { my ($self, %args) = @_; diff --git a/lib/AccountManager/L10N/fr.pm b/lib/AccountManager/L10N/fr.pm index f855ea2..5a73849 100644 --- a/lib/AccountManager/L10N/fr.pm +++ b/lib/AccountManager/L10N/fr.pm @@ -35,6 +35,10 @@ msgstr "À propos" msgid "Account profile: %1" msgstr "Profil d'utilisateur: %1" +#: templates/web/renater/complete_challenge.tt2.html:26 +msgid "Account profiles:" +msgstr "Profils d'utilisateur:" + #: templates/web/renater/complete_challenge.tt2.html:22 msgid "Accounts validity period, in days:" msgstr "Durée de validité des comptes, en jours:" diff --git a/templates/web/renater/complete_challenge.tt2.html b/templates/web/renater/complete_challenge.tt2.html index 5eb19ad..9650ad0 100644 --- a/templates/web/renater/complete_challenge.tt2.html +++ b/templates/web/renater/complete_challenge.tt2.html @@ -22,6 +22,15 @@ <legend>[% lh.maketext("Accounts validity period, in days:") %]</legend> <input name="validity" value="[% validity %]" id="validity" type="number" class="required" min="1"/> </fieldset> + <fieldset> + <legend>[% lh.maketext("Account profiles:") %]</legend> +[% FOREACH profile IN profiles %] + [% template = profile _ '.tt2' %] + [% PROCESS $template scope=account.scope() id=account.id() | trim %] + <input type="checkbox" name="profiles" value="[% profile %]" checked/>[% profile %]: [% description.${lh.language_tag()} %]<br> +[% END %] + + </fieldset> <input type="hidden" name="federation" value="[% federation %]"/> <input type="hidden" name="entityid" value="[% entityid %]"/> <input type="hidden" name="email" value="[% email %]"/> -- GitLab