|
|
|
@ -9,13 +9,14 @@ from rest_framework import status |
|
|
|
from rest_framework.generics import UpdateAPIView |
|
|
|
from rest_framework.generics import UpdateAPIView |
|
|
|
from rest_framework.exceptions import MethodNotAllowed |
|
|
|
from rest_framework.exceptions import MethodNotAllowed |
|
|
|
from rest_framework.permissions import IsAuthenticated |
|
|
|
from rest_framework.permissions import IsAuthenticated |
|
|
|
|
|
|
|
|
|
|
|
from django.contrib.auth import authenticate |
|
|
|
|
|
|
|
from rest_framework.views import APIView |
|
|
|
from rest_framework.views import APIView |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from django.contrib.auth import authenticate |
|
|
|
from django.db.models import Q |
|
|
|
from django.db.models import Q |
|
|
|
|
|
|
|
from django.core.exceptions import ObjectDoesNotExist |
|
|
|
|
|
|
|
|
|
|
|
from .permissions import IsClubOwner |
|
|
|
from .permissions import IsClubOwner |
|
|
|
|
|
|
|
from .utils import is_valid_email |
|
|
|
|
|
|
|
|
|
|
|
class CustomAuthToken(APIView): |
|
|
|
class CustomAuthToken(APIView): |
|
|
|
permission_classes = [] |
|
|
|
permission_classes = [] |
|
|
|
@ -24,8 +25,13 @@ class CustomAuthToken(APIView): |
|
|
|
username = request.data.get('username') |
|
|
|
username = request.data.get('username') |
|
|
|
password = request.data.get('password') |
|
|
|
password = request.data.get('password') |
|
|
|
device_id = request.data.get('device_id') |
|
|
|
device_id = request.data.get('device_id') |
|
|
|
|
|
|
|
|
|
|
|
user = authenticate(username=username, password=password) |
|
|
|
user = authenticate(username=username, password=password) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if user is None and is_valid_email(username) == True: |
|
|
|
|
|
|
|
true_username = self.get_username_from_email(username) |
|
|
|
|
|
|
|
user = authenticate(username=true_username, password=password) |
|
|
|
|
|
|
|
|
|
|
|
if user is not None: |
|
|
|
if user is not None: |
|
|
|
|
|
|
|
|
|
|
|
if user.device_id is None or user.device_id == device_id or user.username == 'apple-test': |
|
|
|
if user.device_id is None or user.device_id == device_id or user.username == 'apple-test': |
|
|
|
@ -39,6 +45,13 @@ class CustomAuthToken(APIView): |
|
|
|
else: |
|
|
|
else: |
|
|
|
return Response({'error': 'L\'utilisateur et le mot de passe de correspondent pas'}, status=status.HTTP_401_UNAUTHORIZED) |
|
|
|
return Response({'error': 'L\'utilisateur et le mot de passe de correspondent pas'}, status=status.HTTP_401_UNAUTHORIZED) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_username_from_email(self, email): |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
user = CustomUser.objects.get(email=email) |
|
|
|
|
|
|
|
return user.username |
|
|
|
|
|
|
|
except ObjectDoesNotExist: |
|
|
|
|
|
|
|
return None # or handle the case where the user doesn't exist |
|
|
|
|
|
|
|
|
|
|
|
class Logout(APIView): |
|
|
|
class Logout(APIView): |
|
|
|
permission_classes = (IsAuthenticated,) |
|
|
|
permission_classes = (IsAuthenticated,) |
|
|
|
|
|
|
|
|
|
|
|
|