Email on zendesk exist check
This commit is contained in:
parent
16fd0e3983
commit
729c0bec7e
@ -15,15 +15,15 @@ Including another URLconf
|
|||||||
"""
|
"""
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
|
|
||||||
from access_controller import settings
|
from access_controller import settings
|
||||||
from main.views import *
|
from main.views import *
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls, name='admin'),
|
path('admin/', admin.site.urls, name='admin'),
|
||||||
path('register/', Reg.as_view(), name='registration'),
|
path('register/', CustomRegistrationView.as_view(), name='registration'),
|
||||||
path('admin/', admin.site.urls),
|
path('', include('django_registration.backends.one_step.urls')),
|
||||||
path('profile/', profile_page, name="Profile"),
|
path('profile/', profile_page, name='profile'),
|
||||||
]
|
]
|
||||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
@ -2,9 +2,9 @@ from main.models import UserProfile
|
|||||||
|
|
||||||
|
|
||||||
# Дополнительные функции
|
# Дополнительные функции
|
||||||
def set_and_get_username(UP: UserProfile): # TODO: Переделать с получением данных через API
|
def set_and_get_name(UP: UserProfile): # TODO: Переделать с получением данных через API
|
||||||
"""
|
"""
|
||||||
Функция устанавливает поле :class:`user.username` текущим именем в Zendesk
|
Функция устанавливает поле :class:`username` текущим именем в Zendesk
|
||||||
|
|
||||||
:param UP: Объект профиля пользователя
|
:param UP: Объект профиля пользователя
|
||||||
:type UP: :class:`main.models.UserProfile`
|
:type UP: :class:`main.models.UserProfile`
|
||||||
|
18
main/migrations/0002_userprofile_name.py
Normal file
18
main/migrations/0002_userprofile_name.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.1.6 on 2021-02-08 16:15
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='userprofile',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(default='None', max_length=100),
|
||||||
|
),
|
||||||
|
]
|
@ -8,3 +8,4 @@ class UserProfile(models.Model):
|
|||||||
user = models.OneToOneField(to=User, on_delete=models.CASCADE)
|
user = models.OneToOneField(to=User, on_delete=models.CASCADE)
|
||||||
role = models.IntegerField()
|
role = models.IntegerField()
|
||||||
image = models.ImageField(upload_to='user_avatars')
|
image = models.ImageField(upload_to='user_avatars')
|
||||||
|
name = models.CharField(default='None', max_length=100)
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Title</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
NIce
|
|
||||||
</body>
|
|
||||||
</html>
|
|
15
main/templates/django_registration/registration_closed.html
Normal file
15
main/templates/django_registration/registration_closed.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 %}
|
@ -0,0 +1,14 @@
|
|||||||
|
{% extends 'base/base.html' %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Регистрация завершена
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block heading %}
|
||||||
|
Регистрация
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<br>
|
||||||
|
<h4> Регистрация прошла успешно. <a href="{% url 'login' %}">Войти сейчас</a></h4>
|
||||||
|
{% endblock %}
|
@ -1,20 +1,24 @@
|
|||||||
<!DOCTYPE html>
|
{% extends 'base/base.html' %}
|
||||||
<html lang="en">
|
{% load static %}
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Title</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Регистрация</h1>
|
|
||||||
<form method="post" action="">
|
|
||||||
{% csrf_token %}
|
|
||||||
{% for field in form %}
|
|
||||||
{{ field.label_tag }}
|
|
||||||
{{ field }}
|
|
||||||
<br>
|
|
||||||
{% if field.errors %}<div class="myerrors clearfix">{{ field.errors }}</div>{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
<input type="submit" value="Зарегистрироваться" class="clearfix">
|
{% block title %}
|
||||||
</body>
|
Регистрация
|
||||||
</html>
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block heading %}
|
||||||
|
Регистрация
|
||||||
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<form method="post" action="">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% for field in form %}
|
||||||
|
{{ field.label_tag }}
|
||||||
|
{{ field }}
|
||||||
|
<br>
|
||||||
|
{% if field.errors %}
|
||||||
|
<span>{{ field.errors }}</span>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
<input type="submit" value="Зарегистрироваться" class="clearfix">
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
@ -1,26 +1,25 @@
|
|||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
|
||||||
from main.extra_func import set_and_get_username, set_and_get_email, load_and_get_image, set_and_get_role
|
from main.extra_func import set_and_get_name, set_and_get_email, load_and_get_image, set_and_get_role
|
||||||
from main.models import UserProfile
|
from main.models import UserProfile
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.urls import reverse_lazy
|
|
||||||
from django_registration.forms import RegistrationFormUniqueEmail
|
from django_registration.forms import RegistrationFormUniqueEmail
|
||||||
from django_registration.views import RegistrationView
|
from django_registration.views import RegistrationView
|
||||||
from zenpy import Zenpy
|
from zenpy import Zenpy
|
||||||
|
|
||||||
from main.models import UserProfile
|
|
||||||
|
|
||||||
|
class CustomRegistrationView(RegistrationView):
|
||||||
class Reg(RegistrationView):
|
|
||||||
form_class = RegistrationFormUniqueEmail
|
form_class = RegistrationFormUniqueEmail
|
||||||
template_name = 'django_registration/registration_form.html'
|
template_name = 'django_registration/registration_form.html'
|
||||||
|
success_url = reverse_lazy('django_registration_complete')
|
||||||
|
|
||||||
def register(self, form):
|
def register(self, form):
|
||||||
creds = {
|
creds = {
|
||||||
'email': 'DEFINEME',
|
'email': 'idar.sokurov.05@mail.ru',
|
||||||
'subdomain': 'ngenix1612197338',
|
'subdomain': 'ngenix1612197338',
|
||||||
'token': 'DEFINEME',
|
'token': 'xRL9Qqz7svFE3X9cHMVC2zOtJUdllzr441C3Z363',
|
||||||
}
|
}
|
||||||
client = Zenpy(**creds)
|
client = Zenpy(**creds)
|
||||||
zenpy_user = client.search(form.data['email'], type='user')
|
zenpy_user = client.search(form.data['email'], type='user')
|
||||||
@ -28,16 +27,20 @@ class Reg(RegistrationView):
|
|||||||
user = User.objects.create_user(
|
user = User.objects.create_user(
|
||||||
username=form.data['username'],
|
username=form.data['username'],
|
||||||
email=form.data['email'],
|
email=form.data['email'],
|
||||||
password=form.data['email'],
|
password=form.data['password1']
|
||||||
)
|
)
|
||||||
profile = UserProfile.objects.create(
|
profile = UserProfile(
|
||||||
image='None.png',
|
image='None.png',
|
||||||
user=user,
|
user=user,
|
||||||
role='None'
|
role=0,
|
||||||
)
|
)
|
||||||
user.save()
|
set_and_get_name(profile)
|
||||||
|
set_and_get_email(profile)
|
||||||
|
set_and_get_role(profile)
|
||||||
|
load_and_get_image(profile)
|
||||||
|
profile.save()
|
||||||
else:
|
else:
|
||||||
raise AttributeError('No such email')
|
self.success_url = reverse_lazy('django_registration_disallowed')
|
||||||
|
|
||||||
|
|
||||||
def profile_page(request):
|
def profile_page(request):
|
||||||
@ -53,7 +56,7 @@ def profile_page(request):
|
|||||||
else: # TODO: Убрать после появления регистрации и авторизации, добавить login_required()
|
else: # TODO: Убрать после появления регистрации и авторизации, добавить login_required()
|
||||||
UP = UserProfile.objects.get(user=1)
|
UP = UserProfile.objects.get(user=1)
|
||||||
context = {
|
context = {
|
||||||
'name': set_and_get_username(UP),
|
'name': set_and_get_name(UP),
|
||||||
'email': set_and_get_email(UP),
|
'email': set_and_get_email(UP),
|
||||||
'role': set_and_get_role(UP),
|
'role': set_and_get_role(UP),
|
||||||
'image_name': load_and_get_image(UP),
|
'image_name': load_and_get_image(UP),
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
# Engine
|
# Engine
|
||||||
Django==3.1.6
|
Django==3.1.6
|
||||||
Pillow==8.1.0
|
Pillow==8.1.0
|
||||||
|
zenpy~=2.0.24
|
||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
Sphinx==3.4.3
|
Sphinx==3.4.3
|
||||||
sphinx-rtd-theme==0.5.1
|
sphinx-rtd-theme==0.5.1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user