示例#1
0
def oauth_callback(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('index'))

    oauth = OAuthSignIn.get_provider(provider)
    social_id, first_name, last_name, email = oauth.callback()
    if social_id is None:
        flash('Authentication failed.')
        return redirect(url_for('index'))

    user = User.query.filter_by(email=email).first()
    if not user:
        user = User(
            first_name=first_name,
            last_name=last_name,
            name=' '.join([first_name, last_name]),
            email=email
        )
        provider_id = ProviderId(id=social_id, user=user)
        db.session.add(user)
        db.session.add(provider_id)
        db.session.commit()

    login_user(user, True)
    return redirect(url_for('index'))
示例#2
0
def oauth_authorize(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('index'))

    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()