Skip to content

Commit

Permalink
#109 backend: add corsheaders as well as default user for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni000 committed Mar 25, 2024
1 parent 6b70ecb commit 8be56d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/dps_training_k/configuration/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
]

MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
Expand Down
12 changes: 8 additions & 4 deletions backend/dps_training_k/game/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8be56d0

Please sign in to comment.