Skip to content
Snippets Groups Projects
Commit ec6001bc authored by kaiyou's avatar kaiyou
Browse files

Merge branch...

Merge branch '90-afficher-si-la-2fa-est-activee-dans-la-liste-des-utilisateruices-et-le-detail' into 'master'

Resolve #90 & #93

Closes #90 et #93

See merge request acides/hiboo/hiboo!35
parents d25b3fdc 08cc51d2
No related branches found
No related tags found
No related merge requests found
......@@ -52,29 +52,31 @@ def totp():
@blueprint.route("/totp/setup", methods=["GET", "POST"])
@security.authentication_required()
@security.confirmation_required("Setup 2FA with TOTP")
@security.confirmation_required("setup TOTP")
def totp_setup():
user = flask_login.current_user
auth = models.Auth(models.Auth.TOTP)
auth.set_otp_key()
user.auths[models.Auth.TOTP] = auth
models.log(models.History.MFA, user=flask_login.current_user)
models.log(models.History.MFA, comment=str(_("TOTP has been enabled")),
user=flask_login.current_user)
models.db.session.add(auth)
models.db.session.commit()
flask.flash(_("Successfully setup 2FA"), "success")
flask.flash(_("Successfully setup TOTP"), "success")
return flask.redirect(flask.url_for(".totp"))
@blueprint.route("/totp/delete", methods=["GET", "POST"])
@security.authentication_required()
@security.confirmation_required("Delete 2FA with TOTP")
@security.confirmation_required("disable TOTP")
def totp_delete():
user = flask_login.current_user
auth = user.auths[models.Auth.TOTP]
models.log(models.History.MFA, user=flask_login.current_user)
models.log(models.History.MFA, comment=str(_("TOTP has been disabled")),
user=flask_login.current_user)
models.db.session.delete(auth)
models.db.session.commit()
flask.flash(_("Successfully deleted 2FA"), "success")
flask.flash(_("Successfully disabled TOTP"), "success")
return flask.redirect(flask.url_for(".totp"))
......
......@@ -11,7 +11,7 @@
<h5>{% trans %}Not configured{% endtrans %}</h5>
<p>{% trans %}Two-factor authentication with Time-based One-Time Passowrd is not setup.{% endtrans %}
<br>
{% trans %}Click on "Setup 2FA" to get started.{% endtrans %}
{% trans %}Click on "Setup TOTP" to get started.{% endtrans %}
</p>
</blockquote>
</div>
......@@ -47,9 +47,9 @@
{% block actions %}
{% if not key %}
<a href="{{ url_for(".totp_setup") }}" class="btn btn-info">{% trans %}Setup 2FA{% endtrans %}</a>
<a href="{{ url_for(".totp_setup") }}" class="btn btn-info">{% trans %}Setup TOTP{% endtrans %}</a>
{% else %}
<a href="{{ url_for(".totp_delete") }}" class="btn btn-warning">{% trans %}Delete 2FA{% endtrans %}</a>
<a href="{{ url_for(".totp_delete") }}" class="btn btn-warning">{% trans %}Delete TOTP{% endtrans %}</a>
{% endif %}
{% endblock %}
......@@ -136,6 +136,11 @@ class Auth(db.Model):
PASSWORD = "password"
TOTP = "totp"
BADGES = {
PASSWORD: "gray",
TOTP: "blue"
}
def __init__(self, realm):
self.realm = realm
......@@ -325,13 +330,13 @@ class History(db.Model):
STATUS = "status"
TRANSITION = "transition"
PASSWORD = "password"
MFA = "2fa"
MFA = "mfa"
DESCRIPTION = {
SIGNUP: _("signed up for this account"),
CREATE: _("created the profile {this.profile.username} on {this.service.name}"),
PASSWORD: _("changed this account password"),
MFA: _("alter this account two-factor authentication settings"),
MFA: _("modified this account multi-factor authentication (MFA) setting"),
STATUS: _("set the {this.service.name} profile {this.profile.username} as {this.value}"),
TRANSITION: _("did {this.transition.label} the profile {this.profile.username} on {this.service.name}")
}
......
......@@ -12,7 +12,13 @@
</div>
{% endif %}
<div>
<i class="fas fa-{{ {"signup": "address-card", "create": "plus", "transition": "recycle", "password": "lock", "2fa": "qrcode"}[event.category] }} bg-blue"></i>
<i class="fas fa-{{ {
"signup": "address-card",
"create": "plus",
"transition": "recycle",
"password": "lock",
"mfa": "qrcode"
}[event.category] }} bg-blue"></i>
<div class="timeline-item">
<span class="time"><i class="fas fa-clock"></i> {{ event.created_at.time().strftime("%H:%M") }}</span>
<h3 class="timeline-header">
......@@ -63,6 +69,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,6 +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 %}Auth. methods{% endtrans %}</dt>
<dd class="col-sm-9">{{ macros.auths_badges(user.auths) }}</dd>
{% if user.contact %}
{% for name, value in user.contact.items() %}
<dt class="col-sm-3">{{ name | capitalize }}</dt>
......
......@@ -12,6 +12,7 @@
<tr>
<th>{% trans %}Username{% endtrans %}</th>
<th>{% trans %}Created on{% endtrans %}</th>
<th>{% trans %}Auth. methods{% endtrans %}</th>
</tr>
</thead>
<tbody>
......@@ -19,6 +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>{{ macros.auths_badges(user.auths) }}</td>
</tr>
{% endfor %}
</tbody>
......
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