Skip to content

Commit

Permalink
Merge branch 'main' into 108-m01-add-basic-triage
Browse files Browse the repository at this point in the history
  • Loading branch information
claasga authored Mar 28, 2024
2 parents b6295a7 + 9623162 commit a0cc18b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 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
14 changes: 11 additions & 3 deletions backend/dps_training_k/game/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="123456"
) # Ensure the username is a string
if created:
user.set_password("2") # 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)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/widgets/LoginPatient.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"patientId": patientIdNumber,
}
fetch('https://localhost:8000/login/', {
fetch('http://localhost:8000/patient/access', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/components/widgets/LoginTrainer.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import {ref} from 'vue'
import {useTrainerStore} from '@/stores/Trainer'
import {Modules, setModule, showErrorToast} from "@/App.vue"
import {Modules, setModule} from "@/App.vue"
import {svg} from "@/assets/Svg"
const usernameInput = ref("")
Expand All @@ -11,12 +11,16 @@
const trainerStore = useTrainerStore()
trainerStore.username = usernameInput.value
const requestBody = {
setModule(Modules.TRAINER)
return
// Will be used when trainer login is implemented in the backend
/*const requestBody = {
"username": usernameInput.value,
"password": passwordInput.value,
}
fetch('https://localhost:8000/login/', {
fetch('https://localhost:8000/trainer/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -41,7 +45,7 @@
.then(data => {
trainerStore.token = data.token
setModule(Modules.TRAINER)
})
})*/
}
</script>

Expand Down

0 comments on commit a0cc18b

Please sign in to comment.