feat: custom forms for accounts
This commit is contained in:
parent
cf59847af1
commit
cd039a8d21
@ -33,13 +33,13 @@ CSRF_TRUSTED_ORIGINS = ['https://' + os.getenv('DOMAIN', 'localhost')]
|
|||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
|
'later42',
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'later42',
|
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'rest_framework.authtoken',
|
'rest_framework.authtoken',
|
||||||
]
|
]
|
||||||
@ -162,6 +162,8 @@ URLS_PER_PAGE = 20
|
|||||||
READABILITY_HOST = os.getenv('READABILITY_HOST', None)
|
READABILITY_HOST = os.getenv('READABILITY_HOST', None)
|
||||||
|
|
||||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||||
|
if DEBUG:
|
||||||
|
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||||
EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS', False)
|
EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS', False)
|
||||||
EMAIL_HOST = os.getenv('EMAIL_HOST', 'smtp')
|
EMAIL_HOST = os.getenv('EMAIL_HOST', 'smtp')
|
||||||
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER', None)
|
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER', None)
|
||||||
|
@ -24,6 +24,13 @@
|
|||||||
{{ user.email }}
|
{{ user.email }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row align-items-start">
|
||||||
|
<div class="col">
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
<a href="{% url 'password_change' %}">Сменить пароль</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p> </p>
|
<p> </p>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{% autoescape off %}
|
{% autoescape off %}
|
||||||
Привет, {{ user.username }}.
|
Привет, {{ user.username }}.
|
||||||
|
|
||||||
Ссылка для активации аккаунта:
|
Ссылка для активации аккаунта:
|
||||||
https://{{ domain }}{% url 'activate' uidb64=uid token=token %}
|
https://{{ domain }}{% url 'activate' uidb64=uid token=token %}
|
||||||
{% endautoescape %}
|
{% endautoescape %}
|
@ -5,8 +5,14 @@
|
|||||||
<form method="post">
|
<form method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
<button class="btn btn-primary text-uppercase" type="submit">Войти</button>
|
<div class="d-flex justify-content-between">
|
||||||
|
<div class="p-2">
|
||||||
|
<button class="btn btn-primary text-uppercase" type="submit">Войти</button>
|
||||||
|
</div>
|
||||||
|
<div class="p-2">
|
||||||
|
<a href={% url 'password_reset' %} class="btn btn-primary text-uppercase">Забыл пароль</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<br />
|
<br />
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
6
later42/templates/registration/password_change_done.html
Normal file
6
later42/templates/registration/password_change_done.html
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<p>Пароль успешно изменен.</p>
|
||||||
|
<p>Перейти в <a href="{% url 'profile' %}">Профиль</a>.</p>
|
||||||
|
{% endblock %}
|
14
later42/templates/registration/password_change_form.html
Normal file
14
later42/templates/registration/password_change_form.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h4 class="card-title">Смена пароля</h4>
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit" class="btn btn-primary btn-block">Сменить</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -0,0 +1,6 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<p>Пароль успешно изменен.</p>
|
||||||
|
<p>Вы можете <a href="{% url 'login' %}">войти</a>.</p>
|
||||||
|
{% endblock %}
|
32
later42/templates/registration/password_reset_confirm.html
Normal file
32
later42/templates/registration/password_reset_confirm.html
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% if validlink %}
|
||||||
|
<p>Введите новый пароль.</p>
|
||||||
|
<form action="" method="post">
|
||||||
|
<div style="display:none">
|
||||||
|
<input type="hidden" value="{{ csrf_token }}" name="csrfmiddlewaretoken">
|
||||||
|
</div>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>{{ form.new_password1.errors }}
|
||||||
|
<label for="id_new_password1">Новый пароль:</label></td>
|
||||||
|
<td>{{ form.new_password1 }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ form.new_password2.errors }}
|
||||||
|
<label for="id_new_password2">Подтверждение:</label></td>
|
||||||
|
<td>{{ form.new_password2 }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td><input type="submit" value="Сменить" /></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<h1>Сброс пароля прошел неудачно</h1>
|
||||||
|
<p>Ссылка неверная или уже была использована.<br />
|
||||||
|
Попробуйте сбросить пароль еще раз.</p>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
6
later42/templates/registration/password_reset_done.html
Normal file
6
later42/templates/registration/password_reset_done.html
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<p>Сообщение успешно отправлено.</p>
|
||||||
|
<p>Вы должны получить его в скором времени.</p>
|
||||||
|
{% endblock %}
|
14
later42/templates/registration/password_reset_form.html
Normal file
14
later42/templates/registration/password_reset_form.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<h4 class="card-title">Reset your password</h4>
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit" class="btn btn-primary btn-block">Reset</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -17,11 +17,11 @@ from django.contrib import admin
|
|||||||
|
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.views import LoginView
|
# from django.contrib.auth import views
|
||||||
|
|
||||||
from rest_framework import routers, serializers, viewsets
|
from rest_framework import routers, serializers, viewsets
|
||||||
|
|
||||||
from later42.forms import CustomLoginForm
|
# from later42.forms import CustomLoginForm
|
||||||
from later42.views import account_activation, index, profile, api, api_token, reader, signup, about
|
from later42.views import account_activation, index, profile, api, api_token, reader, signup, about
|
||||||
|
|
||||||
|
|
||||||
@ -44,9 +44,7 @@ urlpatterns = [
|
|||||||
path('signup/', signup.register, name='signup'),
|
path('signup/', signup.register, name='signup'),
|
||||||
path(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
|
path(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
|
||||||
account_activation.activate, name='activate'),
|
account_activation.activate, name='activate'),
|
||||||
path("accounts/login/",
|
path('accounts/', include('django.contrib.auth.urls')),
|
||||||
LoginView.as_view(authentication_form=CustomLoginForm), name="login"),
|
|
||||||
path("accounts/", include("django.contrib.auth.urls")),
|
|
||||||
path('profile/', profile.get, name='profile'),
|
path('profile/', profile.get, name='profile'),
|
||||||
path('api/url/', api.URL.as_view(), name='urls'),
|
path('api/url/', api.URL.as_view(), name='urls'),
|
||||||
path('delete/<int:url_id>', index.delete, name='delete'),
|
path('delete/<int:url_id>', index.delete, name='delete'),
|
||||||
|
@ -15,18 +15,14 @@ def register(request):
|
|||||||
form = SignUpForm(request.POST)
|
form = SignUpForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
user = form.save(commit=False)
|
user = form.save(commit=False)
|
||||||
# user.refresh_from_db()
|
|
||||||
user.is_active = False
|
user.is_active = False
|
||||||
user.save()
|
user.save()
|
||||||
raw_password = form.cleaned_data.get('password1')
|
raw_password = form.cleaned_data.get('password1')
|
||||||
|
|
||||||
current_site = get_current_site(request)
|
current_site = get_current_site(request)
|
||||||
|
|
||||||
# user = authenticate(username=user.username, password=raw_password)
|
|
||||||
# login(request, user)
|
|
||||||
|
|
||||||
mail_subject = 'Later42: Активация аккаунта'
|
mail_subject = 'Later42: Активация аккаунта'
|
||||||
message = render_to_string('email_activation.html', {
|
message = render_to_string('registration/email_activation.html', {
|
||||||
'user': user,
|
'user': user,
|
||||||
'domain': current_site.domain,
|
'domain': current_site.domain,
|
||||||
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
|
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
|
||||||
@ -39,7 +35,7 @@ def register(request):
|
|||||||
)
|
)
|
||||||
email.send()
|
email.send()
|
||||||
|
|
||||||
return render(request, 'email_sent.html')
|
return render(request, 'registration/email_sent.html')
|
||||||
else:
|
else:
|
||||||
form = SignUpForm()
|
form = SignUpForm()
|
||||||
return render(request, 'signup.html', {'form': form})
|
return render(request, 'registration/signup.html', {'form': form})
|
||||||
|
Loading…
Reference in New Issue
Block a user