Example #1
0
def authorized(next=None):
    next_url = request.args.get('next') or url_for('frontend.splash')

    if not 'code' in request.args:
        flash(Markup(_('You did not authorize this application with Github. Please see <a href="https://github.com/xen/fontbakery/blob/master/INSTALL.md#github-authorization">INSTALL</a> file for details.')))
        return redirect(next_url)

    redirect_uri = url_for('.authorized', _external=True)
    data = dict(code=request.args['code'], redirect_uri=redirect_uri)
    auth = github.get_auth_session(data=data)

    token = auth.access_token
    me = auth.get('user').json()

    user = User.get_or_init(me['login'])

    # if user.id is None:
    #     new record isn't saved yet
    #     flash(_('Welcome to Bakery.'))

    # update user data
    user.name = me.get('name', me.get('login'))
    user.github_access_token = token
    user.avatar = me['gravatar_id']
    user.email = me['email']

    # save to database
    db.session.add(user)
    db.session.commit()

    session['user_id'] = user.id
    g.user = user
    return redirect(next_url)
Example #2
0
def authorized(next=None):
    next_url = request.args.get('next') or url_for('frontend.splash')

    if not 'code' in request.args:
        flash(Markup(_(('You did not authorize this application with Github.'
                        ' Please see <a href="https://github.com/xen/fontbakery/blob/master/INSTALL.md#github-authorization">INSTALL</a>'
                        ' file for details.'))))
        return redirect(next_url)

    redirect_uri = url_for('.authorized', _external=True)
    data = dict(code=request.args['code'], redirect_uri=redirect_uri)
    auth = github.get_auth_session(data=data)

    user = authorize_user(auth.get('user').json(), auth.access_token)

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

    return redirect(next_url)
Example #3
0
def authorized(next=None):
    next_url = request.args.get('next') or url_for('frontend.splash')

    if not 'code' in request.args:
        flash(
            Markup(
                _('You did not authorize this application with Github. Please see <a href="https://github.com/xen/fontbakery/blob/master/INSTALL.md#github-authorization">INSTALL</a> file for details.'
                  )))
        return redirect(next_url)

    redirect_uri = url_for('.authorized', _external=True)
    data = dict(code=request.args['code'], redirect_uri=redirect_uri)
    auth = github.get_auth_session(data=data)

    token = auth.access_token
    me = auth.get('user').json()

    user = User.get_or_init(me['login'])

    # if user.id is None:
    #     new record isn't saved yet
    #     flash(_('Welcome to Bakery.'))

    # update user data
    user.name = me.get('name', me.get('login'))
    user.github_access_token = token
    user.avatar = me['gravatar_id']
    user.email = me['email']

    # save to database
    db.session.add(user)
    db.session.commit()

    session['user_id'] = user.id
    g.user = user
    return redirect(next_url)