Удалена регистрация пользователей внутри тенантов - теперь только вход и управление ролями владельцем
This commit is contained in:
@@ -1,9 +0,0 @@
|
|||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% block title %}Регистрация{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<h2>Регистрация</h2>
|
|
||||||
<p>Форма регистрации доступна на главной странице.</p>
|
|
||||||
<a href="{% url 'index' %}">Перейти на главную</a>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -4,7 +4,6 @@ from . import views
|
|||||||
app_name = 'accounts'
|
app_name = 'accounts'
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('register/', views.register_view, name='register'),
|
|
||||||
path('login/', views.login_view, name='login'),
|
path('login/', views.login_view, name='login'),
|
||||||
path('logout/', views.logout_view, name='logout'),
|
path('logout/', views.logout_view, name='logout'),
|
||||||
path('profile/', views.profile_view, name='profile'),
|
path('profile/', views.profile_view, name='profile'),
|
||||||
|
|||||||
@@ -11,72 +11,11 @@ from django.contrib.auth.tokens import default_token_generator
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.auth import update_session_auth_hash
|
from django.contrib.auth import update_session_auth_hash
|
||||||
from django.contrib.auth.forms import PasswordChangeForm
|
from django.contrib.auth.forms import PasswordChangeForm
|
||||||
from .forms import CustomUserCreationForm, PasswordResetForm
|
from .forms import PasswordResetForm
|
||||||
from .models import CustomUser
|
from .models import CustomUser
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
def register(request):
|
|
||||||
if request.method == 'POST':
|
|
||||||
form = CustomUserCreationForm(request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
user = form.save(commit=False)
|
|
||||||
user.is_active = False # Пользователь не активен до подтверждения email
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
# Отправляем письмо с подтверждением
|
|
||||||
confirmation_url = request.build_absolute_uri(
|
|
||||||
reverse('accounts:confirm_email', kwargs={'token': user.email_confirmation_token})
|
|
||||||
)
|
|
||||||
|
|
||||||
subject = 'Подтверждение Email'
|
|
||||||
message = f'Привет {user.name}!\n\nДля подтверждения вашего email перейдите по следующей ссылке: {confirmation_url}\n\nСпасибо за регистрацию!'
|
|
||||||
from_email = settings.DEFAULT_FROM_EMAIL
|
|
||||||
recipient_list = [user.email]
|
|
||||||
|
|
||||||
# Выводим письмо в консоль, как вы просили
|
|
||||||
print(f"Письмо для подтверждения:\nТема: {subject}\nСообщение:\n{message}\nПолучатель: {recipient_list}")
|
|
||||||
|
|
||||||
# В реальной системе отправили бы письмо:
|
|
||||||
# send_mail(subject, message, from_email, recipient_list, fail_silently=False)
|
|
||||||
|
|
||||||
messages.success(request, 'Пожалуйста, проверьте вашу почту для подтверждения email.')
|
|
||||||
return redirect('accounts:login')
|
|
||||||
else:
|
|
||||||
form = CustomUserCreationForm()
|
|
||||||
|
|
||||||
return render(request, 'register.html', {'form': form})
|
|
||||||
|
|
||||||
|
|
||||||
def register_view(request):
|
|
||||||
if request.method == 'POST':
|
|
||||||
form = CustomUserCreationForm(request.POST)
|
|
||||||
if form.is_valid():
|
|
||||||
user = form.save(commit=False)
|
|
||||||
user.is_active = False # Пользователь не активен до подтверждения email
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
# Отправляем письмо с подтверждением (выводим в консоль)
|
|
||||||
confirmation_url = request.build_absolute_uri(
|
|
||||||
f'/accounts/confirm/{user.email_confirmation_token}/'
|
|
||||||
)
|
|
||||||
|
|
||||||
subject = 'Подтверждение Email'
|
|
||||||
message = f'Привет {user.name}!\n\nДля подтверждения вашего email перейдите по следующей ссылке: {confirmation_url}\n\nСпасибо за регистрацию!'
|
|
||||||
from_email = 'noreply@example.com' # Используем значение из настроек
|
|
||||||
recipient_list = [user.email]
|
|
||||||
|
|
||||||
# Выводим письмо в консоль, как вы просили
|
|
||||||
print(f"Письмо для подтверждения:\nТема: {subject}\nСообщение:\n{message}\nПолучатель: {recipient_list}")
|
|
||||||
|
|
||||||
messages.success(request, 'Пожалуйста, проверьте вашу почту для подтверждения email.')
|
|
||||||
return redirect('accounts:login') # Перенаправляем на страницу входа после регистрации
|
|
||||||
else:
|
|
||||||
form = CustomUserCreationForm()
|
|
||||||
|
|
||||||
return render(request, 'register.html', {'form': form})
|
|
||||||
|
|
||||||
|
|
||||||
def login_view(request):
|
def login_view(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
email = request.POST.get('email')
|
email = request.POST.get('email')
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
{% block title %}Регистрация / Вход{% endblock %}
|
{% block title %}Вход{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<!-- Контейнер для сообщений об ошибках - фиксированное место -->
|
<!-- Контейнер для сообщений об ошибках - фиксированное место -->
|
||||||
@@ -20,44 +20,10 @@
|
|||||||
|
|
||||||
<h2 class="text-center mb-4">Добро пожаловать</h2>
|
<h2 class="text-center mb-4">Добро пожаловать</h2>
|
||||||
|
|
||||||
<!-- Вкладки для переключения между регистрацией и входом -->
|
|
||||||
<ul class="nav nav-tabs mb-4">
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link {% if not request.GET.tab or request.GET.tab == 'register' %}active{% endif %}" data-bs-toggle="tab" href="#register">Регистрация</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link {% if request.GET.tab == 'login' %}active{% endif %}" data-bs-toggle="tab" href="#login">Вход</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<!-- Содержимое вкладок -->
|
<!-- Содержимое вкладок -->
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<!-- Вкладка регистрации -->
|
|
||||||
<div class="tab-pane fade {% if not request.GET.tab or request.GET.tab == 'register' %}show active{% endif %}" id="register">
|
|
||||||
<form method="post" action="{% url 'accounts:register' %}">
|
|
||||||
{% csrf_token %}
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="{{ form.name.id_for_label }}" class="form-label">Имя</label>
|
|
||||||
{{ form.name }}
|
|
||||||
{% if form.name.errors %}
|
|
||||||
<div class="text-danger">{{ form.name.errors }}</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="{{ form.email.id_for_label }}" class="form-label">Email</label>
|
|
||||||
{{ form.email }}
|
|
||||||
{% if form.email.errors %}
|
|
||||||
<div class="text-danger">{{ form.email.errors }}</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% include 'accounts/password_input.html' with field_name=form.password1.id_for_label field_label='Пароль' required=True field_errors=form.password1.errors %}
|
|
||||||
{% include 'accounts/password_input.html' with field_name=form.password2.id_for_label field_label='Подтверждение пароля' required=True field_errors=form.password2.errors %}
|
|
||||||
<button type="submit" class="btn btn-primary w-100">Зарегистрироваться</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Вкладка входа -->
|
<!-- Вкладка входа -->
|
||||||
<div class="tab-pane fade {% if request.GET.tab == 'login' %}show active{% endif %}" id="login">
|
<div class="tab-pane fade show active" id="login">
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@@ -104,17 +70,6 @@
|
|||||||
<script>
|
<script>
|
||||||
// Управление вкладками
|
// Управление вкладками
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
const tab = urlParams.get('tab');
|
|
||||||
|
|
||||||
if (tab === 'login') {
|
|
||||||
// Переключаемся на вкладку входа
|
|
||||||
const loginTab = document.querySelector('a[href="#login"]');
|
|
||||||
if(loginTab) {
|
|
||||||
bootstrap.Tab.getOrCreateInstance(loginTab).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Добавляем обработчик для показа/скрытия пароля
|
// Добавляем обработчик для показа/скрытия пароля
|
||||||
document.querySelectorAll('.show-password-btn').forEach(button => {
|
document.querySelectorAll('.show-password-btn').forEach(button => {
|
||||||
button.addEventListener('click', function() {
|
button.addEventListener('click', function() {
|
||||||
|
|||||||
@@ -81,13 +81,10 @@
|
|||||||
<a class="btn btn-outline-secondary ms-2" href="{% url 'accounts:logout' %}">Выйти</a>
|
<a class="btn btn-outline-secondary ms-2" href="{% url 'accounts:logout' %}">Выйти</a>
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<!-- Кнопки входа и регистрации для неавторизованных пользователей -->
|
<!-- Кнопка входа для неавторизованных пользователей -->
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="btn btn-outline-primary me-2" href="{% url 'accounts:login' %}">Вход</a>
|
<a class="btn btn-outline-primary me-2" href="{% url 'accounts:login' %}">Вход</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
|
||||||
<a class="btn btn-outline-secondary" href="{% url 'accounts:register' %}">Регистрация</a>
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% block title %}Регистрация{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="container">
|
|
||||||
<div class="form-container">
|
|
||||||
<h2 class="text-center mb-4">Регистрация</h2>
|
|
||||||
|
|
||||||
<div class="tab-content">
|
|
||||||
<div class="tab-pane fade show active" id="register">
|
|
||||||
<form method="post" action="{% url 'accounts:register' %}">
|
|
||||||
{% csrf_token %}
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="{{ form.name.id_for_label }}" class="form-label">Имя</label>
|
|
||||||
{{ form.name }}
|
|
||||||
{% if form.name.errors %}
|
|
||||||
<div class="text-danger">{{ form.name.errors }}</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<label for="{{ form.email.id_for_label }}" class="form-label">Email</label>
|
|
||||||
{{ form.email }}
|
|
||||||
{% if form.email.errors %}
|
|
||||||
<div class="text-danger">{{ form.email.errors }}</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
{% include 'accounts/password_input.html' with field_name=form.password1.id_for_label field_label='Пароль' required=True field_errors=form.password1.errors %}
|
|
||||||
{% include 'accounts/password_input.html' with field_name=form.password2.id_for_label field_label='Подтверждение пароля' required=True field_errors=form.password2.errors %}
|
|
||||||
<button type="submit" class="btn btn-primary w-100">Зарегистрироваться</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<!-- Ссылка на вход -->
|
|
||||||
<div class="text-center mt-3">
|
|
||||||
<a href="{% url 'accounts:login' %}" class="text-decoration-none">Уже есть аккаунт? Войти</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
||||||
Reference in New Issue
Block a user