flask server
This commit is contained in:
parent
5acb2992ce
commit
0a71a6c840
54 changed files with 5876 additions and 0 deletions
|
|
@ -0,0 +1,34 @@
|
|||
from .db import get_db
|
||||
from .data_models import DataError
|
||||
from sqlite3 import IntegrityError
|
||||
|
||||
def is_valid_token(token):
|
||||
db = get_db()
|
||||
db_cursor = db.cursor()
|
||||
db_cursor.execute("SELECT COUNT(*) FROM registration_token where token = :token", {"token": token})
|
||||
rows = db_cursor.fetchone()
|
||||
|
||||
return rows[0] == 1
|
||||
|
||||
def insert_token(token):
|
||||
db = get_db()
|
||||
db_cursor = db.cursor()
|
||||
try:
|
||||
db_cursor.execute("INSERT INTO registration_token(token) VALUES(:token)", {"token": token})
|
||||
except IntegrityError as e:
|
||||
return DataError.REGISTRATION_CODE_ALREADY_EXISTS
|
||||
db.commit()
|
||||
|
||||
def delete_token(token):
|
||||
db = get_db()
|
||||
db_cursor = db.cursor()
|
||||
db_cursor.execute("DELETE FROM registration_token WHERE token=:token", {"token": token})
|
||||
db.commit()
|
||||
|
||||
def get_tokens():
|
||||
db = get_db()
|
||||
db_cursor = db.cursor()
|
||||
db_cursor.execute("SELECT * FROM registration_token")
|
||||
rows = db_cursor.fetchall()
|
||||
|
||||
return list(map(lambda row: row['token'],rows))
|
||||
Loading…
Add table
Add a link
Reference in a new issue