def callback(provider): """Verify authorization status. This method consist in the second step of authorization with the thirth-party provider. If authorization succeed a new user is added to the database if doesn't exists yet. Args: provider: The provider name: facebook, twitter, etc. """ if not current_user.is_anonymous: return redirect(url_for('general.index')) social_id, username, email, picture = OAuthSignIn.get_provider(provider) \ .callback() if social_id is None: flash('Authentication failed.', 'danger') return redirect(url_for('general.index')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id, username, email, picture) db.session.add(user) db.session.commit() login_user(user, True) return redirect(url_for('general.index'))
def callback(provider): """Verify authorization status. This method consist in the second step of authorization with the thirth-party provider. If authorization succeed a new user is added to the database if doesn't exists yet. Args: provider: The provider name: facebook, twitter, etc. """ if not current_user.is_anonymous: return redirect(url_for("general.index")) social_id, username, email, picture = OAuthSignIn.get_provider(provider).callback() if social_id is None: flash("Authentication failed.", "danger") return redirect(url_for("general.index")) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id, username, email, picture) db.session.add(user) db.session.commit() login_user(user, True) return redirect(url_for("general.index"))
def authorize(provider): """Initiate authorization with the provider. If there is no logged in user this method initiate the authorization process with the provider received as parameter. Check OAuthSignIn class for more details about authorize implementation. Args: provider: The provider name: facebook, twitter, etc. """ if not current_user.is_anonymous: return redirect(url_for('general.index')) return OAuthSignIn.get_provider(provider).authorize()
def authorize(provider): """Initiate authorization with the provider. If there is no logged in user this method initiate the authorization process with the provider received as parameter. Check OAuthSignIn class for more details about authorize implementation. Args: provider: The provider name: facebook, twitter, etc. """ if not current_user.is_anonymous: return redirect(url_for("general.index")) return OAuthSignIn.get_provider(provider).authorize()