fix bug, update registration
This commit is contained in:
parent
e955dfab99
commit
8b512afadb
@ -51,8 +51,14 @@ MIDDLEWARE = [
|
||||
|
||||
ROOT_URLCONF = 'access_controller.urls'
|
||||
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
EMAIL_HOST = 'smtp.mail.ru'
|
||||
EMAIL_PORT = 2525
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_HOST_USER = 'djgr.02@mail.ru'
|
||||
EMAIL_HOST_PASSWORD = 'djangogroup02'
|
||||
SERVER_EMAIL = EMAIL_HOST_USER
|
||||
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
|
@ -22,26 +22,12 @@ class ZendeskAdmin:
|
||||
def check_user(self, email: str) -> bool:
|
||||
return True if self.admin.search(email, type='user') else False
|
||||
|
||||
def get_user_name(self, email: str) -> str:
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.name
|
||||
|
||||
def get_user_role(self, email: str) -> str:
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.role
|
||||
|
||||
def get_user_id(self, email: str) -> str:
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.id
|
||||
def get_user(self, email: str) -> str:
|
||||
return self.admin.users.search(email).values[0]
|
||||
|
||||
def get_user_org(self, email: str) -> str:
|
||||
user = self.admin.users.search(email).values[0]
|
||||
print(user)
|
||||
return user.organization
|
||||
|
||||
def get_user_image(self, email: str) -> str:
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.photo['content_url'] if user.photo else None
|
||||
return user.organization.name
|
||||
|
||||
def create_admin(self) -> None:
|
||||
if self.email is None:
|
||||
@ -68,9 +54,10 @@ def update_profile(user_profile: UserProfile):
|
||||
:param user_profile: Объект профиля пользователя
|
||||
:type user_profile: :class:`main.models.UserProfile`
|
||||
"""
|
||||
user_profile.name = ZendeskAdmin().get_user_name(user_profile.user.email)
|
||||
user_profile.role = ZendeskAdmin().get_user_role(user_profile.user.email)
|
||||
user_profile.image = ZendeskAdmin().get_user_image(user_profile.user.email)
|
||||
user = ZendeskAdmin().get_user(user_profile.user.email)
|
||||
user_profile.name = user.name
|
||||
user_profile.role = user.role
|
||||
user_profile.image = user.photo['content_url'] if user.photo else None
|
||||
user_profile.save()
|
||||
|
||||
|
||||
|
@ -11,5 +11,5 @@
|
||||
|
||||
{% block content %}
|
||||
<br>
|
||||
<h4> Нет пользователя с указаным адресом электронной почты, либо был введён неверный пароль</h4>
|
||||
<h4> Нет пользователя с указаным адресом электронной почты.</h4>
|
||||
{% endblock %}
|
||||
|
@ -1,3 +0,0 @@
|
||||
Someone asked for password reset for email {{ email }}. Follow thelink below:
|
||||
{{ protocol }}://{{ domain }}{% url "password_reset_confirm" uidb64=uid token=token %}
|
||||
Your username, in case you've forgotten: {{ user.get_username }}
|
@ -1,16 +1,14 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.forms import PasswordResetForm
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.tokens import default_token_generator
|
||||
from django.contrib.auth.views import PasswordResetView
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse_lazy
|
||||
from django_registration.backends.one_step.views import RegistrationView
|
||||
|
||||
from main.extra_func import check_user_exist, check_user_auth, update_profile, get_user_organization
|
||||
from main.models import UserProfile
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from access_controller.settings import EMAIL_HOST_USER
|
||||
from main.extra_func import check_user_exist, update_profile, get_user_organization
|
||||
from main.forms import CustomRegistrationForm
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
|
||||
class CustomRegistrationView(RegistrationView):
|
||||
@ -24,32 +22,29 @@ class CustomRegistrationView(RegistrationView):
|
||||
|
||||
def register(self, form):
|
||||
self.is_allowed = True
|
||||
|
||||
forms = PasswordResetForm(initial={'email': form.data['email']})
|
||||
if forms.is_valid():
|
||||
opts = {
|
||||
'use_https': self.request.is_secure(),
|
||||
'token_generator': default_token_generator,
|
||||
'from_email': form.data['email'],
|
||||
'email_template_name': 'registration/password_reset_email.html',
|
||||
'subject_template_name': 'registration/password_reset_subject.txt',
|
||||
'request': self.request,
|
||||
'html_email_template_name': None,
|
||||
'extra_email_context': None,
|
||||
}
|
||||
forms.full_clean()
|
||||
forms.save(**opts)
|
||||
|
||||
if get_user_organization(form.data['email']) == 'SYSTEM' and check_user_exist(form.data['email']):
|
||||
user = User.objects.create_user(
|
||||
username=form.data['email'],
|
||||
email=form.data['email'],
|
||||
)
|
||||
|
||||
f = PasswordResetView
|
||||
profile = user.userprofile
|
||||
update_profile(profile)
|
||||
return user
|
||||
if check_user_exist(form.data['email']) and get_user_organization(form.data['email']) == 'SYSTEM':
|
||||
forms = PasswordResetForm(self.request.POST)
|
||||
if forms.is_valid():
|
||||
opts = {
|
||||
'use_https': self.request.is_secure(),
|
||||
'token_generator': default_token_generator,
|
||||
'from_email': EMAIL_HOST_USER,
|
||||
'email_template_name': 'registration/password_reset_email.html',
|
||||
'subject_template_name': 'registration/password_reset_subject.txt',
|
||||
'request': self.request,
|
||||
'html_email_template_name': None,
|
||||
'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)
|
||||
)
|
||||
forms.save(**opts)
|
||||
update_profile(user.userprofile)
|
||||
return user
|
||||
else:
|
||||
raise ValueError('Непредвиденная ошибка')
|
||||
else:
|
||||
self.is_allowed = False
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user