diff --git a/lib/AccountManager/App.pm b/lib/AccountManager/App.pm index 870b178a6baf4c4f9b4b9647482e6d09a805b32f..a73c8f5796d717980f308e06af557a2d0056c6f5 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 f855ea218cc97325369de5f64f14b7a6e88b1253..5a73849b0707e2464359bfc32d557ebd9ec98bf2 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 5eb19ad82a587d0af0abca319f5f3140755eef70..9650ad0453c205b44256a45013697c977efb424e 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 %]"/>