|
|
|
|
@ -1,14 +1,17 @@ |
|
|
|
|
import string |
|
|
|
|
|
|
|
|
|
import os |
|
|
|
|
import logging |
|
|
|
|
from uuid import uuid4 |
|
|
|
|
from urllib.parse import urlsplit |
|
|
|
|
from urllib.parse import urlsplit, urlencode |
|
|
|
|
|
|
|
|
|
from django.db.models import Q |
|
|
|
|
from facepy import GraphAPI |
|
|
|
|
from facepy.exceptions import FacepyError |
|
|
|
|
from django.contrib.auth import get_user_model, logout, login, views |
|
|
|
|
from django.contrib.auth.forms import AuthenticationForm |
|
|
|
|
from django.core.files.base import ContentFile |
|
|
|
|
from django.http import JsonResponse |
|
|
|
|
from django.http import JsonResponse, HttpResponse |
|
|
|
|
from django.urls import reverse_lazy |
|
|
|
|
from django.utils.decorators import method_decorator |
|
|
|
|
from django.views.decorators.csrf import csrf_exempt |
|
|
|
|
@ -19,7 +22,7 @@ from django.conf import settings |
|
|
|
|
from apps.notification.utils import send_email |
|
|
|
|
from apps.config.models import Config |
|
|
|
|
from apps.user.models import Referral |
|
|
|
|
from .forms import LearnerRegistrationForm |
|
|
|
|
from .forms import LearnerRegistrationForm, LandingRegistrationForm |
|
|
|
|
from .tokens import verification_email_token |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -239,3 +242,42 @@ class FacebookLoginOrRegistration(View): |
|
|
|
|
login(requests, user=user) |
|
|
|
|
self.request.session['referrer'] = None |
|
|
|
|
return JsonResponse({"success": True}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LandingRegistrationView(View): |
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs): |
|
|
|
|
form = LandingRegistrationForm(request.POST) |
|
|
|
|
if not form.is_valid(): |
|
|
|
|
return HttpResponse(form.errors.as_text()) |
|
|
|
|
phone = form.cleaned_data['phone'] |
|
|
|
|
name = form.cleaned_data['name'].split() |
|
|
|
|
email = form.cleaned_data['email'].lower() |
|
|
|
|
|
|
|
|
|
if User.objects.filter(Q(email=email) | Q(phone=phone)).count(): |
|
|
|
|
return redirect('/p/user-exists') |
|
|
|
|
|
|
|
|
|
user = User( |
|
|
|
|
username=email, |
|
|
|
|
email=email, |
|
|
|
|
phone=phone, |
|
|
|
|
) |
|
|
|
|
user.first_name = name[0] |
|
|
|
|
if len(name) > 1: |
|
|
|
|
user.last_name = name[1] |
|
|
|
|
password = User.objects.make_random_password(8, string.ascii_lowercase + string.digits) |
|
|
|
|
user.set_password(password) |
|
|
|
|
user.save() |
|
|
|
|
|
|
|
|
|
verification_token = verification_email_token.make_token(user) |
|
|
|
|
url = 'https://%s%s?%s' % (settings.MAIN_HOST, |
|
|
|
|
reverse_lazy('lilcity:verification-email', args=[verification_token, user.id]), |
|
|
|
|
urlencode({'next': 'https://lil.school/p/free-lesson'})) |
|
|
|
|
try: |
|
|
|
|
send_email('Регистрация в Lil School', email, "notification/email/landing_registration.html", url=url, |
|
|
|
|
user=user, password=password) |
|
|
|
|
except Exception as e: |
|
|
|
|
logger.error(str(e)) |
|
|
|
|
|
|
|
|
|
return redirect(url) |
|
|
|
|
|
|
|
|
|
|