Add new page if email has not sent
This commit is contained in:
parent
68b1f64d36
commit
8a0a1639fc
@ -17,28 +17,27 @@ from django.contrib import admin
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.urls import path, include
|
||||
|
||||
from main.views import main_page, profile_page, CustomRegistrationView, CustomLoginView
|
||||
from main.views import main_page, profile_page, CustomRegistrationView, CustomLoginView, registration_error
|
||||
from main.views import work_page, work_hand_over, work_become_engineer, \
|
||||
AdminPageView, statistic_page
|
||||
from main.urls import router
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls, name='admin'),
|
||||
path('', main_page, name='index'),
|
||||
path('accounts/profile/', profile_page, name='profile'),
|
||||
path('accounts/register/', CustomRegistrationView.as_view(), name='registration'),
|
||||
path('accounts/register/error/', registration_error, name='registration_email_error'),
|
||||
path('accounts/login/', CustomLoginView.as_view(), name='login'),
|
||||
path('accounts/', include('django.contrib.auth.urls')),
|
||||
path('accounts/', include('django_registration.backends.one_step.urls')),
|
||||
path('work/<int:id>', work_page, name="work"),
|
||||
path('work/hand_over/', work_hand_over, name="work_hand_over"),
|
||||
path('work/become_engineer/', work_become_engineer, name="work_become_engineer"),
|
||||
path('accounts/', include('django_registration.backends.activation.urls')),
|
||||
path('accounts/login/', include('django.contrib.auth.urls')),
|
||||
path('control/', AdminPageView.as_view(), name='control'),
|
||||
path('statistic/', statistic_page, name='statistic')
|
||||
]
|
||||
]
|
||||
|
||||
urlpatterns += [
|
||||
path(
|
||||
@ -47,7 +46,7 @@ urlpatterns += [
|
||||
name='password_reset'
|
||||
),
|
||||
path(
|
||||
'password-reset/done/',
|
||||
'password_reset/done/',
|
||||
auth_views.PasswordResetDoneView.as_view(),
|
||||
name='password_reset_done'
|
||||
),
|
||||
|
@ -11,5 +11,5 @@
|
||||
|
||||
{% block content %}
|
||||
<br>
|
||||
<h4> Нет пользователя с указаным адресом электронной почты либо произошла ошибка при отправке сообщения.</h4>
|
||||
<h4> Нет пользователя с указаным адресом электронной почты.</h4>
|
||||
{% endblock %}
|
||||
|
15
main/templates/django_registration/registration_error.html
Normal file
15
main/templates/django_registration/registration_error.html
Normal file
@ -0,0 +1,15 @@
|
||||
{% extends 'base/base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}
|
||||
Регистрация завершена
|
||||
{% endblock %}
|
||||
|
||||
{% block heading %}
|
||||
Регистрация
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<br>
|
||||
<h4> Произошла ошибка при отправке электронного сообщения.</h4>
|
||||
{% endblock %}
|
@ -24,7 +24,7 @@ from zenpy.lib.api_objects import User as ZenpyUser
|
||||
from access_controller.settings import EMAIL_HOST_USER, ZENDESK_ROLES, ZENDESK_MAX_AGENTS, ZENDESK_GROUPS
|
||||
from main.extra_func import check_user_exist, update_profile, get_user_organization, \
|
||||
make_engineer, make_light_agent, get_users_list, update_users_in_model, count_users, \
|
||||
StatisticData,ZendeskAdmin
|
||||
StatisticData, ZendeskAdmin
|
||||
from main.forms import AdminPageUsers, CustomRegistrationForm, CustomAuthenticationForm, StatisticForm
|
||||
from main.serializers import ProfileSerializer
|
||||
from .models import UserProfile
|
||||
@ -45,8 +45,12 @@ class CustomRegistrationView(RegistrationView):
|
||||
"""
|
||||
form_class = CustomRegistrationForm
|
||||
template_name = 'django_registration/registration_form.html'
|
||||
success_url = reverse_lazy('django_registration_complete')
|
||||
is_allowed = True
|
||||
urls = {
|
||||
'done': reverse_lazy('password_reset_done'),
|
||||
'invalid_zendesk_email': reverse_lazy('django_registration_disallowed'),
|
||||
'email_sending_error': reverse_lazy('registration_email_error'),
|
||||
}
|
||||
redirect_url = 'done'
|
||||
|
||||
def register(self, form: CustomRegistrationForm) -> User:
|
||||
"""
|
||||
@ -59,7 +63,7 @@ class CustomRegistrationView(RegistrationView):
|
||||
:param form: Email пользователя на Zendesk
|
||||
:return: user
|
||||
"""
|
||||
self.is_allowed = True
|
||||
self.redirect_url = 'done'
|
||||
if check_user_exist(form.data['email']) and get_user_organization(form.data['email']) == 'SYSTEM':
|
||||
forms = PasswordResetForm(self.request.POST)
|
||||
if forms.is_valid():
|
||||
@ -74,9 +78,9 @@ class CustomRegistrationView(RegistrationView):
|
||||
'extra_email_context': None,
|
||||
}
|
||||
user = User.objects.create_user(
|
||||
username=form.data['email'],
|
||||
email=form.data['email'],
|
||||
password=User.objects.make_random_password(length=50)
|
||||
username=form.data['email'],
|
||||
email=form.data['email'],
|
||||
password=User.objects.make_random_password(length=50)
|
||||
)
|
||||
try:
|
||||
update_profile(user.userprofile)
|
||||
@ -84,12 +88,11 @@ class CustomRegistrationView(RegistrationView):
|
||||
forms.save(**opts)
|
||||
return user
|
||||
except SMTPException:
|
||||
# user.delete()
|
||||
self.is_allowed = False
|
||||
self.redirect_url = 'email_sending_error'
|
||||
else:
|
||||
raise ValueError('Непредвиденная ошибка')
|
||||
else:
|
||||
self.is_allowed = False
|
||||
self.redirect_url = 'invalid_zendesk_email'
|
||||
|
||||
@staticmethod
|
||||
def set_permission(user: User) -> None:
|
||||
@ -106,7 +109,7 @@ class CustomRegistrationView(RegistrationView):
|
||||
)
|
||||
user.user_permissions.add(permission)
|
||||
|
||||
def get_success_url(self, user: User = None) -> success_url:
|
||||
def get_success_url(self, user: User = None):
|
||||
"""
|
||||
Функция возвращает url-адрес страницы, куда нужно перейти после успешной/не успешной регистрации.
|
||||
Используется самой django-registration.
|
||||
@ -114,10 +117,11 @@ class CustomRegistrationView(RegistrationView):
|
||||
:param user: пользователь, пытающийся зарегистрироваться
|
||||
:return: адресация на страницу успешной регистрации
|
||||
"""
|
||||
if self.is_allowed:
|
||||
return reverse_lazy('password_reset_done')
|
||||
else:
|
||||
return reverse_lazy('django_registration_disallowed')
|
||||
return self.urls[self.redirect_url]
|
||||
|
||||
|
||||
def registration_error(request):
|
||||
return render(request, 'django_registration/registration_error.html')
|
||||
|
||||
|
||||
@login_required()
|
||||
@ -232,7 +236,7 @@ def main_page(request):
|
||||
return render(request, 'pages/index.html')
|
||||
|
||||
|
||||
class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin,SuccessMessageMixin, FormView):
|
||||
class AdminPageView(LoginRequiredMixin, PermissionRequiredMixin, SuccessMessageMixin, FormView):
|
||||
"""
|
||||
Класс отображения страницы администратора.
|
||||
|
||||
@ -315,7 +319,6 @@ class UsersViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
})
|
||||
|
||||
|
||||
|
||||
@login_required()
|
||||
def statistic_page(request: WSGIRequest) -> HttpResponse:
|
||||
"""
|
||||
@ -325,7 +328,7 @@ def statistic_page(request: WSGIRequest) -> HttpResponse:
|
||||
:return: адресация на страницу статистики
|
||||
"""
|
||||
if not request.user.has_perm('main.has_control_access'):
|
||||
return PermissionDenied
|
||||
raise PermissionDenied
|
||||
context = {
|
||||
'pagename': 'страница статистики',
|
||||
'errors': list(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user