Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

109 m01 fix login and access logic #110

Merged
merged 4 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="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)
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