39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
# Create your views here.
|
|
from abc import ABC
|
|
|
|
from django.contrib.auth.models import User
|
|
from django.urls import reverse_lazy
|
|
from django_registration.forms import RegistrationFormUniqueEmail
|
|
from django_registration.views import RegistrationView
|
|
from zenpy import Zenpy
|
|
|
|
from main.models import UserProfile
|
|
|
|
|
|
class Reg(RegistrationView):
|
|
form_class = RegistrationFormUniqueEmail
|
|
template_name = 'django_registration/registration_form.html'
|
|
|
|
def register(self, form):
|
|
creds = {
|
|
'email': 'DEFINEME',
|
|
'subdomain': 'ngenix1612197338',
|
|
'token': 'DEFINEME',
|
|
}
|
|
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['email'],
|
|
)
|
|
profile=UserProfile.objects.create(
|
|
image='None.png',
|
|
user=user,
|
|
role='None'
|
|
)
|
|
user.save()
|
|
else:
|
|
raise AttributeError('No such email')
|