Skip to content
Snippets Groups Projects
Verified Commit 6c281cd5 authored by ornanovitch's avatar ornanovitch
Browse files

badges with macros (merci @f00wl)

parent 11995b4d
No related branches found
No related tags found
No related merge requests found
......@@ -136,6 +136,11 @@ class Auth(db.Model):
PASSWORD = "password"
TOTP = "totp"
BADGES = {
PASSWORD: "gray",
TOTP: "blue"
}
def __init__(self, realm):
self.realm = realm
......
......@@ -70,6 +70,14 @@
{% endif %}
{% endmacro %}
{% macro auths_badges(auths) %}
{% for realm, auth in auths.items() %}
<span class="badge bg-{{ auth.BADGES[realm] }}">
{{ realm }}
</span>
{% endfor %}
{% endmacro %}
{% macro infobox(title, text, color, icon) %}
<div class="info-box">
<span class="info-box-icon bg-{{ color }}"><i class="fas fa-{{ icon }}"></i></span>
......
......@@ -18,15 +18,9 @@
<dt class="col-sm-3">{% trans %}Created at{% endtrans %}</dt>
<dd class="col-sm-9">{{ user.created_at }}</dd>
<dt class="col-sm-3">{% trans %}2FA{% endtrans %}</dt>
<dt class="col-sm-3">{% trans %}Auth. methods{% endtrans %}</dt>
<!-- TODO: passer par un badge coloré défini en macro -->
<dd class="col-sm-9">
{% if totp %}
{% trans %}Enabled{% endtrans %}
{% else %}
{% trans %}Disabled{% endtrans %}
{% endif %}
</dd>
<dd class="col-sm-9">{{ macros.auths_badges(user.auths) }}</dd>
{% if user.contact %}
{% for name, value in user.contact.items() %}
......
......@@ -12,7 +12,7 @@
<tr>
<th>{% trans %}Username{% endtrans %}</th>
<th>{% trans %}Created on{% endtrans %}</th>
<th>{% trans %}2 factor auth.{% endtrans %}</th>
<th>{% trans %}Auth. methods{% endtrans %}</th>
</tr>
</thead>
<tbody>
......@@ -20,7 +20,7 @@
<tr>
<td><a href="{{ url_for("user.details", user_uuid=user.uuid) }}">{{ user.username }}</a></td>
<td>{{ user.created_at.date() }}</td>
<td>{% if user.auths["totp"] %}OUI{% else %}NON{% endif %}</td>
<td>{{ macros.auths_badges(user.auths) }}</td>
</tr>
{% endfor %}
</tbody>
......
......@@ -26,8 +26,7 @@ def list():
@security.admin_required()
def details(user_uuid):
user = models.User.query.get(user_uuid) or flask.abort(404)
totp = models.Auth.TOTP in user.auths
return flask.render_template("user_details.html", user=user, totp=totp)
return flask.render_template("user_details.html", user=user)
@blueprint.route("/reset/<user_uuid>", methods=["GET", "POST"])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment