示例#1
0
def login_by_github_callback():
    """Github OAuth 回调
    """
    code, info = OAuthSignIn.get_provider('github').callback()
    if code is None:
        raise OAuthFail()

    user = User.query.filter_by(github_id = info.get('id')).first()
    if user is None:
        user = User(
                github_id = info.get('id'),
                nickname = info.get('login'),
                name = info.get('name'),
                avatar = info.get('avatar_url'),
                bio = info.get('bio'),
        )
        db.session.add(user)

    # update github info
    user.github_login = info.get('login')
    user.github_email = info.get('email')
    user.github_name = info.get('name')

    # update oauth code
    user.oauth_code = code
    db.session.commit()

    # 如果是admin来请求oauth
    if request.referrer == url_for('admin.admin_login', _external = True):
        if user.github_email in current_app.config['TECHSHOW_ADMIN']:
            login_user(user)
            return redirect(url_for('admin.admin_index'))

    return render_template('oauth_pending.html', oauth_logo = '/static/images/github_logo.png')
示例#2
0
def login_by_qiniu_callback():
    """Qiniu OAuth 回调
    """
    code, info = OAuthSignIn.get_provider('qiniu').callback()
    if code is None:
        raise OAuthFail()

    user = User.query.filter_by(qiniu_id = info.get('uid')).first()
    if user is None:
        user = User(
                qiniu_id = info.get('uid'),
                name = info.get('full_name'),
                nickname = info.get('full_name'),
                gender = info.get('gender')
        )
        db.session.add(user)

    # update qiniu info
    user.qiniu_name = info.get('full_name')
    user.qiniu_email = info.get('email')

    # update oauth_code
    user.oauth_code = code
    db.session.commit()

    # 如果是admin来请求oauth
    if request.referrer == url_for('admin.admin_login', _external = True):
        if user.qiniu_email in current_app.config['TECHSHOW_ADMINs']:
            login_user(user)
            return redirect(url_for('admin.admin_index'))

    return render_template('oauth_pending.html', oauth_logo = '/static/images/qiniu_logo.png')