mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
refactor: Modification de l'url de l'api Auth
This commit is contained in:
@ -10,6 +10,9 @@ from rest_framework.views import APIView
|
||||
from rest_framework.parsers import JSONParser
|
||||
from rest_framework import status
|
||||
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
from drf_yasg import openapi
|
||||
|
||||
from datetime import datetime
|
||||
import jwt
|
||||
import json
|
||||
@ -53,20 +56,12 @@ class SessionView(APIView):
|
||||
except jwt.InvalidTokenError:
|
||||
return JsonResponse({"error": "Invalid token"}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
class ProfileListView(APIView):
|
||||
class ProfileView(APIView):
|
||||
def get(self, request):
|
||||
profilsList = bdd.getAllObjects(_objectName=Profile)
|
||||
profils_serializer = ProfileSerializer(profilsList, many=True)
|
||||
return JsonResponse(profils_serializer.data, safe=False)
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class ProfileView(APIView):
|
||||
def get(self, request, _id):
|
||||
profil=bdd.getObject(Profile, "id", _id)
|
||||
profil_serializer=ProfileSerializer(profil)
|
||||
return JsonResponse(profil_serializer.data, safe=False)
|
||||
|
||||
def post(self, request):
|
||||
profil_data=JSONParser().parse(request)
|
||||
print(f'{profil_data}')
|
||||
@ -74,12 +69,20 @@ class ProfileView(APIView):
|
||||
|
||||
if profil_serializer.is_valid():
|
||||
profil_serializer.save()
|
||||
|
||||
|
||||
return JsonResponse(profil_serializer.data, safe=False)
|
||||
|
||||
|
||||
return JsonResponse(profil_serializer.errors, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def put(self, request, _id):
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class ProfileSimpleView(APIView):
|
||||
def get(self, request, id):
|
||||
profil=bdd.getObject(Profile, "id", id)
|
||||
profil_serializer=ProfileSerializer(profil)
|
||||
return JsonResponse(profil_serializer.data, safe=False)
|
||||
|
||||
def put(self, request, id):
|
||||
data=JSONParser().parse(request)
|
||||
profil = Profile.objects.get(id=_id)
|
||||
profil_serializer = ProfilUpdateSerializer(profil, data=data)
|
||||
@ -89,8 +92,8 @@ class ProfileView(APIView):
|
||||
|
||||
return JsonResponse(profil_serializer.errors, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def delete(self, request, _id):
|
||||
return bdd.delete_object(Profile, _id)
|
||||
def delete(self, request, id):
|
||||
return bdd.delete_object(Profile, id)
|
||||
|
||||
def infoSession(request):
|
||||
profilCache = cache.get('session_cache')
|
||||
@ -102,14 +105,6 @@ def infoSession(request):
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class LoginView(APIView):
|
||||
|
||||
def get(self, request):
|
||||
return JsonResponse({
|
||||
'errorFields':'',
|
||||
'errorMessage':'',
|
||||
'profil':0,
|
||||
}, safe=False)
|
||||
|
||||
def post(self, request):
|
||||
data=JSONParser().parse(request)
|
||||
validatorAuthentication = validator.ValidatorAuthentication(data=data)
|
||||
@ -153,22 +148,15 @@ class LoginView(APIView):
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class SubscribeView(APIView):
|
||||
|
||||
def get(self, request):
|
||||
return JsonResponse({
|
||||
'message':'',
|
||||
'errorFields':'',
|
||||
'errorMessage':''
|
||||
}, safe=False)
|
||||
|
||||
def post(self, request):
|
||||
retourErreur = error.returnMessage[error.BAD_URL]
|
||||
retour = ''
|
||||
newProfilConnection=JSONParser().parse(request)
|
||||
|
||||
|
||||
validatorSubscription = validator.ValidatorSubscription(data=newProfilConnection)
|
||||
validationOk, errorFields = validatorSubscription.validate()
|
||||
|
||||
|
||||
|
||||
if validationOk:
|
||||
|
||||
# On vérifie que l'email existe : si ce n'est pas le cas, on retourne une erreur
|
||||
@ -200,13 +188,7 @@ class SubscribeView(APIView):
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class NewPasswordView(APIView):
|
||||
def get(self, request):
|
||||
return JsonResponse({
|
||||
'message':'',
|
||||
'errorFields':'',
|
||||
'errorMessage':''
|
||||
}, safe=False)
|
||||
|
||||
|
||||
def post(self, request):
|
||||
retourErreur = error.returnMessage[error.BAD_URL]
|
||||
retour = ''
|
||||
@ -234,22 +216,15 @@ class NewPasswordView(APIView):
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class ResetPasswordView(APIView):
|
||||
def get(self, request, _uuid):
|
||||
return JsonResponse({
|
||||
'message':'',
|
||||
'errorFields':'',
|
||||
'errorMessage':''
|
||||
}, safe=False)
|
||||
|
||||
def post(self, request, _uuid):
|
||||
def post(self, request, code):
|
||||
retourErreur = error.returnMessage[error.BAD_URL]
|
||||
retour = ''
|
||||
newProfilConnection=JSONParser().parse(request)
|
||||
|
||||
validatorResetPassword = validator.ValidatorResetPassword(data=newProfilConnection)
|
||||
validationOk, errorFields = validatorResetPassword.validate()
|
||||
|
||||
profil = bdd.getObject(Profile, "code", _uuid)
|
||||
|
||||
profil = bdd.getObject(Profile, "code", code)
|
||||
if profil:
|
||||
|
||||
if datetime.strptime(util.convertToStr(util._now(), '%d-%m-%Y %H:%M'), '%d-%m-%Y %H:%M') > datetime.strptime(profil.datePeremption, '%d-%m-%Y %H:%M'):
|
||||
|
||||
Reference in New Issue
Block a user