def dispatch_request(self, provider_name): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn(provider_name=provider_name) logged_user = oauth.callback() if not logged_user: flash(_('Authentication failed.')) return redirect(url_for('index')) try: user = User.objects.get(email=logged_user['email']) user.avatar = logged_user['avatar'] user.save() except DoesNotExist: user = User(**logged_user) user.save() login_user(user, remember=True) return redirect(request.args.get('next') or url_for('index'))
def google_callback(): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider('google') email = oauth.callback() if email is None: return redirect(url_for('login')) user = mongo.db.users.find_one({'email': email}) if user is None: id = mongo.db.users.insert({'email': email}) user = mongo.db.users.find_one({'_id': id}) login_user(User(user), remember=False) return redirect(url_for('index'))
def oauth_callback(provider): print(provider) if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) email = oauth.callback() if email is None: flash('Authentication failed.') return redirect(url_for('index')) user=User.query.filter_by(email=email).first() if not user: username = email.split('@')[0] stri=" " user=User(username=username, email=email,password=bcrypt.generate_password_hash(stri).decode('utf-8')) db.session.add(user) db.session.commit() login_user(user, remember=True) return redirect(url_for('index'))
def callback(provider): """"Callback from the OAuth provider.""" if not current_user.is_anonymous(): return redirect(url_for('main_page')) oauth = OAuthSignIn.get_provider(provider) username, email = oauth.callback() if email is None: # TODO: OAuth failed -> redirect somewhere else return redirect(url_for('main_page')) # Check if the user exists in the db, else create user = models.User.query.filter_by(email=email).first() if not user: user = models.User(email, username) db.session.add(user) db.session.commit() login_user(user, remember=True) user.authenticated = True db.session.add(user) db.session.commit() return redirect(url_for('dashboard'))
def dispatch_request(self, provider_name): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn(provider_name=provider_name) return oauth.authorize()
def oauth_authorize(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth = OAuthSignIn.get_provider(provider) return oauth.authorize()
def oauth_authorize(provider): """Requests authorization to the OAuth provider.""" oauth = OAuthSignIn.get_provider(provider) return oauth.authorize()