diff --git a/hiboo/account/settings.py b/hiboo/account/settings.py index a67ac7787abf3cf5f34bd513967a825c08aafe57..4b61027bd37d6fb01aab7555fb06dc3598c2b175 100644 --- a/hiboo/account/settings.py +++ b/hiboo/account/settings.py @@ -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")) diff --git a/hiboo/account/templates/account_totp.html b/hiboo/account/templates/account_totp.html index b63ac5c3bb526f314e43ce43364787fd16a7d5e9..19880741acfebe0b8f439e05a5feb7d277764a44 100644 --- a/hiboo/account/templates/account_totp.html +++ b/hiboo/account/templates/account_totp.html @@ -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 %} diff --git a/hiboo/models.py b/hiboo/models.py index 382a3ec5be20bf356f7fb01842e118aa4d756310..aac6d4aadbb5d8e489bb7df098033ef255c9474e 100644 --- a/hiboo/models.py +++ b/hiboo/models.py @@ -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}") } diff --git a/hiboo/templates/macros.html b/hiboo/templates/macros.html index bf6b278d49822a05844093e4d008fc32e7faaf03..117e6b222d9b059e57246295db546371165fa46d 100644 --- a/hiboo/templates/macros.html +++ b/hiboo/templates/macros.html @@ -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> diff --git a/hiboo/user/templates/user_details.html b/hiboo/user/templates/user_details.html index 8813b4e95a237f8397ab4d6d2cd3333b58f5254e..b8736e2ece1bded48077d9c1b6c66d3b39a2080f 100644 --- a/hiboo/user/templates/user_details.html +++ b/hiboo/user/templates/user_details.html @@ -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> diff --git a/hiboo/user/templates/user_list.html b/hiboo/user/templates/user_list.html index e68e8847271d20019389b11688d7804d5dc0b9d4..1c81656fb425ea5e2957936e645b4a85a9009977 100644 --- a/hiboo/user/templates/user_list.html +++ b/hiboo/user/templates/user_list.html @@ -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>