|
|
|
|
@ -1,13 +1,21 @@ |
|
|
|
|
from uuid import uuid4 |
|
|
|
|
|
|
|
|
|
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.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 |
|
|
|
|
from django.views.generic.edit import BaseFormView |
|
|
|
|
from django.urls import reverse_lazy |
|
|
|
|
|
|
|
|
|
from apps.notification.utils import send_email |
|
|
|
|
from apps.user.models import LilcityUserSettings, LilcityUserProxy |
|
|
|
|
from .forms import LearnerRegistrationForm |
|
|
|
|
from .tokens import verification_email_token |
|
|
|
|
from apps.notification.utils import send_email |
|
|
|
|
|
|
|
|
|
User = get_user_model() |
|
|
|
|
|
|
|
|
|
@ -100,3 +108,37 @@ class PasswordResetConfirmView(views.PasswordResetConfirmView): |
|
|
|
|
|
|
|
|
|
class PasswordResetComplete(views.PasswordResetCompleteView): |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(csrf_exempt, name="dispatch") |
|
|
|
|
class FacebookLoginOrRegistration(View): |
|
|
|
|
def post(self, requests, *args, **kwargs): |
|
|
|
|
access_token = requests.POST.get('access_token') |
|
|
|
|
graph = GraphAPI(access_token) |
|
|
|
|
try: |
|
|
|
|
data = graph.get('/me?fields=email, first_name, last_name') |
|
|
|
|
except FacepyError: |
|
|
|
|
return JsonResponse({"success": False}) |
|
|
|
|
|
|
|
|
|
facebook_id = data.get('id') |
|
|
|
|
|
|
|
|
|
lilcity_user_settings = LilcityUserSettings.objects.filter(facebook_id=facebook_id) |
|
|
|
|
if lilcity_user_settings.count(): |
|
|
|
|
login(requests, user=lilcity_user_settings[0].user) |
|
|
|
|
return JsonResponse({"success": True}) |
|
|
|
|
|
|
|
|
|
email = requests.POST.get('email') or data.get('email') |
|
|
|
|
if not email: |
|
|
|
|
return JsonResponse({"success": False, |
|
|
|
|
"errors": {"email": 'is field required'} |
|
|
|
|
}) |
|
|
|
|
else: |
|
|
|
|
first_name = data.get('first_name', '') |
|
|
|
|
last_name = data.get('last_name', '') |
|
|
|
|
|
|
|
|
|
user = LilcityUserProxy.objects.create_user(username=email, email=email, first_name=first_name, last_name=last_name, password=uuid4().hex) |
|
|
|
|
|
|
|
|
|
user.lilcity_user_settings.is_verification_email = True |
|
|
|
|
user.lilcity_user_settings.facebook_id = facebook_id |
|
|
|
|
user.lilcity_user_settings.save() |
|
|
|
|
return JsonResponse({"success": True}) |
|
|
|
|
|