Example #1
0
def authorized(access_token):
    next_url = request.args.get('next') or url_for('home')
    post_auth_redirect = session.pop('post_auth_redirect',
                                     url_for('job_enqueue'))

    if access_token is None:
        return redirect(next_url)

    params = {'access_token': access_token}

    gh_user = github.get('user', params=params)
    github_login = gh_user['login']

    if settings.GITHUB_ORG:
        res = github.raw_request('GET', 'orgs/{0}/members/{1}'.format(
            settings.GITHUB_ORG, github_login), params=params)
        if res.status_code != 204:
            session.pop('user_id', None)
            return redirect(url_for('unauthorized'))

    user = User.query.filter_by(github_login=github_login).first()
    if user is None:
        user = User(github_login=github_login)
        db_session.add(user)
    user.github_name = gh_user.get('name')
    user.github_avatar = gh_user.get('avatar_url')
    user.github_access_token = access_token
    db_session.commit()

    session['user_id'] = user.id
    return redirect(post_auth_redirect)
Example #2
0
def authorized(access_token):
    next_url = request.args.get('next') or url_for('home')
    post_auth_redirect = session.pop('post_auth_redirect',
                                     url_for('job_enqueue'))

    if access_token is None:
        return redirect(next_url)

    params = {'access_token': access_token}

    gh_user = github.get('user', params=params)
    github_login = gh_user['login']

    if settings.GITHUB_ORG:
        res = github.raw_request('GET',
                                 'orgs/{0}/members/{1}'.format(
                                     settings.GITHUB_ORG, github_login),
                                 params=params)
        if res.status_code != 204:
            session.pop('user_id', None)
            return redirect(url_for('unauthorized'))

    user = User.query.filter_by(github_login=github_login).first()
    if user is None:
        user = User(github_login=github_login)
        db_session.add(user)
    user.github_name = gh_user.get('name')
    user.github_avatar = gh_user.get('avatar_url')
    user.github_access_token = access_token
    db_session.commit()

    session['user_id'] = user.id
    return redirect(post_auth_redirect)
Example #3
0
def job_enqueue_post():
    form = EnqueueJobForm(request.form, deploy_job=True)
    if not form.validate():
        return jsonify(dict(data=form.errors, _status=False)), 400

    job = QueuedJob()
    form.populate_obj(job)
    db_session.add(job)
    db_session.commit()

    return jsonify(dict(data=True, _status=True))
Example #4
0
def job_enqueue_post():
    form = EnqueueJobForm(request.form, deploy_job=True)
    if not form.validate():
        return jsonify(dict(data=form.errors, _status=False)), 400

    job = QueuedJob()
    form.populate_obj(job)
    db_session.add(job)
    db_session.commit()

    return jsonify(dict(data=True, _status=True))