This is the main repository of our quiz/game
We are using Heroku/Dokku, runtime of python-3.6.10 and Flask Backend is based on Postgresql and psycopg2 is the adapter used
Most of the code has been documented (TODO) You can read more about the API below
There are 3 main API Handlers
They have been briefly discussed below
All Post requests require data as a JSON object see fetch help
below
Route: /api/user/:action
This handler deals with authentication, registering, and reading user data.
Usage: Create a new (non-admin) account
Method: post
expected post data:
{
"user": "$user",
"name": "$fullname",
"school": "$school",
"password": "$pass",
"ig_user_id": "$insta"
}
Returns
on success
{
"id": "$userID",
"current_level": "$current_level",
"is_admin": "$is_admin",
"is_disqualified": "$is_disqualified",
"name": "name",
"secure_data": {
"email": "$email",
"school": "$school",
"ig_user_id": "$insta"
}
}
on error
{ "error": "$reason" }
Note: The password is hashed.
Usage: Log in a registered user
Method: post
expected post data:
{ "user": "$user", "password": "$pasword" }
Returns
on success
{
"id": "$userID",
"current_level": "$current_level",
"is_admin": "$is_admin",
"is_disqualified": "$is_disqualified",
"name": "name",
"secure_data": {
"email": "$email",
"school": "$school",
"ig_user_id": "$insta"
}
}
on error
{ "error": "$reason" }
Usage: fetch general details of any user
Method: get
Returns
on success
{
"id": "$userID",
"current_level": "$current_level",
"is_admin": "$is_admin",
"is_disqualified": "$is_disqualified",
"name": "name"
}
on error
{ "error": "$reason" }
Notice how the secure_data
has been removed, this allows us to preserve privacy and only show private data when needed.
Route: /api/play/:action
This handler deals with actual logic of answering questions and leaderboards
Usagea: get current leaderboard positions
Method: get
Returns
[
{
"id": "$userID",
"current_level": "$current_level",
"is_admin": "$is_admin",
"is_disqualified": "$is_disqualified",
"name": "name"
}
]
Usage: Get current question of the user,requires user to be logged in
Method: post
returns
{
"question_level": "$question_level",
"question": "$question",
"hint": "$hint",
"special_stringified_data": "$special_stringified_data",
"game_over": false
}
if all questions are completed:
{ "game_over": true }
Usage: When user submits the Ques.
Method: post
Required post data
{ "answer": "$answer" }
returns
on correct
{ "result": true, "next_level": "$next" }
on incorrect
{ "result": false }
The admin panel has not been documented yet.
Use something like this:
// get
const req = (url) => fetch(url, { credentials: "include" });
/* credentials:include is important */
// post
const port = (url, dict) =>
fetch(url, {
credentials: "include",
body: JSON.stringify(dict),
headers: { "content-type": "application/json" },
});