From 42f3f0262d06f50d730c55c232362c8ddd984d55 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Fri, 17 Jun 2022 22:20:40 +0400 Subject: Enable Login Form In Production Adds a non-discoverable login form in all environments to make it easier to authenticate. Ideally, we'd have an actual login button, but this is an easy solution in the meantime. Signed-off-by: Hassan Abouelela --- backend/routes/forms/submit.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'backend/routes/forms/submit.py') diff --git a/backend/routes/forms/submit.py b/backend/routes/forms/submit.py index baf403d..5c500b5 100644 --- a/backend/routes/forms/submit.py +++ b/backend/routes/forms/submit.py @@ -22,6 +22,7 @@ from backend.authentication.user import User from backend.models import Form, FormResponse from backend.route import Route from backend.routes.auth.authorize import set_response_token +from backend.routes.forms.discover import AUTH_FORM from backend.routes.forms.unittesting import execute_unittest from backend.validation import ErrorMessage, api @@ -106,9 +107,18 @@ class SubmitForm(Route): data = await request.json() data["timestamp"] = None - if form := await request.state.db.forms.find_one( - {"_id": request.path_params["form_id"], "features": "OPEN"} - ): + form_id = request.path_params["form_id"] + + if form_id == AUTH_FORM.id: + response = FormResponse( + id="not-submitted", + form_id=AUTH_FORM.id, + response={question.id: None for question in AUTH_FORM.questions}, + timestamp=datetime.datetime.now().isoformat() + ).dict() + return JSONResponse({"form": AUTH_FORM.dict(admin=False), "response": response}) + + if form := await request.state.db.forms.find_one({"_id": form_id, "features": "OPEN"}): form = Form(**form) response = data.copy() response["id"] = str(uuid.uuid4()) -- cgit v1.2.3