问题描述
我将用户ID存储在令牌中,我在对令牌进行身份验证,然后在获得用户ID验证后,是否在MysqL数据库中启用了该用户。 因此,对于其他表,我也需要用于数据库查询的用户ID,那么如何在这些函数中获取用户ID?有没有办法获取有效载荷并获取身份。 Main.py
app.secret_key = "temp"
api = Api(app)
jwt = JWT(app,authenticate,identity) #/auth automatically
Security.py
def authenticate(username,password):
user = User.find_by_username(username)
if user and user.password == password:
return user
def identity(payload):
user_id = payload["identity"]
return User.find_by_userid(user_id)
def find_by_userid(cls,_id):
#db connection
query = "select uid from users where uid= %s"
消息文件
#i want user id in this function as well
def fetch_msg_(cls,uid):
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)