first commit

This commit is contained in:
root
2024-09-20 04:29:09 +00:00
commit 5383007f49
459 changed files with 88755 additions and 0 deletions

64
templates/mfa/authenticate.html Executable file
View File

@@ -0,0 +1,64 @@
{% extends "mfa/base_entrance.html" %}
{% load i18n %}
{% load allauth %}
{% load allauth static %}
{% block head_title %}
{% trans "Sign In" %}
{% endblock head_title %}
{% block content %}
{% element h1 %}
{% trans "Two-Factor Authentication" %}
{% endelement %}
{% element p %}
{% blocktranslate %}Your account is protected by two-factor authentication. Please enter an authenticator code:{% endblocktranslate %}
{% endelement %}
{% url 'mfa_authenticate' as action_url %}
{% element form form=form method="post" action=action_url %}
{% slot body %}
{% csrf_token %}
{% element fields form=form unlabeled=True %}
{% endelement %}
{% endslot %}
{% slot actions %}
{% element button type="submit" tags="primary,mfa,login" %}
{% trans "Sign In" %}
{% endelement %}
{% endslot %}
{% endelement %}
{% element hr %}
{% endelement %}
{% element h2 %}
{% translate "Alternative options" %}
{% endelement %}
{% element button_group vertical=True %}
{% if "webauthn" in MFA_SUPPORTED_TYPES %}
{% element button form="webauthn_form" id="mfa_webauthn_authenticate" type="button" tags="outline,primary" %}
{% trans "Use a security key" %}
{% endelement %}
{% endif %}
{% url "account_login" as login_url %}
{% element button href=login_url tags="outline,primary,mfa,cancel" %}
{% trans "Cancel" %}
{% endelement %}
{% endelement %}
{% if "webauthn" in MFA_SUPPORTED_TYPES %}
{% element form id="webauthn_form" form=webauthn_form method="post" action=action_url no_visible_fields=True %}
{% slot body %}
{% csrf_token %}
{% element fields form=webauthn_form %}
{% endelement %}
{% endslot %}
{% endelement %}
{{ js_data|json_script:"js_data" }}
{% include "mfa/webauthn/snippets/scripts.html" %}
<script type="text/javascript">
allauth.webauthn.forms.authenticateForm({
ids: {
authenticate: "mfa_webauthn_authenticate",
credential: "{{ webauthn_form.credential.auto_id }}"
},
data: JSON.parse(document.getElementById('js_data').textContent)
})
</script>
{% endif %}
{% endblock content %}

View File

@@ -0,0 +1 @@
{% extends "allauth/layouts/entrance.html" %}

1
templates/mfa/base_manage.html Executable file
View File

@@ -0,0 +1 @@
{% extends "allauth/layouts/manage.html" %}

View File

@@ -0,0 +1,4 @@
{% extends "account/email/base_notification.txt" %}
{% load i18n %}
{% block notification_message %}{% blocktrans %}A new set of Two-Factor Authentication recovery codes has been generated.{% endblocktrans %}{% endblock notification_message %}

View File

@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}New Recovery Codes Generated{% endblocktrans %}
{% endautoescape %}

View File

@@ -0,0 +1,4 @@
{% extends "account/email/base_notification.txt" %}
{% load i18n %}
{% block notification_message %}{% blocktrans %}Authenticator app activated.{% endblocktrans %}{% endblock notification_message %}

View File

@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Authenticator App Activated{% endblocktrans %}
{% endautoescape %}

View File

@@ -0,0 +1,4 @@
{% extends "account/email/base_notification.txt" %}
{% load i18n %}
{% block notification_message %}{% blocktrans %}Authenticator app deactivated.{% endblocktrans %}{% endblock notification_message %}

View File

@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Authenticator App Deactivated{% endblocktrans %}
{% endautoescape %}

View File

@@ -0,0 +1,4 @@
{% extends "account/email/base_notification.txt" %}
{% load i18n %}
{% block notification_message %}{% blocktrans %}A new security key has been added.{% endblocktrans %}{% endblock notification_message %}

View File

@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Security Key Added{% endblocktrans %}
{% endautoescape %}

View File

@@ -0,0 +1,4 @@
{% extends "account/email/base_notification.txt" %}
{% load i18n %}
{% block notification_message %}{% blocktrans %}A security key has been removed.{% endblocktrans %}{% endblock notification_message %}

View File

@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Security Key Removed{% endblocktrans %}
{% endautoescape %}

115
templates/mfa/index.html Executable file
View File

@@ -0,0 +1,115 @@
{% extends "mfa/base_manage.html" %}
{% load allauth %}
{% load i18n %}
{% block head_title %}
{% trans "Two-Factor Authentication" %}
{% endblock head_title %}
{% block content %}
{% element h1 tags="mfa,index" %}
{% trans "Two-Factor Authentication" %}
{% endelement %}
{% if "totp" in MFA_SUPPORTED_TYPES %}
{% element panel %}
{% slot title %}
{% translate "Authenticator App" %}
{% endslot %}
{% slot body %}
{% if authenticators.totp %}
{% element p %}
{% translate "Authentication using an authenticator app is active." %}
{% endelement %}
{% else %}
{% element p %}
{% translate "An authenticator app is not active." %}
{% endelement %}
{% endif %}
{% endslot %}
{% slot actions %}
{% url 'mfa_deactivate_totp' as deactivate_url %}
{% url 'mfa_activate_totp' as activate_url %}
{% if authenticators.totp %}
{% element button href=deactivate_url tags="danger,delete,panel" %}
{% translate "Deactivate" %}
{% endelement %}
{% else %}
{% element button href=activate_url tags="panel" %}
{% translate "Activate" %}
{% endelement %}
{% endif %}
{% endslot %}
{% endelement %}
{% endif %}
{% if "webauthn" in MFA_SUPPORTED_TYPES %}
{% element panel %}
{% slot title %}
{% translate "Security Keys" %}
{% endslot %}
{% slot body %}
{% if authenticators.webauthn|length %}
<p>
{% blocktranslate count count=authenticators.webauthn|length %}You have added {{ count }} security key.{% plural %}You have added {{ count }} security keys.{% endblocktranslate %}
</p>
{% else %}
<p>{% translate "No security keys have been added." %}</p>
{% endif %}
{% endslot %}
{% slot actions %}
{% if authenticators.webauthn|length %}
{% url 'mfa_list_webauthn' as webauthn_list_url %}
{% element button href=webauthn_list_url %}
{% translate "Manage" %}
{% endelement %}
{% else %}
{% url 'mfa_add_webauthn' as webauthn_add_url %}
{% element button href=webauthn_add_url %}
{% translate "Add" %}
{% endelement %}
{% endif %}
{% endslot %}
{% endelement %}
{% endif %}
{% if "recovery_codes" in MFA_SUPPORTED_TYPES %}
{% with total_count=authenticators.recovery_codes.generate_codes|length unused_count=authenticators.recovery_codes.get_unused_codes|length %}
{% element panel %}
{% slot title %}
{% translate "Recovery Codes" %}
{% endslot %}
{% slot body %}
{% if authenticators.recovery_codes %}
{% element p %}
{% blocktranslate count unused_count=unused_count %}There is {{ unused_count }} out of {{ total_count }} recovery codes available.{% plural %}There are {{ unused_count }} out of {{ total_count }} recovery codes available.{% endblocktranslate %}
{% endelement %}
{% else %}
{% element p %}
{% translate "No recovery codes set up." %}
{% endelement %}
{% endif %}
{% endslot %}
{% if is_mfa_enabled %}
{% if authenticators.recovery_codes %}
{% if unused_count > 0 %}
{% slot actions %}
{% url 'mfa_view_recovery_codes' as view_url %}
{% element button href=view_url tags="panel" %}
{% translate "View" %}
{% endelement %}
{% endslot %}
{% slot actions %}
{% url 'mfa_download_recovery_codes' as download_url %}
{% element button href=download_url tags="secondary,panel" %}
{% translate "Download" %}
{% endelement %}
{% endslot %}
{% endif %}
{% endif %}
{% slot actions %}
{% url 'mfa_generate_recovery_codes' as generate_url %}
{% element button href=generate_url tags="secondary,panel" %}
{% translate "Generate" %}
{% endelement %}
{% endslot %}
{% endif %}
{% endelement %}
{% endwith %}
{% endif %}
{% endblock content %}

View File

@@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans %}A new set of recovery codes has been generated.{% endblocktrans %}

View File

@@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans %}Authenticator app activated.{% endblocktrans %}

View File

@@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans %}Authenticator app deactivated.{% endblocktrans %}

View File

@@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans %}Security key added.{% endblocktrans %}

View File

@@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans %}Security key removed.{% endblocktrans %}

View File

@@ -0,0 +1,22 @@
{% extends "account/base_reauthenticate.html" %}
{% load i18n %}
{% load allauth %}
{% block reauthenticate_content %}
{% element p %}
{% blocktranslate %}Enter an authenticator code:{% endblocktranslate %}
{% endelement %}
{% url 'mfa_reauthenticate' as action_url %}
{% element form form=form method="post" action=action_url %}
{% slot body %}
{% csrf_token %}
{% element fields form=form unlabeled=True %}
{% endelement %}
{{ redirect_field }}
{% endslot %}
{% slot actions %}
{% element button type="submit" tags="primary,mfa,login" %}
{% trans "Confirm" %}
{% endelement %}
{% endslot %}
{% endelement %}
{% endblock %}

View File

@@ -0,0 +1,5 @@
{% extends "mfa/base_manage.html" %}
{% load i18n %}
{% block head_title %}
{% trans "Recovery Codes" %}
{% endblock head_title %}

View File

@@ -0,0 +1,2 @@
{% for code in unused_codes %}{{ code }}
{% endfor %}

View File

@@ -0,0 +1,33 @@
{% extends "mfa/recovery_codes/base.html" %}
{% load i18n %}
{% load allauth %}
{% block content %}
{% element h1 %}
{% translate "Recovery Codes" %}
{% endelement %}
{% element p %}
{% blocktranslate %}You are about to generate a new set of recovery codes for your account.{% endblocktranslate %}
{% if unused_code_count %}
{% blocktranslate %}This action will invalidate your existing codes.{% endblocktranslate %}
{% endif %}
{% blocktranslate %}Are you sure?{% endblocktranslate %}
{% endelement %}
{% url 'mfa_generate_recovery_codes' as action_url %}
{% element form method="post" action=action_url no_visible_fields=True %}
{% slot body %}
{% csrf_token %}
{{ form.as_p }}
{% endslot %}
{% slot actions %}
{% setvar tags %}
{% if unused_code_count %}
danger
{% else %}
{% endif %}
{% endsetvar %}
{% element button type="submit" tags=tags %}
{% trans "Generate" %}
{% endelement %}
{% endslot %}
{% endelement %}
{% endblock content %}

View File

@@ -0,0 +1,30 @@
{% extends "mfa/recovery_codes/base.html" %}
{% load i18n %}
{% load allauth %}
{% block content %}
{% element h1 %}
{% translate "Recovery Codes" %}
{% endelement %}
{% element p %}
{% blocktranslate count unused_count=unused_codes|length %}There is {{ unused_count }} out of {{ total_count }} recovery codes available.{% plural %}There are {{ unused_count }} out of {{ total_count }} recovery codes available.{% endblocktranslate %}
{% endelement %}
{% element field id="recovery_codes" type="textarea" disabled=True rows=unused_codes|length readonly=True %}
{% slot label %}
{% translate "Unused codes" %}
{% endslot %}
{% comment %} djlint:off {% endcomment %}
{% slot value %}{% for code in unused_codes %}{% if forloop.counter0 %}
{% endif %}{{ code }}{% endfor %}{% endslot %}
{% comment %} djlint:on {% endcomment %}
{% endelement %}
{% if unused_codes %}
{% url 'mfa_download_recovery_codes' as download_url %}
{% element button href=download_url %}
{% translate "Download codes" %}
{% endelement %}
{% endif %}
{% url 'mfa_generate_recovery_codes' as generate_url %}
{% element button href=generate_url %}
{% translate "Generate new codes" %}
{% endelement %}
{% endblock content %}

View File

@@ -0,0 +1,36 @@
{% extends "mfa/totp/base.html" %}
{% load allauth i18n %}
{% block head_title %}
{% translate "Activate Authenticator App" %}
{% endblock head_title %}
{% block content %}
{% element h1 %}
{% translate "Activate Authenticator App" %}
{% endelement %}
{% element p %}
{% blocktranslate %}To protect your account with two-factor authentication, scan the QR code below with your authenticator app. Then, input the verification code generated by the app below.{% endblocktranslate %}
{% endelement %}
{% url 'mfa_activate_totp' as action_url %}
{% element form form=form method="post" action=action_url %}
{% slot body %}
{% element img src=totp_svg_data_uri alt=form.secret tags="mfa,totp,qr" %}
{% endelement %}
{% csrf_token %}
{% element field id="authenticator_secret" type="text" value=form.secret disabled=True %}
{% slot label %}
{% translate "Authenticator secret" %}
{% endslot %}
{% slot help_text %}
{% translate "You can store this secret and use it to reinstall your authenticator app at a later time." %}
{% endslot %}
{% endelement %}
{% element fields form=form %}
{% endelement %}
{% endslot %}
{% slot actions %}
{% element button type="submit" %}
{% trans "Activate" %}
{% endelement %}
{% endslot %}
{% endelement %}
{% endblock content %}

5
templates/mfa/totp/base.html Executable file
View File

@@ -0,0 +1,5 @@
{% extends "mfa/base_manage.html" %}
{% load i18n %}
{% block head_title %}
{% trans "Authenticator App" %}
{% endblock head_title %}

View File

@@ -0,0 +1,28 @@
{% extends "mfa/totp/base.html" %}
{% load i18n %}
{% load allauth %}
{% block head_title %}
{% trans "Deactivate Authenticator App" %}
{% endblock head_title %}
{% block content %}
{% element h1 %}
{% trans "Deactivate Authenticator App" %}
{% endelement %}
{% element p %}
{% blocktranslate %}You are about to deactivate authenticator app based authentication. Are you sure?{% endblocktranslate %}
{% endelement %}
{% url 'mfa_deactivate_totp' as action_url %}
{% element form form=form method="post" action=action_url no_visible_fields=True %}
{% slot body %}
{% csrf_token %}
{% element fields form=form %}
{{ form.as_p }}
{% endelement %}
{% endslot %}
{% slot actions %}
{% element button tags="danger,delete" type="submit" %}
{% trans "Deactivate" %}
{% endelement %}
{% endslot %}
{% endelement %}
{% endblock content %}

View File

@@ -0,0 +1,34 @@
{% extends "mfa/webauthn/base.html" %}
{% load i18n %}
{% load static %}
{% load allauth %}
{% block content %}
{% element h1 %}
{% trans "Add Security Key" %}
{% endelement %}
{% url 'mfa_add_webauthn' as action_url %}
{% element form form=form method="post" action=action_url %}
{% slot body %}
{% csrf_token %}
{% element fields form=form %}
{% endelement %}
{% endslot %}
{% slot actions %}
{% element button id="mfa_webauthn_add" type="button" %}
{% trans "Add" %}
{% endelement %}
{% endslot %}
{% endelement %}
{% include "mfa/webauthn/snippets/scripts.html" %}
{{ js_data|json_script:"js_data" }}
<script>
allauth.webauthn.forms.addForm({
ids: {
add: "mfa_webauthn_add",
passwordless: "{{ form.passwordless.auto_id }}",
credential: "{{ form.credential.auto_id }}"
},
data: JSON.parse(document.getElementById('js_data').textContent)
})
</script>
{% endblock %}

View File

@@ -0,0 +1,18 @@
{% extends "mfa/webauthn/base.html" %}
{% load i18n %}
{% load allauth %}
{% block content %}
{% element h1 %}
{% trans "Remove Security Key" %}
{% endelement %}
<p>{% blocktranslate %}Are you sure you want to remove this security key?{% endblocktranslate %}</p>
{% url 'mfa_remove_webauthn' pk=authenticator.pk as action_url %}
{% element form method="post" action=action_url no_visible_fields=True %}
{% slot actions %}
{% csrf_token %}
{% element button tags="danger" type="submit" %}
{% translate "Remove" %}
{% endelement %}
{% endslot %}
{% endelement %}
{% endblock %}

View File

@@ -0,0 +1,72 @@
{% extends "mfa/webauthn/base.html" %}
{% load i18n %}
{% load static %}
{% load allauth %}
{% load humanize %}
{% block content %}
{% element h1 %}
{% trans "Security Keys" %}
{% endelement %}
{% if authenticators|length == 0 %}
<p>{% blocktranslate %}No security keys have been added.{% endblocktranslate %}</p>
{% else %}
{% element table %}
{% element thead %}
{% element th %}
{% translate "Key" %}
{% endelement %}
{% element th %}
{% translate "Usage" %}
{% endelement %}
{% element th %}
{% endelement %}
{% endelement %}
{% element tbody %}
{% for authenticator in authenticators %}
{% element tr %}
{% element td %}
{{ authenticator }}
{% if authenticator.wrap.is_passwordless is True %}
{% element badge tags="mfa,key,primary" %}
{% translate "Passkey" %}
{% endelement %}
{% elif authenticator.wrap.is_passwordless is False %}
{% element badge tags="mfa,key,secondary" %}
{% translate "Security key" %}
{% endelement %}
{% else %}
{% element badge title=_("This key does not indicate whether it is a passkey.") tags="mfa,key,warning" %}
{% translate "Unspecified" %}
{% endelement %}
{% endif %}
{% endelement %}
{% element td %}
{% blocktranslate with created_at=authenticator.created_at|date:"SHORT_DATE_FORMAT" %}Added on {{ created_at }}{% endblocktranslate %}.
{% if authenticator.last_used_at %}
{% blocktranslate with last_used=authenticator.last_used_at|naturaltime %}Last used {{ last_used }}{% endblocktranslate %}
{% else %}
Not used.
{% endif %}
{% endelement %}
{% element td align="right" %}
{% url 'mfa_edit_webauthn' pk=authenticator.pk as edit_url %}
{% element button tags="mfa,authenticator,edit,tool" href=edit_url %}
{% translate "Edit" %}
{% endelement %}
{% url 'mfa_remove_webauthn' pk=authenticator.pk as remove_url %}
{% element button tags="mfa,authenticator,danger,delete,tool" href=remove_url %}
{% translate "Remove" %}
{% endelement %}
{% endelement %}
{% endelement %}
{% endfor %}
{% endelement %}
{% endelement %}
{% endif %}
{% url 'mfa_add_webauthn' as add_url %}
{% element button href=add_url %}
{% translate "Add" %}
{% endelement %}
</li>
</ul>
{% endblock %}

View File

@@ -0,0 +1,5 @@
{% extends "mfa/base_manage.html" %}
{% load i18n %}
{% block head_title %}
{% trans "Security Keys" %}
{% endblock head_title %}

View File

@@ -0,0 +1,22 @@
{% extends "mfa/webauthn/base.html" %}
{% load i18n %}
{% load static %}
{% load allauth %}
{% block content %}
{% element h1 %}
{% trans "Edit Security Key" %}
{% endelement %}
{% url 'mfa_edit_webauthn' as action_url %}
{% element form form=form method="post" action=action_url %}
{% slot body %}
{% csrf_token %}
{% element fields form=form %}
{% endelement %}
{% endslot %}
{% slot actions %}
{% element button id="mfa_webauthn_edit" type="submit" %}
{% trans "Save" %}
{% endelement %}
{% endslot %}
{% endelement %}
{% endblock %}

View File

@@ -0,0 +1,30 @@
{% extends "account/base_reauthenticate.html" %}
{% load i18n %}
{% load allauth %}
{% block reauthenticate_content %}
{% url 'mfa_reauthenticate_webauthn' as action_url %}
{% element form form=form method="post" action=action_url %}
{% slot body %}
{% csrf_token %}
{% element fields form=form unlabeled=True %}
{% endelement %}
{{ redirect_field }}
{% endslot %}
{% slot actions %}
{% element button id="mfa_webauthn_reauthenticate" type="submit" tags="primary,mfa,login" %}
{% trans "Use a security key" %}
{% endelement %}
{% endslot %}
{% endelement %}
{{ js_data|json_script:"js_data" }}
{% include "mfa/webauthn/snippets/scripts.html" %}
<script type="text/javascript">
allauth.webauthn.forms.authenticateForm({
ids: {
authenticate: "mfa_webauthn_reauthenticate",
credential: "{{ form.credential.auto_id }}"
},
data: JSON.parse(document.getElementById('js_data').textContent)
})
</script>
{% endblock %}

View File

@@ -0,0 +1,14 @@
{% include "mfa/webauthn/snippets/scripts.html" %}
<form id="mfa_login" action="{% url 'mfa_login_webauthn' %}" method="post">
{% csrf_token %}
{{ redirect_field }}
<input type="hidden" name="credential" id="mfa_credential">
</form>
<script type="text/javascript">
allauth.webauthn.forms.loginForm({
ids: {
login: "passkey_login",
credential: "mfa_credential",
}
})
</script>

View File

@@ -0,0 +1,4 @@
{% load i18n static %}
<noscript>{% translate "This functionality requires JavaScript." %}"</noscript>
<script type="text/javascript" src="{% static 'mfa/js/webauthn-json.js' %}"></script>
<script type="text/javascript" src="{% static 'mfa/js/webauthn.js' %}"></script>