def verify_password(login, password): user = service.check_login(login) if user: if user.check_password(password): return True else: unauthorized('wrong password') unauthorized('unauthorized access')
def get_tasks(): user = service.check_login( auth.username()) # Если существует возвращает объект User if user is None: return server_error('user`s none') tasks = service.get_tasks(user) return make_response( jsonify({'tasks': [task.to_dict() for task in tasks]}), 200)
def get_task(task_id: int): user = service.check_login( auth.username()) # Если существует возвращает объект User if user is None: return server_error('user`s none') task = service.get_task(user, task_id) if task is None: return not_found(f'task {task_id} was not found') return make_response(jsonify(task.to_dict()), 200)
def done_task(task_id: int) -> object: user = service.check_login( auth.username()) # Если существует возвращает объект User task = service.done_task(user, task_id) if task[0] == 1: return not_found(task[1]) elif task[0] == 2: return server_error(task[1]) response = {'status': 200, 'message': task[1], 'task': task[2].to_dict()} return make_response(jsonify(response), 200)
def create_task() -> object: user = service.check_login( auth.username()) # Если существует возвращает объект User data = request.get_json() or {} if not data: return bad_request('missing json request') elif 'title' not in data: return bad_request('the title field is missing') elif 'description' not in data: return bad_request('the description field is missing') elif 'deadline' not in data: return bad_request('the deadline field is missing') task = service.create_task(data, user) if task[0] == 1: return bad_request(task[1]) elif task[0] == 2: return server_error(task[1]) response = {'status': 201, 'task': task[2].to_dict()} return make_response(jsonify(response), 201)