|
@@ -11,8 +11,8 @@ SECRET_KEY = "df2f77bd544240801a048bd4293afd8eeb7fff3cb7050e42c791db4b83ebadcd"
|
|
ALGORITHM = "HS256"
|
|
ALGORITHM = "HS256"
|
|
ACCESS_TOKEN_EXPIRE_DAYS = 5
|
|
ACCESS_TOKEN_EXPIRE_DAYS = 5
|
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
|
-
|
|
|
|
-def get_user_id(token,db):
|
|
|
|
|
|
+def get_user_id(token):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
credentials_exception = HTTPException(
|
|
credentials_exception = HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Could not validate credentials",
|
|
detail="Could not validate credentials",
|
|
@@ -32,15 +32,15 @@ def get_user_id(token,db):
|
|
user_id = first(db.query('SELECT * FROM users where username="' + user.username+'"'))['id']
|
|
user_id = first(db.query('SELECT * FROM users where username="' + user.username+'"'))['id']
|
|
return user_id
|
|
return user_id
|
|
|
|
|
|
-def check_user_exists( username,db):
|
|
|
|
-
|
|
|
|
|
|
+def check_user_exists( username):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
if int(next(iter(db.query('SELECT COUNT(*) FROM AI_anchor.users WHERE username = "'+username+'"')))['COUNT(*)']) > 0:
|
|
if int(next(iter(db.query('SELECT COUNT(*) FROM AI_anchor.users WHERE username = "'+username+'"')))['COUNT(*)']) > 0:
|
|
return True
|
|
return True
|
|
else:
|
|
else:
|
|
return False
|
|
return False
|
|
|
|
|
|
-def get_user( username: str,db):
|
|
|
|
-
|
|
|
|
|
|
+def get_user( username: str):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
if not check_user_exists(username): # if user don't exist
|
|
if not check_user_exists(username): # if user don't exist
|
|
return False
|
|
return False
|
|
user_dict = next(
|
|
user_dict = next(
|
|
@@ -48,8 +48,8 @@ def get_user( username: str,db):
|
|
user = util.models.User(**user_dict)
|
|
user = util.models.User(**user_dict)
|
|
return user
|
|
return user
|
|
|
|
|
|
-def user_register( user,db):
|
|
|
|
-
|
|
|
|
|
|
+def user_register( user):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
table = db['users']
|
|
table = db['users']
|
|
user.password = get_password_hash(user.password)
|
|
user.password = get_password_hash(user.password)
|
|
table.insert(dict(user))
|
|
table.insert(dict(user))
|
|
@@ -60,8 +60,8 @@ def get_password_hash( password):
|
|
def verify_password( plain_password, hashed_password):
|
|
def verify_password( plain_password, hashed_password):
|
|
return pwd_context.verify(plain_password, hashed_password)
|
|
return pwd_context.verify(plain_password, hashed_password)
|
|
|
|
|
|
-def authenticate_user( username: str, password: str,db):
|
|
|
|
-
|
|
|
|
|
|
+def authenticate_user( username: str, password: str):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
if not check_user_exists(username): # if user don't exist
|
|
if not check_user_exists(username): # if user don't exist
|
|
return False
|
|
return False
|
|
user_dict = next(iter(db.query('SELECT * FROM AI_anchor.users where username ="'+username+'"')))
|
|
user_dict = next(iter(db.query('SELECT * FROM AI_anchor.users where username ="'+username+'"')))
|
|
@@ -70,8 +70,8 @@ def authenticate_user( username: str, password: str,db):
|
|
return False
|
|
return False
|
|
return user
|
|
return user
|
|
|
|
|
|
-def get_user_role(id,db):
|
|
|
|
-
|
|
|
|
|
|
+def get_user_role(id):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
state = 'SELECT * FROM user_role '\
|
|
state = 'SELECT * FROM user_role '\
|
|
'INNER JOIN users on user_role.user_id= users.id '\
|
|
'INNER JOIN users on user_role.user_id= users.id '\
|
|
'INNER JOIN role on user_role.role_id = role.id '\
|
|
'INNER JOIN role on user_role.role_id = role.id '\
|
|
@@ -81,8 +81,8 @@ def get_user_role(id,db):
|
|
role_list.append({'id':row['role_id'],'name':row['name']})
|
|
role_list.append({'id':row['role_id'],'name':row['name']})
|
|
return role_list
|
|
return role_list
|
|
|
|
|
|
-def get_avatar_by_role(id,db):
|
|
|
|
-
|
|
|
|
|
|
+def get_avatar_by_role(id):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
state = 'SELECT * FROM ('\
|
|
state = 'SELECT * FROM ('\
|
|
'SELECT role_id FROM AI_anchor.user_role '\
|
|
'SELECT role_id FROM AI_anchor.user_role '\
|
|
'INNER JOIN users on user_role.user_id= users.id '\
|
|
'INNER JOIN users on user_role.user_id= users.id '\
|
|
@@ -95,12 +95,12 @@ def get_avatar_by_role(id,db):
|
|
role_list.append({'id':row['role_id'],'name':row['name']})
|
|
role_list.append({'id':row['role_id'],'name':row['name']})
|
|
return role_list
|
|
return role_list
|
|
#def add_role( username,role_id):
|
|
#def add_role( username,role_id):
|
|
- #
|
|
|
|
|
|
+ #db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
#user_role_table = db['user_role']
|
|
#user_role_table = db['user_role']
|
|
#user_role_table.insert({'user_id':,'role_id':role_id})
|
|
#user_role_table.insert({'user_id':,'role_id':role_id})
|
|
|
|
|
|
-def get_user_id(token,db):
|
|
|
|
-
|
|
|
|
|
|
+def get_user_id(token):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
credentials_exception = HTTPException(
|
|
credentials_exception = HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Could not validate credentials",
|
|
detail="Could not validate credentials",
|
|
@@ -120,13 +120,13 @@ def get_user_id(token,db):
|
|
user_id = first(db.query('SELECT * FROM users where username="' + user.username+'"'))['id']
|
|
user_id = first(db.query('SELECT * FROM users where username="' + user.username+'"'))['id']
|
|
return user_id
|
|
return user_id
|
|
|
|
|
|
-def get_id_by_email(email,db):
|
|
|
|
-
|
|
|
|
|
|
+def get_id_by_email(email):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
user_dict = next(iter(db.query('SELECT * FROM users where email ="'+email+'"')))
|
|
user_dict = next(iter(db.query('SELECT * FROM users where email ="'+email+'"')))
|
|
return user_dict['id']
|
|
return user_dict['id']
|
|
|
|
|
|
-def email_veri_pass(name,db):
|
|
|
|
-
|
|
|
|
|
|
+def email_veri_pass(name):
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
user_dict = next(iter(db.query('SELECT * FROM users where username ="'+name+'"')))
|
|
user_dict = next(iter(db.query('SELECT * FROM users where username ="'+name+'"')))
|
|
user_obj = first(db.query('SELECT * FROM register_veri_code where user_id ="'+str(user_dict['id'])+'"'))
|
|
user_obj = first(db.query('SELECT * FROM register_veri_code where user_id ="'+str(user_dict['id'])+'"'))
|
|
if user_obj == None:
|
|
if user_obj == None:
|