From 7838789094ac220aa387862feb5bca914466e14e Mon Sep 17 00:00:00 2001
From: Guillaume Rousse <guillaume.rousse@renater.fr>
Date: Tue, 13 Feb 2018 17:11:53 +0100
Subject: [PATCH] attributes handling simplification

---
 lib/AccountManager/Account.pm         | 13 +++++++++----
 templates/web/validate_token.tt2.html |  9 ++-------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/lib/AccountManager/Account.pm b/lib/AccountManager/Account.pm
index 4c329f0..dbd4fc5 100644
--- a/lib/AccountManager/Account.pm
+++ b/lib/AccountManager/Account.pm
@@ -1,5 +1,6 @@
 package AccountManager::Account;
 
+use utf8;
 use strict;
 use warnings;
 
@@ -153,14 +154,18 @@ sub mail {
 
 sub eduPersonAffiliation {
     my ($self) = @_;
-    return $affiliation{$self->profile()};
+    my $affiliations = $affiliation{$self->profile()} || [];
+
+    return join(', ', @$affiliations);
 }
 
 sub eduPersonScopedAffiliation {
     my ($self) = @_;
-    my $affiliations = $scopedAffiliation{$self->profile()};
-    return $affiliations ?
-        [ map { $_ . '@' . $self->{scope} } @$affiliations ] : undef;
+    my $affiliations = $scopedAffiliation{$self->profile()} || [];
+
+    $affiliations = [ map { $_ . '@' . $self->{scope} } @$affiliations ];
+
+    return join(', ', @$affiliations);
 }
 
 sub eduPersonPrincipalName {
diff --git a/templates/web/validate_token.tt2.html b/templates/web/validate_token.tt2.html
index 2582260..b58179c 100644
--- a/templates/web/validate_token.tt2.html
+++ b/templates/web/validate_token.tt2.html
@@ -37,15 +37,10 @@
         <div>
             <table>
                 <caption>List of user attributes</caption>
-    [% FOREACH attribute IN [ 'cn', 'displayName', 'givenName', 'sn', 'mail', 'schacHomeOrganization', 'schacHomeOrganizationType', 'eduPersonPrincipalName' ] -%]
+    [% FOREACH attribute IN [ 'cn', 'displayName', 'givenName', 'sn', 'mail', 'schacHomeOrganization', 'schacHomeOrganizationType', 'eduPersonPrincipalName', 'eduPersonAffiliation', 'eduPersonScopedAffiliation' ] -%]
                 <tr>
                     <th>[% attribute %]</th><td> [% account.$attribute %]</td>
                 </tr>
-    [% END %]
-    [% FOREACH attribute IN [ 'eduPersonAffiliation', 'eduPersonScopedAffiliation' ] -%]
-                <tr>
-                    <th>[% attribute %]</th><td> [% account.$attribute.join(', ') %]</td>
-                </tr>
     [% END %]
                 <tr>
                     <th>eduPersonTargetedID:</th><td><i>value dynamically generated by the SP</i></td>
@@ -60,7 +55,7 @@
     [% END %]
 </div>
 
-<p><strong>Please keep a record of the above user names and passwords</strong> because currently there is no mecanism to retrieve the above credentials once you close this page. If you forget the username and passwords, you can however request new test accounts.</p>
+<p>Click <a href="[% conf.app_url %]?action=download_accounts&entityid=[% sp_entityid %]&token=[% token %]&key=[% key %]">here</a> to download the details of those accounts in CSV format.</p>
 
 <div class="alert-box warning radius">
     <p>Note that these test accounts will automatically expire in [% conf.accounts_validity_period %] days and that they can only be used to test federated login to your eduGAIN-enabled Service Provider with entityID <strong>[% sp_entityid %]</strong>.</p>
-- 
GitLab