def decorator(func): @functools.wraps(func) def inner(req, *args, **kwargs): # methods校验 methods_check(req, methods) # NOTE:暂时弃用,req.user校验 # request_ckeck(req, login_required, perm) # NOTE:推荐 # req.token校验,更新token并通过接口返回 request_token_check(req, func, jwt_required, *args, **kwargs) return func(req, *args, **kwargs) urlpatterns.append(url(r'^{path}$'.format(path=path), inner, name=name)) return inner
def decorator(func): @functools.wraps(func) def inner(req, *args, **kwargs): # methods校验 methods_check(req, methods) # request_ckeck(req, login_required, perm) request_token_check(req, func, jwt_required, *args, **kwargs) return func(req, *args, **kwargs) urlpatterns.append( url(r'^{path}$'.format(path=path), inner, name='{n}_defined in {p} via {m}'.format(n=name or '', p=path, m=str(methods)))) return inner
def decorator(func): def inner(request, *args, **kwargs): # methods校验 try: assert request.method in methods except AssertionError: dataformat = get_dataformat(request) message = 'Method Not Allowed ({method}): {path}'.format( method=request.method, path=request.path) r = dict(status_code=HTTP_405_METHOD_NOT_ALLOWED, detail=message) response = HttpResponseNotAllowed( methods, json.dumps(r), content_type=dataformat.content_type) log.warn(message) return response # request.user校验 try: assert login_required check_user(request.user, perm) except AssertionError: pass except InsufficientPermissionsError: message = 'user get no permission (perm:{perm})'.format( perm=perm) log.warn(message) raise InsufficientPermissionsError(detail=message) # NOTE:推荐 # request.jwt校验 try: assert jwt_required jwt_token_verify_handler(request.jwt) except AssertionError: pass except: message = 'user not authentication' log.warn(message) raise InvalidJwtToken(detail=message) return func(request, *args, **kwargs) urlpatterns.append( url(r'^{path}/$'.format(path=path), inner, name=name)) return inner