Ejemplo n.º 1
0
def githubCallback():
    if 'code' not in request.args:
        return '', 500

    # Fetch user from GitHub OAuth and store in session
    github = GitHub(GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET)
    access_token = github.get_token(request.args['code'])

    if access_token is None:
        flash('Could not authorize your request. Please try again.', 'danger')
        return '', 404

    user = User.find_or_create_from_token(access_token)

    session['access_token'] = access_token
    session['user_id'] = user.id

    # Transfer tasks in session to user database
    if 'tasks' in session:
        for task in session['tasks']:
            user_id = session['user_id']
            task_desc = task['description']
            Task.add_task(task_desc, user_id)

        session.pop('tasks', None)

    return redirect(url_for('home.index'))
Ejemplo n.º 2
0
def githubCallback():
    if 'code' not in request.args:
        return '', 500

    # Fetch user from GitHub OAuth and store in session
    github = GitHub(GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET)
    access_token = github.get_token(request.args['code'])
    if access_token is None:
        flash('Could not authorize your request. Please try again.', 'danger')
        return '', 404

    user = User.find_or_create_from_token(access_token)

    session['access_token'] = access_token
    session['user_id'] = user.id

    return redirect(url_for('home.index'))