-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/update password reset template (#261)
* Утилиты для работы с рассылкой email и регистрацией пользователей перенесены в приложение users. * Утилиты для работы с рассылкой email и регистрацией пользователей перенесены в приложение users. * Обновлены зависимости poetry. * Добавлен кастомный шаблон входа в админ-панель. * Добавлен кастомный шаблон письма с одноразовым кодом. * Шаблоны разнесены по соответствующим директориям. * Добавлены настройки для 2FA. * Добавлено создание модели EmailDevice новых пользователей для рассылки OTP. * Добавлен кастомный сайт админ-панели с 2FA. * Заменен дефолтный сайт админ-панели на кастомизированный. * Добавлена форма для 2FA. * Удалены ненужные модели. * Обновлены пути к шаблонам. * Утилиты для работы с рассылкой email и регистрацией пользователей перенесены в приложение users. * Шаблоны перенесены в приложение users. * Обновлены настройки для тестирования миграций. * Обновлен шаблон письма, добавлен восклицательный знак. * Изменена основа шаблона на встроенный base_site.html. * Изменен стиль отображения ошибок формы. * Настройки админ-панели перенесены из urls в sites. * Ненужные шаблоны удалены. * Исправлены названия. --------- Co-authored-by: Konstantin Raikhert <raikhert13@gmail.com>
- Loading branch information
1 parent
935b66e
commit 88b2993
Showing
27 changed files
with
330 additions
and
130 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
from django_otp.plugins.otp_email.models import EmailDevice | ||
|
||
from users.models import User | ||
from utils.emailing.reset_password import send_password_reset_email | ||
from users.utils.emailing.reset_password import send_password_reset_email | ||
|
||
|
||
@receiver(post_save, sender=User) | ||
def password_reset_email(sender, instance, created, **kwargs): | ||
"""Send email to new admin with link to set password.""" | ||
if created and not instance.is_superuser: | ||
send_password_reset_email(instance) | ||
if created: | ||
EmailDevice.objects.create( | ||
user=instance, | ||
email=instance.email, | ||
) | ||
if not instance.is_superuser: | ||
send_password_reset_email(instance) |
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,14 @@ | ||
from django_otp.admin import OTPAdminSite | ||
|
||
from users.forms import CustomOTPAuthenticationForm | ||
|
||
|
||
class CustomOTPAdminSite(OTPAdminSite): | ||
"""Customized admin site.""" | ||
|
||
login_form = CustomOTPAuthenticationForm | ||
|
||
site_header = "Бот фонда 'Расправь крылья!'" | ||
site_title = "Бот фонда 'Расправь крылья!'" | ||
|
||
login_template = "authentication/login.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,95 @@ | ||
{% extends "admin/base_site.html" %} | ||
{% load i18n static %} | ||
|
||
{% block extrastyle %} | ||
{{ block.super }} | ||
<link rel="stylesheet" type="text/css" href="{% static "admin/css/login.css" %}" /> | ||
{{ form.media }} | ||
|
||
<style type="text/css"> | ||
input#id_otp_token, | ||
select#id_otp_device | ||
{ | ||
clear: both; | ||
padding: 6px; | ||
width: 100%; | ||
-webkit-box-sizing: border-box; | ||
-moz-box-sizing: border-box; | ||
box-sizing: border-box; | ||
} | ||
</style> | ||
{% endblock %} | ||
|
||
{% block bodyclass %}{{ block.super }} login{% endblock %} | ||
|
||
{% block usertools %}{% endblock %} | ||
|
||
{% block nav-global %}{% endblock %} | ||
|
||
{% block content_title %}{% endblock %} | ||
|
||
{% block breadcrumbs %}{% endblock %} | ||
|
||
{% block nav-sidebar %}{% endblock %} | ||
|
||
{% block content %} | ||
{% if form.errors and not form.non_field_errors %} | ||
<p class="errornote"> | ||
{% if form.errors.items|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %} | ||
</p> | ||
{% endif %} | ||
|
||
{% if form.non_field_errors %} | ||
{% for error in form.non_field_errors %} | ||
<p class="errornote"> | ||
{{ error }} | ||
</p> | ||
{% endfor %} | ||
{% endif %} | ||
|
||
<div id="content-main"> | ||
|
||
{% if user.is_authenticated %} | ||
<p class="errornote"> | ||
{% blocktrans trimmed %} | ||
You are authenticated as {{ username }}, but are not authorized to | ||
access this page. Would you like to login to a different account? | ||
{% endblocktrans %} | ||
</p> | ||
{% endif %} | ||
|
||
<form action="{{ app_path }}" method="post" id="login-form">{% csrf_token %} | ||
<div class="form-row"> | ||
{{ form.username.errors }} | ||
{{ form.username.label_tag }} {{ form.username }} | ||
</div> | ||
<div class="form-row"> | ||
{{ form.password.errors }} | ||
{{ form.password.label_tag }} {{ form.password }} | ||
<input type="hidden" name="next" value="{{ next }}" /> | ||
</div> | ||
{% if form.get_user %} | ||
<div class="form-row"> | ||
{{ form.otp_token.errors }} | ||
<label for="id_otp_token" class="required">{% trans 'Одноразовый код:' %}</label> {{ form.otp_token }} | ||
</div> | ||
{% endif %} | ||
{% url 'admin_password_reset' as password_reset_url %} | ||
{% if password_reset_url %} | ||
<div class="password-reset-link"> | ||
<a href="{{ password_reset_url }}">{% trans 'Forgotten your password or username?' %}</a> | ||
</div> | ||
{% endif %} | ||
<div class="submit-row"> | ||
<label> </label><input type="submit" value="{% trans 'Log in' %}" /> | ||
{% if form.get_user %} | ||
<label> </label><input type="submit" name="otp_challenge" value="{% trans 'Отправить код' %}" /> | ||
{% endif %} | ||
</div> | ||
</form> | ||
|
||
<script type="text/javascript"> | ||
document.getElementById('id_username').focus() | ||
</script> | ||
</div> | ||
{% endblock %} |
Oops, something went wrong.