Half-Working order-answers

This commit is contained in:
Mawoka
2023-01-02 18:18:44 +01:00
parent 629822b2df
commit 0f000987ca
13 changed files with 664 additions and 314 deletions
+3
View File
@@ -116,6 +116,7 @@ class QuizQuestionType(str, Enum):
VOTING = "VOTING"
SLIDE = "SLIDE"
TEXT = "TEXT"
ORDER = "ORDER"
class TextQuizAnswer(BaseModel):
@@ -140,6 +141,8 @@ class QuizQuestion(BaseModel):
raise ValueError("Answer must be from type VotingQuizAnswer if type is VOTING")
if values["type"] == QuizQuestionType.TEXT and type(v[0]) != TextQuizAnswer:
raise ValueError("Answer must be from type TextQuizAnswer if type is TEXT")
if values["type"] == QuizQuestionType.ORDER and type(v[0]) != VotingQuizAnswer:
raise ValueError("Answer must be from type VotingQuizAnswer if type is ORDER")
if values["type"] == QuizQuestionType.SLIDE and type(v[0]) != str:
raise ValueError("Answer must be from type SlideElement if type is SLIDE")
return v
-1
View File
@@ -80,7 +80,6 @@ def verify_webauthn(data, fidocredentialss: list[FidoCredentials], login_session
credential.response.client_data_json = base64.b64decode(credential.response.client_data_json + b"==")
credential.response.authenticator_data = base64.urlsafe_b64decode(credential.response.authenticator_data + b"==")
credential.response.signature = base64.urlsafe_b64decode(credential.response.signature + b"==")
print(credential)
try:
verify_authentication_response(
credential=credential,
+1 -1
View File
@@ -78,7 +78,7 @@ async def create_user(user: RouteUser, background_task: BackgroundTasks) -> User
if len(user.username) == 32:
return JSONResponse({"details": "Username mustn't be 32 characters long"}, 400)
await user.save()
print(settings.skip_email_verification)
# print(settings.skip_email_verification)
if settings.skip_email_verification:
user.verify_key = None
user.verified = True
+20
View File
@@ -5,6 +5,7 @@ import base64
import hashlib
import json
import os
import random
import aiohttp
import socketio
@@ -248,6 +249,8 @@ async def set_question_number(sid, data: str):
for i in range(len(temp_return["answers"])):
temp_return["answers"][i] = VotingQuizAnswer(**temp_return["answers"][i])
temp_return["type"] = game_data.questions[int(float(data))].type
if temp_return["type"] == QuizQuestionType.ORDER:
random.shuffle(temp_return["answers"])
# print("emitting")
await sio.emit(
"set_question_number",
@@ -259,9 +262,14 @@ async def set_question_number(sid, data: str):
)
class _SubmitAnswerDataOrderType(BaseModel):
answer: str
class _SubmitAnswerData(BaseModel):
question_index: int
answer: str
complex_answer: list[_SubmitAnswerDataOrderType] | None
class _AnswerData(BaseModel):
@@ -303,6 +311,18 @@ async def submit_answer(sid: str, data: dict):
answer_right = True
elif game_data.questions[int(float(data.question_index))].type == QuizQuestionType.VOTING:
answer_right = False
elif game_data.questions[int(float(data.question_index))].type == QuizQuestionType.ORDER:
if data.complex_answer is None:
answer_right = False
else:
question = game_data.questions[int(float(data.question_index))]
correct_answers = []
for a in question.answers:
correct_answers.append({"answer": a.answer})
print(data.dict()["complex_answer"], correct_answers)
if correct_answers == data.dict()["complex_answer"]:
answer_right = True
elif game_data.questions[int(float(data.question_index))].type == QuizQuestionType.TEXT:
answer_right = False
for q in game_data.questions[int(float(data.question_index))].answers: