def func_wrapper(*args, **kwargs): content = json.loads(request.data) if "token" in content and content[ "token"] != "" or "neo_user_token" in request.cookies: if "token" in content: json_token = content["token"] else: json_token = request.cookies.get("neo_user_token") client = User.decode_auth_token(json_token) if client.type != account_type and account_type == "ADMIN": raise InsufficientAccountRight kwargs['client'] = client kwargs["is_device"] = False return func(*args, **kwargs) if "device_token" in content and content[ "device_token"] != "" or "neo_device_token" in request.cookies: if "device_token" in content: json_token = content["device_token"] else: json_token = request.cookies.get("neo_device_token") client = Device.decode_auth_token(json_token) kwargs['client'] = client kwargs["is_device"] = True return func(*args, **kwargs) raise TokenNotFound
def func_wrapper(*args, **kwargs): try: content = json.loads(request.data) if content is None: raise JsonNotFound for elem in definer: if elem is not None: if elem[2] and elem[0] not in content: raise JsonParameterNotFound(elem[0]) if elem[0] in content and type( content[elem[0]]) is not type(elem[1]): raise JsonParameterFormatError(elem[0], type(elem[1])) if secured is not None: if "token" in content and content[ "token"] != "" or "neo_user_token" in request.cookies: if "token" in content: json_token = content["token"] else: json_token = request.cookies.get("neo_user_token") client = User.decode_auth_token(json_token) if client.type != secured and secured == "ADMIN": raise InsufficientAccountRight kwargs['client'] = client kwargs["is_device"] = False if "device_token" in content and content[ "device_token"] != "" or "neo_device_token" in request.cookies: if "device_token" in content: json_token = content["device_token"] else: json_token = request.cookies.get("neo_device_token") client = Device.decode_auth_token(json_token) kwargs['client'] = client kwargs["is_device"] = True kwargs['content'] = content return func(*args, **kwargs) except ContentException: response = jsonify({ "success": False, "message": ContentException.message }) response.status_code = ContentException.status_code return response except json.decoder.JSONDecodeError: response = jsonify({ "success": False, "message": JsonUnreadable.message }) response.status_code = JsonUnreadable.status_code return response
def logout(device_token): try: device = Device.decode_auth_token(device_token) device.circle.notify_users(p2={ 'event': 'device', 'type': 'disconnect', 'device_id': device.id }) response = {"data": {"success": True}, "status_code": 200} except e_device.DeviceException as exception: response = { "data": { "success": False, "message": exception.message }, "status_code": exception.status_code } return response