From 6b70ecb317eb68e21ae4366933e180f5efa7e73c Mon Sep 17 00:00:00 2001 From: Wolkenfarmer Date: Mon, 25 Mar 2024 12:26:50 +0100 Subject: [PATCH 1/4] #109 frontend: adapt to current route configurations --- frontend/src/components/widgets/LoginPatient.vue | 2 +- frontend/src/components/widgets/LoginTrainer.vue | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/widgets/LoginPatient.vue b/frontend/src/components/widgets/LoginPatient.vue index 0ed78f77..ca890d16 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 @@ From 8be56d035fbefe4b56482ad444ea6774f6b14a2b Mon Sep 17 00:00:00 2001 From: Toni000 Date: Mon, 25 Mar 2024 14:33:38 +0100 Subject: [PATCH 2/4] #109 backend: add corsheaders as well as default user for testing --- backend/dps_training_k/configuration/settings.py | 1 + backend/dps_training_k/game/views.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) 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 2af3de95..c7f406f2 100644 --- a/backend/dps_training_k/game/views.py +++ b/backend/dps_training_k/game/views.py @@ -3,17 +3,21 @@ 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): - if not (request.data.get("exerciseCode") and request.data.get("patientCode")): + 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("exerciseCode") - patient_code = request.data.get("patientCode") + exercise_code = request.data.get("exerciseId") + patient_code = request.data.get("patientId") user = authenticate(username=exercise_code, password=patient_code) if user: token, created = Token.objects.get_or_create(user=user) From 983ae17819abad3b9caaffab079b791b9ac2850e Mon Sep 17 00:00:00 2001 From: Wolkenfarmer Date: Thu, 28 Mar 2024 10:27:31 +0100 Subject: [PATCH 3/4] #109: fix patient access --- backend/dps_training_k/game/views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/dps_training_k/game/views.py b/backend/dps_training_k/game/views.py index 89d6ea6a..d4d8787a 100644 --- a/backend/dps_training_k/game/views.py +++ b/backend/dps_training_k/game/views.py @@ -5,9 +5,12 @@ 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 + 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() @@ -17,9 +20,9 @@ def post(self, request, *args, **kwargs): 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) From 962316259ef5f15a1f33834c29fb901d8aacac07 Mon Sep 17 00:00:00 2001 From: Wolkenfarmer Date: Thu, 28 Mar 2024 10:35:36 +0100 Subject: [PATCH 4/4] #109: adapt dummy patient in backend to frontend mock data --- backend/dps_training_k/game/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/dps_training_k/game/views.py b/backend/dps_training_k/game/views.py index d4d8787a..bd587844 100644 --- a/backend/dps_training_k/game/views.py +++ b/backend/dps_training_k/game/views.py @@ -9,10 +9,10 @@ class PatientAccessView(APIView): def post(self, request, *args, **kwargs): user, created = User.objects.get_or_create( - username="123" + username="123456" ) # Ensure the username is a string if created: - user.set_password("123") # Properly hash the password + user.set_password("2") # Properly hash the password user.save() if not (request.data.get("exerciseId") and request.data.get("patientId")):