def register(current_user): if request.method == 'POST': if request.content_type == content_type: requestJson = request.get_json(force = True) content = removePass(user_control.add_user(requestJson)) else: content = errorContent() return buildResponse('application/json', content)
def login(): if request.method == 'POST': if request.content_type == content_type: requestJson = request.get_json(force = True) content = removePass(user_control.login(requestJson, secret)) else: content = errorContent() return buildResponse('application/json', content)
def update(current_user, id): method = request.method if method == 'PUT' or method == 'PATCH': if request.content_type == content_type: requestJson = request.get_json(force = True) content = removePass(user_control.update_user(id, requestJson)) else: content = errorContent() return buildResponse('application/json', content)
def decorated(*args, **kwargs): token = None if 'x-access-token' in request.headers: token = request.headers['x-access-token'] if not token: content = 401, {"error": 'Unauthorized, token is missing'} return buildResponse('application/json', content) secret = 'developedbydbgroldan' try: data = jwt.decode(token, secret) code, user = UserService().get(data.get('id')) current_user = user if code == 200 else False if not current_user: content = 401, 'Unauthorized, token is invalid' return buildResponse('application/json', content) except Exception as e: content = 401, {"error": 'Unauthorized, token is invalid'} return buildResponse('application/json', content) return f(current_user, *args, **kwargs)
def delete(current_user, id): content = removePass(user_control.delete(id)) if request.content_type == content_type else errorContent() return buildResponse('application/json', content)
def get_all(current_user): content = removePassSet(user_control.get_all()) if request.content_type == content_type else errorContent() print('********', content) return buildResponse('application/json', content)
def not_found(e): content = 200, {'error': 'Not found'} return buildResponse('application/json', content)
def index(): content = 200, {'message': 'Server started successfully'} return buildResponse('application/json', content)