TamaTown/DreamTown/cgi-bin/auth/5555/retrieveQuestion
2022-11-10 04:11:58 +13:00

51 lines
999 B
Python

#!/usr/bin/python3
from dreamtown_config import *
import sys
import binascii
import os
import json
import sqlite3
import hashlib
print("Content-Type: application/json")
print("")
method = os.environ["REQUEST_METHOD"]
if method != "POST":
print("Expected POST")
os._exit(1)
content_len = int(os.environ["CONTENT_LENGTH"])
post = sys.stdin.read(content_len)
jsonData = json.loads(post)
result = {"status":SUCCESS}
def TryRetrive():
username = jsonData['name'].lower()
authToken = jsonData['authToken']
#Check User Exists
c = db.cursor()
c.execute('SELECT COUNT(1) from users WHERE Name=?',(username,))
rows = c.fetchone()
count = rows[0]
if count == 0:
result['status'] = USER_DOES_NOT_EXIST
return 0
#Check QuestionType
c.execute('SELECT QuestionType from securityQuestion WHERE Name=?',(username,))
rows = c.fetchone()
QuestionType = rows[0]
result['questionId'] = QuestionType
db = DbConnect()
TryRetrive()
db.commit()
db.close()
print(json.dumps(result))