|
@@ -156,9 +156,12 @@ async def make_video_slide(request: Request, response: Response, Authorize: Auth
|
|
|
current_user = Authorize.get_jwt_subject()
|
|
|
return templates.TemplateResponse("make_video_slide.html", {"request": request, "response": response})
|
|
|
|
|
|
-@app.post('/user_profile', response_class=HTMLResponse)
|
|
|
+@app.post('/user_profile')
|
|
|
async def user_profile(token: str = Depends(oauth2_scheme)):
|
|
|
db_check()
|
|
|
+ if 'ok'!=verify_jwt_token(token):
|
|
|
+ return {'msg':{'eng':'Please login first','zh':'請先登入帳號'}}
|
|
|
+
|
|
|
user_id = get_user_id(token)
|
|
|
user_obj = first(db.query('SELECT * FROM users where id ="'+str(user_id)+'"'))
|
|
|
|
|
@@ -290,6 +293,14 @@ def logout(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
Authorize.unset_jwt_cookies()
|
|
|
return {"msg": "ok"}
|
|
|
|
|
|
+@app.post('/logout_jwt')
|
|
|
+def logout(token: str = Depends(oauth2_scheme)):
|
|
|
+ db_check()
|
|
|
+ time_stamp = datetime.fromtimestamp(time.time())
|
|
|
+ time_stamp = time_stamp.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ db['jwt_black_list'].insert({'token':token,'datetime':time_stamp})
|
|
|
+ return {"msg": "ok"}
|
|
|
+
|
|
|
@app.post('/get_role')
|
|
|
async def get_role(token: str = Depends(oauth2_scheme)):
|
|
|
|
|
@@ -964,14 +975,19 @@ class text_in(BaseModel):
|
|
|
async def make_voice(in_text:text_in):
|
|
|
x = threading.Thread(target=call_voice, args=(in_text.text,))
|
|
|
x.start()
|
|
|
-
|
|
|
+
|
|
|
+def verify_jwt_token(token):
|
|
|
+ for row in db.query('SELECT * FROM jwt_black_list'):
|
|
|
+ print(row)
|
|
|
+ print(first(db.query('SELECT COUNT(*) FROM jwt_black_list where token="'+token+'"'))['COUNT(*)'])
|
|
|
+ if first(db.query('SELECT COUNT(*) FROM jwt_black_list where token="'+token+'"'))['COUNT(*)'] == 0:
|
|
|
+ return 'ok'
|
|
|
+ else:
|
|
|
+ return 'please login again'
|
|
|
def db_check():
|
|
|
global db
|
|
|
- try:
|
|
|
- db.tables
|
|
|
- except:
|
|
|
- print("database down")
|
|
|
- db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
+ db.close()
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
|
|
|
|
|
|
|