Skip to content

Commit

Permalink
feat: improved echo_attributes page
Browse files Browse the repository at this point in the history
  • Loading branch information
Gartic99 committed Nov 27, 2023
1 parent 984ec83 commit 7eaf526
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
4 changes: 4 additions & 0 deletions example_sp/djangosaml2_sp/custom_accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class Meta:
ordering = ['username']
verbose_name_plural = _("Accounts")

def attrs(self):
for attr, value in self.__dict__.items():
yield attr, value

def __str__(self):
return '{} - {} {}'.format(self.matricola,
self.first_name, self.last_name)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
BASE_URL = '{}/saml2'.format(BASE)

LOGIN_URL = '/saml2/login/'
LOGOUT_URL = '/saml2/logout/'
LOGOUT_URL = '/logout/'
LOGIN_REDIRECT_URL = '/echo_attributes'

SAML2_DEFAULT_BINDING = saml2.BINDING_HTTP_POST
Expand Down
31 changes: 18 additions & 13 deletions example_sp/djangosaml2_sp/saml2_sp/templates/echo_attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@
<div class="nav-tabs-hidescroll mt-4 mt-md-5">
<div class="tab-content">
<div id="profile" class="tab-pane fade show active">
<h5 class="text-center mb-4">Profilo Utente</h5>
<ul class="list-group">
<li class="list-group-item"><strong>Username:</strong> {{ user.username }}</li>
<li class="list-group-item"><strong>Email:</strong> {{ user.email }}</li>
<li class="list-group-item"><strong>Nome:</strong> {{ user.first_name }}</li>
<li class="list-group-item"><strong>Cognome:</strong> {{ user.last_name }}</li>
<li class="list-group-item"><strong>Attivo:</strong> {% if user.is_active %}Sì{% else %}No{% endif %}</li>
<li class="list-group-item"><strong>Matricola:</strong> {% if user.matricola %}{{ user.matricola }}{% else %}N/A{% endif %}</li>
<li class="list-group-item"><strong>Codice Fiscale:</strong> {% if user.codice_fiscale %}{{ user.codice_fiscale }}{% else %}N/A{% endif %}</li>
<li class="list-group-item"><strong>Genere:</strong> {% if user.gender %}{{ user.gender }}{% else %}N/A{% endif %}</li>
<li class="list-group-item"><strong>Data di Nascita:</strong> {% if user.birth_date %}{{ user.birth_date }}{% else %}N/A{% endif %}</li>
<li class="list-group-item"><strong>Luogo di Nascita:</strong> {% if user.place_of_birth %}{{ user.place_of_birth }}{% else %}N/A{% endif %}</li>
</ul>
<h5 class="mb-4">Profilo Utente</h5>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Nome</th>
<th scope="col">Valore</th>
</tr>
</thead>
<tbody class="table-group-divider">
{% for name, value in user.attrs %}
<tr>
<td>{{ name }}</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions example_sp/djangosaml2_sp/saml2_sp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@


logger = logging.getLogger('djangosaml2')
attribute_display_names = {
'last_login': 'Last Login',
'username': 'Username',
'email': 'Email',
'matricola': 'Matricola',
'first_name': 'First Name',
'last_name': 'Last Name',
'codice_fiscale': 'Codice Fiscale',
'gender': 'Gender',
'place_of_birth': 'Place of Birth',
'birth_date': 'Birth Date',
}
context = {
"LOGOUT_URL" : settings.LOGOUT_URL,
"LOGIN_URL" : settings.LOGIN_URL,
Expand All @@ -41,6 +53,7 @@ def amministrazione(request):
return render(request,"amministrazione.html",context)

def echo_attributes(request):
context['attribute_display_names']=attribute_display_names
return render(request,"echo_attributes.html",context)

# TODO fix this in IdP side?
Expand Down

0 comments on commit 7eaf526

Please sign in to comment.