def socket(token) : # 验证Token res = Safety.decode(token) if res==None : return {'state':False,'msg':'Token验证失败!'} name = Env.admin_token_prefix+str(res['uid']) # 是否超时 time = Redis.run().ttl(name) if time<=0 : return {'state':False,'msg':'Token已超时!'} res['n_time'] = time return {'state':True,'data':res}
def verify(self) : # 获取Token data = None if request.method=='POST': data=request.form elif request.method=='GET': data=request.args token = data.get('token') # 验证Token res = Safety.decode(token) if res==None : self.error('Token验证失败!') name = Env.admin_token_prefix+str(res['uid']) # 是否超时 time = Redis.run().ttl(name) if time<=0 : self.error('Token已超时!') res['n_time'] = time # 是否续期 if Env.admin_token_auto : Redis.run().setex(name,Env.admin_token_time,'1') return res