def register(): validator = Registration() data = validate(request.json, validator) user = User.create(data['email'], data['password']) db_session.commit() response = json_response(user.json_data, 201) response.headers['Location'] = url_for("api.profile", user_id=user.id) return response
def create_story(project_id, list_id): project = get_or_abort(Project, project_id) if (not g.user.can_access(project)): raise Unauthorized() list = get_or_abort(UserStoryList, list_id) data = request.json story = UserStory.create(data['title'], data['points'], list) response = json_response(story.json_data, 201) response.headers.set('Location', url_for('api.story', project_id=project_id, list_id=list_id, story_id=story.id)) return response
def login(): data = request.json user = User.get_by_email(data['email']) if (user is None): abort(400) if (not check_password_hash(user.password, data['password'])): abort(400) session = Session(user=user) db_session.commit() response = json_response(session.json_data, 201) response.headers['Location'] = url_for("api.profile", user_id=user.id) return response
def project(project_id): project = get_or_abort(Project, project_id) if (not g.user.can_access(project)): raise Unauthorized() return json_response(project.json_data)
def create_project(): p = Project.create(request.json['name'], g.user) response = json_response(p.json_data, 201) response.headers.set('Location', url_for("api.project", project_id=p.id)) return response
def user_projects(user_id): user = get_or_abort(User, user_id) projects = user.get_projects() data = {"projects": [p.json_data for p in projects]} return json_response(data)
def profile(user_id): user = get_or_abort(User, user_id) return json_response(user.json_data)
def get_errorhandler(code): return lambda e: json_response({"error": str(e)}, code)