diff --git a/backend/dps_training_k/configuration/settings.py b/backend/dps_training_k/configuration/settings.py index 52620d92..46d4c21b 100644 --- a/backend/dps_training_k/configuration/settings.py +++ b/backend/dps_training_k/configuration/settings.py @@ -57,6 +57,7 @@ ] MIDDLEWARE = [ + "corsheaders.middleware.CorsMiddleware", "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", diff --git a/backend/dps_training_k/game/views.py b/backend/dps_training_k/game/views.py index 5c8335d7..d4d8787a 100644 --- a/backend/dps_training_k/game/views.py +++ b/backend/dps_training_k/game/views.py @@ -3,18 +3,26 @@ from rest_framework.response import Response from django.contrib.auth import authenticate from rest_framework.authtoken.models import Token +from game.models import User class PatientAccessView(APIView): def post(self, request, *args, **kwargs): + user, created = User.objects.get_or_create( + username="123" + ) # Ensure the username is a string + if created: + user.set_password("123") # Properly hash the password + user.save() + if not (request.data.get("exerciseId") and request.data.get("patientId")): return Response( status=status.HTTP_400_BAD_REQUEST, data="Some required fields are missing", ) - exercise_code = request.data.get("exerciseId") - patient_code = request.data.get("patientId") - user = authenticate(username=exercise_code, password=patient_code) + exercise_id = str(request.data.get("exerciseId")) + patient_id = str(request.data.get("patientId")) + user = authenticate(username=exercise_id, password=patient_id) if user: token, created = Token.objects.get_or_create(user=user) return Response({"token": token.key}, status=status.HTTP_200_OK) diff --git a/frontend/src/components/widgets/LoginPatient.vue b/frontend/src/components/widgets/LoginPatient.vue index e3d49c01..416f97dc 100644 --- a/frontend/src/components/widgets/LoginPatient.vue +++ b/frontend/src/components/widgets/LoginPatient.vue @@ -25,7 +25,7 @@ "patientId": patientIdNumber, } - fetch('https://localhost:8000/login/', { + fetch('http://localhost:8000/patient/access', { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/frontend/src/components/widgets/LoginTrainer.vue b/frontend/src/components/widgets/LoginTrainer.vue index abc1c622..46dde68d 100644 --- a/frontend/src/components/widgets/LoginTrainer.vue +++ b/frontend/src/components/widgets/LoginTrainer.vue @@ -1,7 +1,7 @@