예제 #1
0
def oauth_callback(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('login.index'))
    oauth = OAuthSignIn.get_provider(provider)
    social_id, username, email = oauth.callback()
    if social_id is None:
        flash('Authentication failed.')
        return redirect(url_for('login.index'))
    print social_id
    print username
    print email
    try:
        user = User.objects().get(social_id=social_id)
    except User.DoesNotExist:
        user = User(social_id=social_id, username=username, email=email)
        user.save()

    login_user(user, True)
    return redirect(url_for('login.index'))
예제 #2
0
def oauth_authorize(provider):
    if not current_user.is_anonymous:
        return redirect(url_for('login.index'))
    oauth = OAuthSignIn.get_provider(provider)
    return oauth.authorize()