update schema, add db init
This commit is contained in:
+21
-21
@@ -1,32 +1,32 @@
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
#def __init__(self, path: str) -> None:
|
def init_db(path: str) -> None:
|
||||||
# self.db_connection = sqlite3.connect(path)
|
with sqlite3.connect(path) as connection:
|
||||||
# cursor = self.db_connection.cursor()
|
cursor = connection.cursor()
|
||||||
# cursor.execute('''
|
cursor.execute('''
|
||||||
# CREATE TABLE IF NOT EXISTS Tokens (
|
CREATE TABLE IF NOT EXISTS Tokens (
|
||||||
# TOKEN TEXT PRIMARY KEY NOT NULL,
|
TOKEN TEXT PRIMARY KEY NOT NULL,
|
||||||
# USER TEXT NOT NULL,
|
USERID INTEGER NOT NULL,
|
||||||
# NAME TEXT NOT NULL
|
NAME TEXT NOT NULL
|
||||||
# )
|
)
|
||||||
# ''')
|
''')
|
||||||
#
|
|
||||||
# cursor.execute('''
|
cursor.execute('''
|
||||||
# CREATE TABLE IF NOT EXISTS Domains (
|
CREATE TABLE IF NOT EXISTS Domains (
|
||||||
# DOMAIN TEXT PRIMARY KEY NOT NULL,
|
DOMAIN TEXT PRIMARY KEY NOT NULL,
|
||||||
# USER TEXT NOT NULL
|
USERID INTEGER NOT NULL
|
||||||
# )
|
)
|
||||||
# ''')
|
''')
|
||||||
#
|
|
||||||
# self.db_connection.commit()
|
connection.commit()
|
||||||
# cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
def check_token_domain(db_path: str, token: str, domain: str) -> bool:
|
def check_token_domain(db_path: str, token: str, domain: str) -> bool:
|
||||||
with sqlite3.connect(db_path) as connection:
|
with sqlite3.connect(db_path) as connection:
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
SELECT COUNT(*) FROM Tokens
|
SELECT COUNT(*) FROM Tokens
|
||||||
JOIN Domains ON Tokens.user = Domains.user
|
JOIN Domains ON Tokens.userid = Domains.userid
|
||||||
WHERE token = ?
|
WHERE token = ?
|
||||||
AND domain = ?
|
AND domain = ?
|
||||||
''', (token,domain))
|
''', (token,domain))
|
||||||
|
|||||||
+3
-1
@@ -73,10 +73,12 @@ def update_addr():
|
|||||||
return jsonify({"status": "500", "code": "internal-server-error", "comment": "An error occurred while processing request"}), 500
|
return jsonify({"status": "500", "code": "internal-server-error", "comment": "An error occurred while processing request"}), 500
|
||||||
|
|
||||||
return jsonify({"status": "200", "code": "ok", "comment": "Updated successfully"})
|
return jsonify({"status": "200", "code": "ok", "comment": "Updated successfully"})
|
||||||
except:
|
except Exception as e:
|
||||||
|
print(e, flush=True)
|
||||||
return jsonify({"status": "500", "code": "internal-server-error", "comment": "An error occurred while processing request"}), 500
|
return jsonify({"status": "500", "code": "internal-server-error", "comment": "An error occurred while processing request"}), 500
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
auth.init_db(DB_PATH)
|
||||||
app.run(host="0.0.0.0", port=8080, debug=True)
|
app.run(host="0.0.0.0", port=8080, debug=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user