-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
743 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from allauth_2fa.middleware import BaseRequire2FAMiddleware | ||
from django.urls import Resolver404, get_resolver | ||
from django.utils.deprecation import MiddlewareMixin | ||
|
||
|
||
class RequireStaffAndSuperuser2FAMiddleware(BaseRequire2FAMiddleware): | ||
def require_2fa(self, request): | ||
# Staff users and superusers are required to have 2FA. | ||
return request.user.is_staff or request.user.is_superuser | ||
|
||
|
||
class TwoFactorMiddleware(MiddlewareMixin): | ||
""" | ||
Reset the login flow if another page is loaded halfway through the login. | ||
(I.e. if the user has logged in with a username/password, but not yet | ||
entered their two-factor credentials.) This makes sure a user does not stay | ||
half logged in by mistake. | ||
""" | ||
|
||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def process_request(self, request): | ||
try: | ||
match = get_resolver(request.urlconf).resolve(request.path) | ||
if ( | ||
match | ||
and not match.url_name | ||
or not match.url_name.startswith("two-factor-authenticate") | ||
): | ||
try: | ||
del request.session["allauth_2fa_user_id"] | ||
except KeyError: | ||
pass | ||
except Resolver404: | ||
return self.get_response(request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/grandchallenge/profiles/templates/allauth_2fa/authenticate.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{% extends "account/base.html" %} | ||
{% load i18n %} | ||
|
||
{% block content %} | ||
<h1> | ||
{% trans "Two-Factor Authentication" %} | ||
</h1> | ||
<p>{% trans "Enter the token from your authenticator app below." %}</p> | ||
<form method="post" class="mt-3"> | ||
{% csrf_token %} | ||
{{ form.non_field_errors }} | ||
{{ form.otp_token.label }}: | ||
{{ form.otp_token }} | ||
<br> | ||
<button class="btn btn-primary mt-3" type="submit"> | ||
{% trans 'Authenticate' %} | ||
</button> | ||
</form> | ||
{% endblock %} |
56 changes: 56 additions & 0 deletions
56
app/grandchallenge/profiles/templates/allauth_2fa/backup_tokens.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{% extends "base.html" %} | ||
{% load i18n %} | ||
|
||
{% block title %}Two-Factor Authentication{% endblock %} | ||
|
||
{% block breadcrumbs %} | ||
<ol class="breadcrumb"> | ||
<li class="breadcrumb-item text-light">Users</li> | ||
<li class="breadcrumb-item"><a | ||
href="{% url 'profile-detail' username=request.user.username %}">{{ request.user.username }}</a></li> | ||
<li class="breadcrumb-item active" aria-current="page">Two Factor Authentication Settings</li> | ||
</ol> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h1 class="mb-3"> | ||
{% trans "Two-Factor Authentication" %} | ||
</h1> | ||
<p> | ||
<i class="fas fa-check-circle text-success mr-1"></i>{% trans 'Two-Factor Authentication is enabled for your account.' %} | ||
</p> | ||
|
||
<h3 class="mt-4"> | ||
{% trans "Back-Up Tokens" %} | ||
</h3> | ||
<p>{% trans "If you have lost access to your authentication device, you can use back-up tokens for authentication instead. Back-up tokens can be used in the same way as the tokens generated by your authentication device. <b>Make sure to keep your back-up tokens secret and store them in a secure place</b>. Should you run out of tokens, you can generate new ones on this page." %}</p> | ||
|
||
{% if backup_tokens %} | ||
{% if reveal_tokens %} | ||
<p>{% trans "We have generated the following back-up tokens. These will only be displayed once. <b>Please keep them secret and store them securely</b>." %}</p> | ||
<ul> | ||
{% for token in backup_tokens %} | ||
<li>{{ token.token }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% else %} | ||
<p> {% trans 'Backup tokens have been generated, but are not revealed here for security reasons. Press the button below to generate new ones.' %} </p> | ||
{% endif %} | ||
{% else %} | ||
<p> {% trans 'No tokens. Press the button below to generate some.' %}</p> | ||
{% endif %} | ||
|
||
<form method="post"> | ||
{% csrf_token %} | ||
<button class="btn btn-primary" type="submit"> | ||
{% trans 'Generate backup tokens' %} | ||
</button> | ||
</form> | ||
|
||
<h3 class="mt-4"> | ||
{% trans "Disable Two-Factor Authentication" %} | ||
</h3> | ||
<p>{% trans 'You can disable two-factor authentication for your account at any time.' %}</p> | ||
<a class="btn btn-primary" href="{% url 'two-factor-remove' %}">Disable Two Factor Authentication</a> | ||
|
||
{% endblock %} |
32 changes: 32 additions & 0 deletions
32
app/grandchallenge/profiles/templates/allauth_2fa/remove.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{% extends "base.html" %} | ||
{% load i18n %} | ||
|
||
{% block title %}Disable Two-Factor Authentication{% endblock %} | ||
|
||
{% block breadcrumbs %} | ||
<ol class="breadcrumb"> | ||
<li class="breadcrumb-item text-light">Users</li> | ||
<li class="breadcrumb-item"><a | ||
href="{% url 'profile-detail' username=request.user.username %}">{{ request.user.username }}</a></li> | ||
<li class="breadcrumb-item active" aria-current="page">Disable Two Factor Authentication</li> | ||
</ol> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h1> | ||
{% trans "Disable Two-Factor Authentication" %} | ||
</h1> | ||
|
||
<p>{% trans "Are you sure you want to disable Two-Factor Authentication from your account?" %}</p> | ||
<p>{% trans "Confirm by entering the token from your authenticator app." %}</p> | ||
<form method="post" class="mt-3"> | ||
{% csrf_token %} | ||
{{ form.non_field_errors }} | ||
{{ form.otp_token.label }}: | ||
{{ form.otp_token }} | ||
<br> | ||
<button class="btn btn-primary mt-3" type="submit"> | ||
{% trans 'Yes, disable 2FA' %} | ||
</button> | ||
</form> | ||
{% endblock %} |
67 changes: 67 additions & 0 deletions
67
app/grandchallenge/profiles/templates/allauth_2fa/setup.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{% extends "base.html" %} | ||
{% load i18n %} | ||
|
||
{% block title %}Enable Two-Factor Authentication{% endblock %} | ||
|
||
{% block breadcrumbs %} | ||
<ol class="breadcrumb"> | ||
<li class="breadcrumb-item text-light">Users</li> | ||
<li class="breadcrumb-item"><a | ||
href="{% url 'profile-detail' username=request.user.username %}">{{ request.user.username }}</a></li> | ||
<li class="breadcrumb-item active" aria-current="page">Set-up Two Factor Authentication</li> | ||
</ol> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h1> | ||
{% trans "Setup Two-Factor Authentication" %} | ||
</h1> | ||
|
||
<h4> | ||
{% trans 'Step 1' %}: | ||
</h4> | ||
|
||
<p> | ||
{% trans "Scan the QR code below with a token generator of your choice (e.g., Google Authenticator, Microsoft Authenticator)." %} | ||
</p> | ||
|
||
<img src="{{ qr_code_url }}"/> | ||
<p> | ||
{% trans "If you can't use the QR code, enter " %} | ||
<a href="#secret-modal" data-toggle="modal" data-target="#secret-modal">{% trans "this code instead." %}</a> | ||
</p> | ||
<h4> | ||
{% trans 'Step 2' %}: | ||
</h4> | ||
|
||
<p> | ||
{% trans 'Input the token generated by the app:' %} | ||
</p> | ||
|
||
<form method="post"> | ||
{% csrf_token %} | ||
{{ form.non_field_errors }} | ||
{{ form.token.label }}: {{ form.token }} | ||
|
||
<button class="btn btn-primary btn-sm" type="submit"> | ||
{% trans 'Verify' %} | ||
</button> | ||
</form> | ||
|
||
{# modal #} | ||
<div id="secret-modal" class="modal fade" tabindex="-1" role="dialog"> | ||
<div class="modal-dialog modal-dialog-centered" role="document"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title">Your two-factor secret</h5> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<p>{{ secret_key }}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
Oops, something went wrong.