예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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)
예제 #5
0
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
예제 #6
0
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)
예제 #7
0
def profile(user_id):
    user = get_or_abort(User, user_id)
    return json_response(user.json_data)
예제 #8
0
def get_errorhandler(code):
    return lambda e: json_response({"error": str(e)}, code)