2021-02-08 20:12:24 +03:00

66 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.shortcuts import render, redirect
from django.urls import reverse_lazy
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 django.contrib.auth.models import User
from django_registration.forms import RegistrationFormUniqueEmail
from django_registration.views import RegistrationView
from zenpy import Zenpy
class CustomRegistrationView(RegistrationView):
form_class = RegistrationFormUniqueEmail
template_name = 'django_registration/registration_form.html'
success_url = reverse_lazy('django_registration_complete')
def register(self, form):
creds = {
'email': 'idar.sokurov.05@mail.ru',
'subdomain': 'ngenix1612197338',
'token': 'xRL9Qqz7svFE3X9cHMVC2zOtJUdllzr441C3Z363',
}
client = Zenpy(**creds)
zenpy_user = client.search(form.data['email'], type='user')
if zenpy_user:
user = User.objects.create_user(
username=form.data['username'],
email=form.data['email'],
password=form.data['password1']
)
profile = UserProfile(
image='None.png',
user=user,
role=0,
)
set_and_get_name(profile)
set_and_get_email(profile)
set_and_get_role(profile)
load_and_get_image(profile)
profile.save()
else:
self.success_url = reverse_lazy('django_registration_disallowed')
def profile_page(request):
"""
Отображение страницы профиля
:param request: объект с деталями запроса
:type request: :class:`django.http.HttpResponse`
:return: объект ответа сервера с HTML-кодом внутри
"""
if request.user.is_authenticated:
UP = UserProfile.objects.get(user=request.user)
else: # TODO: Убрать после появления регистрации и авторизации, добавить login_required()
UP = UserProfile.objects.get(user=1)
context = {
'name': set_and_get_name(UP),
'email': set_and_get_email(UP),
'role': set_and_get_role(UP),
'image_name': load_and_get_image(UP),
'pagename': 'Страница профиля'
}
return render(request, 'pages/profile.html', context)