Cambios API Clientes permisos

This commit is contained in:
fjrodriguez
2023-09-22 15:28:52 -06:00
parent 4bdb833cdb
commit ac80bf6a45
12 changed files with 452 additions and 55 deletions

View File

@@ -8,7 +8,7 @@ from django.views.generic.edit import CreateView
from rest_framework.authentication import TokenAuthentication
from rest_framework.decorators import authentication_classes,api_view,permission_classes
from rest_framework.exceptions import AuthenticationFailed
from rest_framework.authtoken.models import Token
from rest_framework.views import APIView
from rest_framework.response import Response
@@ -380,7 +380,7 @@ class CheckVersionView(APIView):
class Custom_Login(APIView):
"""Autentica al device"""
authentication_classes= [TokenAuthentication]
permissions_classes=[IsAuthenticated, HasAuthorizationHeader]
permission_classes=[IsAuthenticated, HasAuthorizationHeader]
def post(self, request):
username = request.data.get('username')
@@ -389,7 +389,8 @@ class Custom_Login(APIView):
user = authenticate(request, username=username,password=password)
if user is not None:
login(request,user)
return Response({'access':True})
token, created = Token.objects.get_or_create(user=user)
return Response({'access':True, 'token':token.key})
else:
return Response({'access':False})
except Exception as ex: