feat: implement user authentication features (registration, activation, and password reset)
All checks were successful
Build and Push Docker Image / build (push) Successful in 46s

- Added email templates for activation and password reset (`activation_email.html`, `password_reset_email.html`, etc.)
- Created forms for registration (`RegisterForm`) and login (`LoginForm`) with custom validation
- Developed new pages for account activation (`activation_success.html`, `activation_invalid.html`), password reset workflow, and profile
- Configured email backend and environment file handling in settings
- Updated header template to conditionally display profile or login links based on authentication status
- Enhanced CSS styles for authentication-related pages and forms
This commit is contained in:
2026-04-15 18:27:23 +02:00
parent 921cea9044
commit 80164b833b
25 changed files with 1198 additions and 59 deletions

View File

@@ -0,0 +1,36 @@
{% extends '_layouts/base.html' %}
{% load static %}
{% block title %}Ссылка недействительна{% endblock %}
{% block add_css %}
<link rel="stylesheet" href="{% static 'css/login.css' %}">
{% endblock %}
{% block content %}
<div class="auth-page">
{% include "_fragments/header.html" %}
<main class="auth-section">
<div class="container auth-layout">
<section class="auth-intro auth-intro--reset">
<p class="auth-kicker">Ошибка подтверждения</p>
<h1 class="auth-title">Ссылка недействительна</h1>
<p class="auth-description">
Ссылка подтверждения истекла или уже была использована. Попробуйте зарегистрироваться снова.
</p>
</section>
<section class="auth-panel">
<div class="auth-copy-block">
<h2 class="auth-panel-title">Что можно сделать</h2>
<p class="auth-panel-text">Если аккаунт уже активирован, просто войдите. Если нет, создайте новый аккаунт и подтвердите почту повторно.</p>
<div class="auth-buttons">
<a class="auth-submit-link" href="{% url 'users:login' %}">Войти</a>
<a class="auth-secondary-link" href="{% url 'users:register' %}">Регистрация</a>
</div>
</div>
</section>
</div>
</main>
{% include "_fragments/footer.html" %}
</div>
{% endblock %}

View File

@@ -0,0 +1,36 @@
{% extends '_layouts/base.html' %}
{% load static %}
{% block title %}Почта подтверждена{% endblock %}
{% block add_css %}
<link rel="stylesheet" href="{% static 'css/login.css' %}">
{% endblock %}
{% block content %}
<div class="auth-page">
{% include "_fragments/header.html" %}
<main class="auth-section">
<div class="container auth-layout">
<section class="auth-intro auth-intro--login">
<p class="auth-kicker">Аккаунт активирован</p>
<h1 class="auth-title">Почта подтверждена</h1>
<p class="auth-description">
Аккаунт успешно активирован. Теперь вы можете пользоваться личным кабинетом и оформлять заказы.
</p>
</section>
<section class="auth-panel">
<div class="auth-copy-block">
<h2 class="auth-panel-title">Готово</h2>
<p class="auth-panel-text">Вы уже авторизованы в системе. Можете перейти в личный кабинет или вернуться к покупкам.</p>
<div class="auth-buttons">
<a class="auth-submit-link" href="{% url 'users:profile' %}">Личный кабинет</a>
<a class="auth-secondary-link" href="/catalog/">В каталог</a>
</div>
</div>
</section>
</div>
</main>
{% include "_fragments/footer.html" %}
</div>
{% endblock %}

View File

@@ -0,0 +1,20 @@
<html lang="ru">
<body style="margin:0;padding:24px;font-family:Arial,sans-serif;background:#f5f7fa;color:#36213e;">
<div style="max-width:640px;margin:0 auto;background:#ffffff;border:1px solid #d6dde6;padding:32px;">
<h1 style="margin:0 0 16px;font-size:28px;color:#36213e;">Подтверждение регистрации</h1>
<p style="margin:0 0 16px;font-size:16px;line-height:1.5;">
Здравствуйте{% if user.get_full_name %}, {{ user.get_full_name }}{% endif %}!
</p>
<p style="margin:0 0 24px;font-size:16px;line-height:1.5;">
Спасибо за регистрацию в {{ site_name }}. Подтвердите почту, чтобы активировать аккаунт.
</p>
<p style="margin:0 0 24px;">
<a href="{{ activation_url }}" style="display:inline-block;padding:14px 22px;background:#63768d;color:#ffffff;text-decoration:none;">Подтвердить почту</a>
</p>
<p style="margin:0;font-size:14px;line-height:1.5;color:#554971;">
Если кнопка не работает, скопируйте ссылку в браузер:<br>
<a href="{{ activation_url }}">{{ activation_url }}</a>
</p>
</div>
</body>
</html>

View File

@@ -0,0 +1,8 @@
Здравствуйте{% if user.get_full_name %}, {{ user.get_full_name }}{% endif %}!
Спасибо за регистрацию в {{ site_name }}.
Чтобы активировать аккаунт, перейдите по ссылке:
{{ activation_url }}
Если вы не создавали аккаунт, просто проигнорируйте это письмо.

View File

@@ -0,0 +1 @@
Подтверждение регистрации в {{ site_name }}

View File

@@ -0,0 +1,19 @@
<html lang="ru">
<body style="margin:0;padding:24px;font-family:Arial,sans-serif;background:#f5f7fa;color:#36213e;">
<div style="max-width:640px;margin:0 auto;background:#ffffff;border:1px solid #d6dde6;padding:32px;">
<h1 style="margin:0 0 16px;font-size:28px;color:#36213e;">Восстановление пароля</h1>
<p style="margin:0 0 24px;font-size:16px;line-height:1.5;">
Вы запросили смену пароля для аккаунта в {{ site_name|default:"SantehRay" }}.
</p>
<p style="margin:0 0 24px;">
<a href="{{ protocol }}://{{ domain }}{% url 'users:password_reset_confirm' uidb64=uid token=token %}" style="display:inline-block;padding:14px 22px;background:#63768d;color:#ffffff;text-decoration:none;">Сменить пароль</a>
</p>
<p style="margin:0;font-size:14px;line-height:1.5;color:#554971;">
Если кнопка не работает, используйте ссылку:<br>
<a href="{{ protocol }}://{{ domain }}{% url 'users:password_reset_confirm' uidb64=uid token=token %}">
{{ protocol }}://{{ domain }}{% url 'users:password_reset_confirm' uidb64=uid token=token %}
</a>
</p>
</div>
</body>
</html>

View File

@@ -0,0 +1,8 @@
Здравствуйте!
Вы запросили восстановление пароля в {{ site_name|default:"SantehRay" }}.
Перейдите по ссылке, чтобы задать новый пароль:
{{ protocol }}://{{ domain }}{% url 'users:password_reset_confirm' uidb64=uid token=token %}
Если вы не отправляли этот запрос, просто проигнорируйте это письмо.

View File

@@ -0,0 +1 @@
Восстановление пароля в {{ site_name|default:"SantehRay" }}

View File

@@ -8,32 +8,76 @@
{% endblock %}
{% block content %}
<div class="full-page">
<div class="auth-page">
{% include "_fragments/header.html" %}
<div class="center-wrapper">
<form class="login-form" action="">
<h2>ВХОД</h2>
<div class="form-group">
<label class="form-label" for="login">Логин</label>
<input class="form-input" type="text" id="login">
</div>
<div class="form-group">
<label class="form-label" for="password">Пароль</label>
<input class="form-input" type="password" id="password">
</div>
<div class="form-group">
<div>
<input class="form-input" type="checkbox" id="persist">
<label class="form-label" for="persist">Оставаться в системе</label>
</div>
</div>
<div class="form-group">
<button type="submit">Войти</button>
</div>
</form>
</div>
<main class="auth-section">
<div class="container auth-layout">
<section class="auth-intro auth-intro--login">
<p class="auth-kicker">Личный кабинет</p>
<h1 id="login-title" class="auth-title">Вход в аккаунт</h1>
<p class="auth-description">
Войдите, чтобы управлять заказами, сохранять избранные товары и быстрее оформлять покупки.
</p>
<a class="auth-side-link" href="/catalog/">Перейти в каталог</a>
</section>
<section class="auth-panel" aria-labelledby="login-title">
<form class="auth-form" action="" method="post">
{% csrf_token %}
{% if form.non_field_errors %}
<div class="auth-alert auth-alert--error">
{% for error in form.non_field_errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
<div class="auth-field">
<label for="{{ form.email.id_for_label }}">Электронная почта</label>
<input
id="{{ form.email.id_for_label }}"
name="{{ form.email.html_name }}"
type="email"
value="{{ form.email.value|default:'' }}"
placeholder="example@mail.ru"
autocomplete="email"
>
{% for error in form.email.errors %}
<p class="auth-field-error">{{ error }}</p>
{% endfor %}
</div>
<div class="auth-field">
<label for="{{ form.password.id_for_label }}">Пароль</label>
<input
id="{{ form.password.id_for_label }}"
name="{{ form.password.html_name }}"
type="password"
placeholder="Введите пароль"
autocomplete="current-password"
>
{% for error in form.password.errors %}
<p class="auth-field-error">{{ error }}</p>
{% endfor %}
<a class="auth-secondary-link" href="{% url 'users:password_reset' %}">Сбросить пароль</a>
</div>
<div class="auth-actions">
<div class="auth-buttons">
<button class="auth-submit" type="submit">Войти</button>
</div>
<p class="auth-switch">
Нет аккаунта?
<a href="{% url 'users:register' %}">Зарегистрироваться</a>
</p>
</div>
</form>
</section>
</div>
</main>
{% include "_fragments/footer.html" %}
</div>
{% endblock %}
{% endblock %}

View File

@@ -0,0 +1,65 @@
{% extends '_layouts/base.html' %}
{% load static %}
{% block title %}Сброс пароля{% endblock %}
{% block add_css %}
<link rel="stylesheet" href="{% static 'css/login.css' %}">
{% endblock %}
{% block content %}
<div class="auth-page">
{% include "_fragments/header.html" %}
<main class="auth-section">
<div class="container auth-layout">
<section class="auth-intro auth-intro--reset">
<p class="auth-kicker">Восстановление доступа</p>
<h1 id="password-reset-title" class="auth-title">Сброс пароля</h1>
<p class="auth-description">
Укажите электронную почту, и мы отправим инструкции для восстановления доступа к вашему аккаунту.
</p>
<a class="auth-side-link" href="/users/login/">Вернуться ко входу</a>
</section>
<section class="auth-panel" aria-labelledby="password-reset-title">
<form class="auth-form" action="" method="post">
{% csrf_token %}
{% if form.non_field_errors %}
<div class="auth-alert auth-alert--error">
{% for error in form.non_field_errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
<div class="auth-field">
<label for="{{ form.email.id_for_label }}">Электронная почта</label>
<input
id="{{ form.email.id_for_label }}"
name="{{ form.email.html_name }}"
type="email"
value="{{ form.email.value|default:'' }}"
placeholder="example@mail.ru"
autocomplete="email"
>
{% for error in form.email.errors %}
<p class="auth-field-error">{{ error }}</p>
{% endfor %}
</div>
<div class="auth-actions">
<button class="auth-submit" type="submit">Отправить письмо</button>
<p class="auth-switch">
Вспомнили пароль?
<a href="{% url 'users:login' %}">Вернуться ко входу</a>
</p>
</div>
</form>
</section>
</div>
</main>
{% include "_fragments/footer.html" %}
</div>
{% endblock %}

View File

@@ -0,0 +1,33 @@
{% extends '_layouts/base.html' %}
{% load static %}
{% block title %}Пароль обновлён{% endblock %}
{% block add_css %}
<link rel="stylesheet" href="{% static 'css/login.css' %}">
{% endblock %}
{% block content %}
<div class="auth-page">
{% include "_fragments/header.html" %}
<main class="auth-section">
<div class="container auth-layout">
<section class="auth-intro auth-intro--login">
<p class="auth-kicker">Готово</p>
<h1 class="auth-title">Пароль обновлён</h1>
<p class="auth-description">
Новый пароль сохранён. Теперь можно войти в аккаунт с обновлёнными данными.
</p>
</section>
<section class="auth-panel">
<div class="auth-copy-block">
<h2 class="auth-panel-title">Вход в аккаунт</h2>
<p class="auth-panel-text">Используйте новый пароль на странице входа.</p>
<a class="auth-submit-link" href="{% url 'users:login' %}">Перейти ко входу</a>
</div>
</section>
</div>
</main>
{% include "_fragments/footer.html" %}
</div>
{% endblock %}

View File

@@ -0,0 +1,78 @@
{% extends '_layouts/base.html' %}
{% load static %}
{% block title %}Новый пароль{% endblock %}
{% block add_css %}
<link rel="stylesheet" href="{% static 'css/login.css' %}">
{% endblock %}
{% block content %}
<div class="auth-page">
{% include "_fragments/header.html" %}
<main class="auth-section">
<div class="container auth-layout">
<section class="auth-intro auth-intro--reset">
<p class="auth-kicker">Обновление пароля</p>
<h1 class="auth-title">Придумайте новый пароль</h1>
<p class="auth-description">
Используйте надёжный пароль, который вы ещё не применяли для этого аккаунта.
</p>
</section>
<section class="auth-panel">
{% if validlink %}
<form class="auth-form" method="post">
{% csrf_token %}
{% if form.non_field_errors %}
<div class="auth-alert auth-alert--error">
{% for error in form.non_field_errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
<div class="auth-field">
<label for="{{ form.new_password1.id_for_label }}">Новый пароль</label>
<input
id="{{ form.new_password1.id_for_label }}"
name="{{ form.new_password1.html_name }}"
type="password"
placeholder="Введите новый пароль"
autocomplete="new-password"
>
{% for error in form.new_password1.errors %}
<p class="auth-field-error">{{ error }}</p>
{% endfor %}
</div>
<div class="auth-field">
<label for="{{ form.new_password2.id_for_label }}">Подтверждение пароля</label>
<input
id="{{ form.new_password2.id_for_label }}"
name="{{ form.new_password2.html_name }}"
type="password"
placeholder="Повторите пароль"
autocomplete="new-password"
>
{% for error in form.new_password2.errors %}
<p class="auth-field-error">{{ error }}</p>
{% endfor %}
</div>
<div class="auth-actions">
<button class="auth-submit" type="submit">Сохранить пароль</button>
</div>
</form>
{% else %}
<div class="auth-copy-block">
<h2 class="auth-panel-title">Ссылка недействительна</h2>
<p class="auth-panel-text">Возможно, ссылка уже использована или срок её действия истёк. Запросите сброс пароля повторно.</p>
<a class="auth-secondary-link" href="{% url 'users:password_reset' %}">Запросить новое письмо</a>
</div>
{% endif %}
</section>
</div>
</main>
{% include "_fragments/footer.html" %}
</div>
{% endblock %}

View File

@@ -0,0 +1,33 @@
{% extends '_layouts/base.html' %}
{% load static %}
{% block title %}Письмо отправлено{% endblock %}
{% block add_css %}
<link rel="stylesheet" href="{% static 'css/login.css' %}">
{% endblock %}
{% block content %}
<div class="auth-page">
{% include "_fragments/header.html" %}
<main class="auth-section">
<div class="container auth-layout">
<section class="auth-intro auth-intro--reset">
<p class="auth-kicker">Проверьте почту</p>
<h1 class="auth-title">Письмо отправлено</h1>
<p class="auth-description">
Если аккаунт с таким адресом существует, мы отправили письмо со ссылкой для смены пароля.
</p>
</section>
<section class="auth-panel">
<div class="auth-copy-block">
<h2 class="auth-panel-title">Что дальше</h2>
<p class="auth-panel-text">Откройте письмо и перейдите по ссылке. Если письма нет, проверьте папку «Спам».</p>
<a class="auth-secondary-link" href="{% url 'users:login' %}">Вернуться ко входу</a>
</div>
</section>
</div>
</main>
{% include "_fragments/footer.html" %}
</div>
{% endblock %}

View File

@@ -0,0 +1,40 @@
{% extends '_layouts/base.html' %}
{% load static %}
{% block title %}Профиль{% endblock %}
{% block add_css %}
<link rel="stylesheet" href="{% static 'css/login.css' %}">
{% endblock %}
{% block content %}
<div class="auth-page">
{% include "_fragments/header.html" %}
<main class="auth-section">
<div class="container auth-layout">
<section class="auth-intro auth-intro--login">
<p class="auth-kicker">Личный кабинет</p>
<h1 class="auth-title">Здравствуйте, {{ request.user.first_name|default:request.user.username }}</h1>
<p class="auth-description">
Ваш аккаунт активен и подтверждён. Здесь можно продолжить работу с заказами и персональными данными.
</p>
<a class="auth-side-link" href="/catalog/">Перейти в каталог</a>
</section>
<section class="auth-panel">
<div class="auth-copy-block">
<h2 class="auth-panel-title">Данные аккаунта</h2>
<p class="auth-panel-text"><strong>Email:</strong> {{ request.user.email }}</p>
<p class="auth-panel-text"><strong>Имя:</strong> {{ request.user.get_full_name|default:"Не указано" }}</p>
<form method="post" action="{% url 'users:logout' %}">
{% csrf_token %}
<div class="auth-actions">
<button class="auth-submit" type="submit">Выйти из аккаунта</button>
</div>
</form>
</div>
</section>
</div>
</main>
{% include "_fragments/footer.html" %}
</div>
{% endblock %}

View File

@@ -0,0 +1,108 @@
{% extends '_layouts/base.html' %}
{% load static %}
{% block title %}Регистрация{% endblock %}
{% block add_css %}
<link rel="stylesheet" href="{% static 'css/login.css' %}">
{% endblock %}
{% block content %}
<div class="auth-page">
{% include "_fragments/header.html" %}
<main class="auth-section">
<div class="container auth-layout auth-layout--reverse">
<section class="auth-intro auth-intro--register">
<p class="auth-kicker">Новый аккаунт</p>
<h1 id="register-title" class="auth-title">Регистрация</h1>
<p class="auth-description">
Создайте аккаунт, чтобы получать персональные предложения, отслеживать покупки и сохранять нужные позиции.
</p>
<a class="auth-side-link" href="/services/">Посмотреть услуги</a>
</section>
<section class="auth-panel" aria-labelledby="register-title">
<form class="auth-form" action="" method="post">
{% csrf_token %}
{% if form.non_field_errors %}
<div class="auth-alert auth-alert--error">
{% for error in form.non_field_errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
<div class="auth-field">
<label for="{{ form.full_name.id_for_label }}">Имя и фамилия</label>
<input
id="{{ form.full_name.id_for_label }}"
name="{{ form.full_name.html_name }}"
type="text"
value="{{ form.full_name.value|default:'' }}"
placeholder="Введите ваше имя"
autocomplete="name"
>
{% for error in form.full_name.errors %}
<p class="auth-field-error">{{ error }}</p>
{% endfor %}
</div>
<div class="auth-field">
<label for="{{ form.email.id_for_label }}">Электронная почта</label>
<input
id="{{ form.email.id_for_label }}"
name="{{ form.email.html_name }}"
type="email"
value="{{ form.email.value|default:'' }}"
placeholder="example@mail.ru"
autocomplete="email"
>
{% for error in form.email.errors %}
<p class="auth-field-error">{{ error }}</p>
{% endfor %}
</div>
<div class="auth-field">
<label for="{{ form.password1.id_for_label }}">Пароль</label>
<input
id="{{ form.password1.id_for_label }}"
name="{{ form.password1.html_name }}"
type="password"
placeholder="Придумайте пароль"
autocomplete="new-password"
>
{% for error in form.password1.errors %}
<p class="auth-field-error">{{ error }}</p>
{% endfor %}
</div>
<div class="auth-field">
<label for="{{ form.password2.id_for_label }}">Подтверждение пароля</label>
<input
id="{{ form.password2.id_for_label }}"
name="{{ form.password2.html_name }}"
type="password"
placeholder="Повторите пароль"
autocomplete="new-password"
>
{% for error in form.password2.errors %}
<p class="auth-field-error">{{ error }}</p>
{% endfor %}
</div>
<div class="auth-actions">
<button class="auth-submit" type="submit">Создать аккаунт</button>
<p class="auth-switch">
Уже есть аккаунт?
<a href="{% url 'users:login' %}">Войти</a>
</p>
</div>
</form>
</section>
</div>
</main>
{% include "_fragments/footer.html" %}
</div>
{% endblock %}

View File

@@ -0,0 +1,34 @@
{% extends '_layouts/base.html' %}
{% load static %}
{% block title %}Подтвердите почту{% endblock %}
{% block add_css %}
<link rel="stylesheet" href="{% static 'css/login.css' %}">
{% endblock %}
{% block content %}
<div class="auth-page">
{% include "_fragments/header.html" %}
<main class="auth-section">
<div class="container auth-layout">
<section class="auth-intro auth-intro--register">
<p class="auth-kicker">Почти готово</p>
<h1 class="auth-title">Подтвердите почту</h1>
<p class="auth-description">
Мы отправили письмо на адрес {{ email }}. Перейдите по ссылке из письма, чтобы активировать аккаунт.
</p>
</section>
<section class="auth-panel">
<div class="auth-copy-block">
<h2 class="auth-panel-title">Что дальше</h2>
<p class="auth-panel-text">Проверьте входящие, а также папки «Спам» и «Промоакции», если письмо не видно сразу.</p>
<p class="auth-switch">После подтверждения вы автоматически сможете войти в личный кабинет.</p>
<a class="auth-secondary-link" href="{% url 'users:login' %}">Вернуться на страницу входа</a>
</div>
</section>
</div>
</main>
{% include "_fragments/footer.html" %}
</div>
{% endblock %}