wuwukai007
2019-08-12 17:03:40 +08:00
def __call__(self,func):
print(self,func)
@functools.wraps(func)
def hander(selff,request,*args,**kwargs):
print(selff)
try:
token = request.COOKIES.get('token')
payload =selff. _check_payload(token=token)
user = selff._check_user(payload=payload)
except Exception as e:
# r = Response({'code': 400, 'message': e.detail[0]})
r = Response({'code': 400, 'message': str(e)})
# r.set_cookie('token','111')
return r
else:
resp = func(selff, request, *args, **kwargs)
try:
new_token = selff.validate({'token':token})
except Exception as e:
return Response({'code':'令牌更新错误'})
else:
resp.set_cookie('token',new_token['token'])
return resp
return hander
@check_token('1')
def list(self, request, *args, **kwargs):
resp = super(generics.ListCreateAPIView,self).list(request,*args,**kwargs)
return resp