Add first version registration
This commit is contained in:
parent
2919761b2f
commit
b8e3d11c6f
@ -37,6 +37,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
'django_registration',
|
||||||
'main',
|
'main',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -16,6 +16,9 @@ Including another URLconf
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
|
from main.views import Reg
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls, name='admin'),
|
||||||
|
path('register/', Reg.as_view(), name='registration'),
|
||||||
]
|
]
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
NIce
|
||||||
|
</body>
|
||||||
|
</html>
|
20
main/templates/django_registration/registration_form.html
Normal file
20
main/templates/django_registration/registration_form.html
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<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">
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,3 +1,38 @@
|
|||||||
from django.shortcuts import render
|
|
||||||
|
|
||||||
# Create your views here.
|
# 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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user