|
|
|
|
@ -1,33 +1,30 @@ |
|
|
|
|
import os |
|
|
|
|
|
|
|
|
|
import logging |
|
|
|
|
from uuid import uuid4 |
|
|
|
|
from urllib.parse import urlsplit |
|
|
|
|
|
|
|
|
|
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, Http404 |
|
|
|
|
from django.http import JsonResponse |
|
|
|
|
from django.urls import reverse_lazy |
|
|
|
|
from django.utils.decorators import method_decorator |
|
|
|
|
from django.views.decorators.csrf import csrf_exempt |
|
|
|
|
from django.views.generic import FormView, View, TemplateView |
|
|
|
|
from django.views.generic.edit import BaseFormView |
|
|
|
|
from django.shortcuts import redirect |
|
|
|
|
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 .tokens import verification_email_token |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
User = get_user_model() |
|
|
|
|
import logging |
|
|
|
|
logger_roistat = logging.getLogger('roistat') |
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LearnerRegistrationView(FormView): |
|
|
|
|
@ -41,14 +38,11 @@ class LearnerRegistrationView(FormView): |
|
|
|
|
last_name = form.cleaned_data['last_name'] |
|
|
|
|
email = form.cleaned_data['email'].lower() |
|
|
|
|
password = form.cleaned_data['password'] |
|
|
|
|
logger_roistat.debug('start registration %s' % email) |
|
|
|
|
|
|
|
|
|
user, created = User.objects.get_or_create( |
|
|
|
|
email=email, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
logger_roistat.debug('user created %s' % created) |
|
|
|
|
|
|
|
|
|
if not created: |
|
|
|
|
if self.request.is_ajax(): |
|
|
|
|
return JsonResponse({ |
|
|
|
|
@ -66,16 +60,13 @@ class LearnerRegistrationView(FormView): |
|
|
|
|
|
|
|
|
|
user.set_password(password) |
|
|
|
|
user.save() |
|
|
|
|
logger_roistat.debug('user saved, id %s' % user.id) |
|
|
|
|
referrer = self.request.session.get('referrer') |
|
|
|
|
if referrer: |
|
|
|
|
logger_roistat.debug('referrer %s' % referrer) |
|
|
|
|
Referral.objects.create(referral=user, referrer_id=referrer, bonus=config.REFERRAL_BONUS, |
|
|
|
|
referrer_bonus=config.REFERRER_BONUS) |
|
|
|
|
# TODO: email admins? мб реферера уже нет, старая ссылка |
|
|
|
|
self.request.session['referrer'] = None |
|
|
|
|
login(self.request, user) |
|
|
|
|
logger_roistat.debug('login ok') |
|
|
|
|
|
|
|
|
|
# fixme: change email text |
|
|
|
|
# fixme: async send email |
|
|
|
|
@ -83,12 +74,10 @@ class LearnerRegistrationView(FormView): |
|
|
|
|
http_referer = str(http_referer[0]) + '://' + str(http_referer[1]) |
|
|
|
|
token = verification_email_token.make_token(user) |
|
|
|
|
url = http_referer + str(reverse_lazy('lilcity:verification-email', args=[token, user.id])) |
|
|
|
|
logger_roistat.debug('now send email') |
|
|
|
|
try: |
|
|
|
|
send_email('Вы успешно прошли регистрацию', email, "notification/email/verification_email.html", url=url, config=config) |
|
|
|
|
except Exception as e: |
|
|
|
|
logger_roistat.error(str(e) + '\nmessage ' + getattr(e, 'message', '')) |
|
|
|
|
logger_roistat.debug('email sent, end reg') |
|
|
|
|
logger.error(str(e)) |
|
|
|
|
|
|
|
|
|
if self.request.is_ajax(): |
|
|
|
|
return JsonResponse({"success": True}, status=201) |
|
|
|
|
|