Committing Everything
This commit is contained in:
@@ -102,19 +102,27 @@ def verify_webauthn(data, fidocredentialss: list[FidoCredentials], login_session
|
||||
@router.post("/start")
|
||||
async def start_login(data: StartLoginInput):
|
||||
user = (
|
||||
#TODO Find out why the fidocredentialls call fails
|
||||
await User.objects.select_related("fidocredentialss")
|
||||
.filter((User.email == data.email) | (User.username == data.email))
|
||||
.get_or_none()
|
||||
# await User.objects.filter((User.email == data.email) | (User.username == data.email))
|
||||
# .get_or_none()
|
||||
)
|
||||
print("User.objects.filter call completed...")
|
||||
step_1: set[StartLoginResponseTypes] = set()
|
||||
step_2: set[StartLoginResponseTypes] = set()
|
||||
webauthn_data = None
|
||||
webauthn_challenge = None
|
||||
print("\"webauthn_challenge = None\" call completed...")
|
||||
print("user.verified: " + str(user.verified))
|
||||
if user is None or not user.verified:
|
||||
step_1.add(StartLoginResponseTypes.PASSWORD)
|
||||
return StartLoginResponse(step_1=step_1, step_2=step_2, session_id=os.urandom(16).hex(), webauthn_data=None)
|
||||
print("Okay. User is not None or unverified...")
|
||||
if user.password is not None:
|
||||
step_1.add(StartLoginResponseTypes.PASSWORD)
|
||||
''' TODO Find out why fidocredentialss is causing problems
|
||||
if len(user.fidocredentialss) > 0:
|
||||
if user.require_password is True:
|
||||
step_2.add(StartLoginResponseTypes.PASSKEY)
|
||||
@@ -129,6 +137,8 @@ async def start_login(data: StartLoginInput):
|
||||
)
|
||||
webauthn_challenge = base64.b64encode(webauthn_data.challenge).decode("utf-8")
|
||||
webauthn_data = options_to_json(webauthn_data)
|
||||
'''
|
||||
print("Moving past commented code, the long string one...")
|
||||
if user.totp_secret is not None:
|
||||
if user.require_password:
|
||||
step_2.add(StartLoginResponseTypes.TOTP)
|
||||
@@ -170,7 +180,8 @@ async def step_1_endpoint(session_id: str, data: StepInput, request: Request, re
|
||||
else:
|
||||
print("unknown step")
|
||||
raise HTTPException(401)
|
||||
user = await User.objects.select_related("fidocredentialss").get_or_none(id=uuid.UUID(login_session.user_id))
|
||||
#TODO fidocredentials bug fix user = await User.objects.select_related("fidocredentialss").get_or_none(id=uuid.UUID(login_session.user_id))
|
||||
user = await User.objects.get_or_none(id=uuid.UUID(login_session.user_id))
|
||||
if data.auth_type == StartLoginResponseTypes.PASSWORD:
|
||||
if verify_password(data.data, user.password):
|
||||
if len(login_session.step_2) == 0 or (step_id == 2 and login_session.step1_success is True):
|
||||
|
||||
@@ -15,7 +15,7 @@ import ormar.exceptions
|
||||
from classquiz.helpers import generate_spreadsheet, handle_import_from_excel
|
||||
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File
|
||||
from fastapi.responses import JSONResponse, StreamingResponse
|
||||
from pydantic import ValidationError, BaseModel
|
||||
from pydantic import ValidationError, BaseModel, Field
|
||||
|
||||
from classquiz.auth import get_current_user
|
||||
from classquiz.config import redis, settings, storage, meilisearch
|
||||
@@ -56,7 +56,8 @@ class PublicQuizResponseUser(BaseModel):
|
||||
|
||||
class PublicQuizResponse(Quiz.get_pydantic()):
|
||||
user_id: PublicQuizResponseUser
|
||||
questions: list[QuizQuestion]
|
||||
# questions: list[QuizQuestion]
|
||||
var_questions: list[QuizQuestion] = Field(..., alias='questions')
|
||||
likes: int
|
||||
dislikes: int
|
||||
views: int
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
# SPDX-FileCopyrightText: 2023 Marlon W (Mawoka)
|
||||
#
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
|
||||
import datetime
|
||||
import uuid
|
||||
|
||||
from fastapi import APIRouter, Response
|
||||
from jinja2 import Template
|
||||
from pydantic import BaseModel
|
||||
from classquiz.config import redis, settings
|
||||
from classquiz.db import database
|
||||
|
||||
settings = settings()
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
sitemap_template = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
{% for entry in pages -%}
|
||||
<url>
|
||||
<loc>{{ root_address}}/view/{{ entry.id.hex }}</loc>
|
||||
{%- if entry.updated_at != None -%}
|
||||
<lastmod>{{ entry.updated_at.strftime("%Y-%m-%d") }}</lastmod>
|
||||
{% endif %}
|
||||
</url>
|
||||
{%- endfor %}
|
||||
</urlset>"""
|
||||
|
||||
|
||||
sql_statement_metadata = """
|
||||
SELECT id, title, description, updated_at from quiz where public ='t'
|
||||
"""
|
||||
|
||||
sql_statement_id_and_modified_only = """
|
||||
SELECT id, updated_at from quiz where public ='t'
|
||||
"""
|
||||
|
||||
template = Template(sitemap_template, enable_async=True)
|
||||
|
||||
|
||||
class SitemapQuiz(BaseModel):
|
||||
id: uuid.UUID
|
||||
updated_at: datetime.datetime
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
@router.get("/get")
|
||||
async def get_sitemap():
|
||||
redis_cache_resp = await redis.get("sitemap")
|
||||
if redis_cache_resp is None:
|
||||
res = await database.fetch_all(sql_statement_id_and_modified_only)
|
||||
entries = []
|
||||
for i in res:
|
||||
entries.append(SitemapQuiz.from_orm(i))
|
||||
rendered_sitemap = await template.render_async({"pages": entries, "root_address": settings.root_address})
|
||||
await redis.set("sitemap", rendered_sitemap, ex=86400)
|
||||
return Response(content=rendered_sitemap, media_type="application/xml")
|
||||
else:
|
||||
return Response(content=redis_cache_resp, media_type="application/xml")
|
||||
@@ -45,7 +45,7 @@ class SitemapQuiz(BaseModel):
|
||||
updated_at: datetime.datetime
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
from_attributes = True
|
||||
|
||||
|
||||
@router.get("/get")
|
||||
|
||||
Reference in New Issue
Block a user