File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111from backend .validation import api
1212
1313__FEATURES = [
14- constants .FormFeatures .DISCOVERABLE .value ,
1514 constants .FormFeatures .OPEN .value ,
1615 constants .FormFeatures .REQUIRES_LOGIN .value
1716]
17+ if not constants .PRODUCTION :
18+ __FEATURES .append (constants .FormFeatures .DISCOVERABLE .value )
1819
1920__QUESTION = Question (
2021 id = "description" ,
21- name = "Check your cookies after pressing the button ." ,
22+ name = "Click the button below to log into the forms application ." ,
2223 type = "section" ,
23- data = {"text" : "You can find cookies under \" Application \" in dev tools. " },
24+ data = {"text" : "" },
2425 required = False
2526)
2627
27- EMPTY_FORM = Form (
28- id = "empty_auth " ,
28+ AUTH_FORM = Form (
29+ id = "login " ,
2930 features = __FEATURES ,
3031 questions = [__QUESTION ],
31- name = "Auth form" ,
32- description = "An empty form to help you get a token." ,
32+ name = "Login" ,
33+ description = "Log into Python Discord Forms." ,
34+ submitted_text = "This page can't be submitted."
3335)
3436
3537
@@ -55,7 +57,7 @@ async def get(self, request: Request) -> JSONResponse:
5557 forms = [form .dict (admin = False ) for form in forms ]
5658
5759 # Return an empty form in development environments to help with authentication.
58- if not forms and not constants .PRODUCTION :
59- forms .append (EMPTY_FORM .dict (admin = False ))
60+ if not constants .PRODUCTION :
61+ forms .append (AUTH_FORM .dict (admin = False ))
6062
6163 return JSONResponse (forms )
Original file line number Diff line number Diff line change 1313from backend import constants , discord
1414from backend .models import Form
1515from backend .route import Route
16- from backend .routes .forms .discover import EMPTY_FORM
16+ from backend .routes .forms .discover import AUTH_FORM
1717from backend .routes .forms .unittesting import filter_unittests
1818from backend .validation import ErrorMessage , OkayResponse , api
1919
@@ -35,13 +35,14 @@ async def get(self, request: Request) -> JSONResponse:
3535 """Returns single form information by ID."""
3636 form_id = request .path_params ["form_id" ].lower ()
3737
38+ if form_id == AUTH_FORM .id :
39+ # Empty form for login purposes
40+ return JSONResponse (AUTH_FORM .dict (admin = False ))
41+
3842 try :
3943 await discord .verify_edit_access (form_id , request )
4044 admin = True
4145 except discord .FormNotFoundError :
42- if not constants .PRODUCTION and form_id == EMPTY_FORM .id :
43- # Empty form to help with authentication in development.
44- return JSONResponse (EMPTY_FORM .dict (admin = False ))
4546 return JSONResponse ({"error" : "not_found" }, status_code = 404 )
4647 except discord .UnauthorizedError :
4748 admin = False
Original file line number Diff line number Diff line change 2222from backend .models import Form , FormResponse
2323from backend .route import Route
2424from backend .routes .auth .authorize import set_response_token
25+ from backend .routes .forms .discover import AUTH_FORM
2526from backend .routes .forms .unittesting import execute_unittest
2627from backend .validation import ErrorMessage , api
2728
@@ -106,9 +107,18 @@ async def submit(self, request: Request) -> JSONResponse:
106107 data = await request .json ()
107108 data ["timestamp" ] = None
108109
109- if form := await request .state .db .forms .find_one (
110- {"_id" : request .path_params ["form_id" ], "features" : "OPEN" }
111- ):
110+ form_id = request .path_params ["form_id" ]
111+
112+ if form_id == AUTH_FORM .id :
113+ response = FormResponse (
114+ id = "not-submitted" ,
115+ form_id = AUTH_FORM .id ,
116+ response = {question .id : None for question in AUTH_FORM .questions },
117+ timestamp = datetime .datetime .now ().isoformat ()
118+ ).dict ()
119+ return JSONResponse ({"form" : AUTH_FORM .dict (admin = False ), "response" : response })
120+
121+ if form := await request .state .db .forms .find_one ({"_id" : form_id , "features" : "OPEN" }):
112122 form = Form (** form )
113123 response = data .copy ()
114124 response ["id" ] = str (uuid .uuid4 ())
You can’t perform that action at this time.
0 commit comments