From ccb30a2defa6034d319fdc9a50911940ad6bbce4 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Thu, 7 May 2020 22:01:14 +0200 Subject: [PATCH] disable sign-up via social login --- app/auth/views/facebook.py | 33 +++++---------------------------- app/auth/views/github.py | 24 ++++-------------------- app/auth/views/google.py | 33 +++++---------------------------- 3 files changed, 14 insertions(+), 76 deletions(-) diff --git a/app/auth/views/facebook.py b/app/auth/views/facebook.py index fb64c537..049037c1 100644 --- a/app/auth/views/facebook.py +++ b/app/auth/views/facebook.py @@ -65,7 +65,7 @@ def facebook_callback(): redirect_uri=_redirect_uri, ) facebook = facebook_compliance_fix(facebook) - token = facebook.fetch_token( + facebook.fetch_token( _token_url, client_secret=FACEBOOK_CLIENT_SECRET, authorization_response=request.url, @@ -107,35 +107,12 @@ def facebook_callback(): user.profile_picture_id = file.id db.session.commit() - # create user else: - if DISABLE_REGISTRATION: - flash("Registration is closed", "error") - return redirect(url_for("auth.login")) - - if not can_be_used_as_personal_email(email) or email_already_used(email): - flash(f"You cannot use {email} as your personal inbox.", "error") - return redirect(url_for("auth.login")) - - LOG.d("create facebook user with %s", facebook_user_data) - user = User.create( - email=email, - name=facebook_user_data["name"], - activated=True, - referral=get_referral(), + flash( + "Sorry you cannot sign up via Facebook, please use email/password sign-up instead", + "error", ) - db.session.flush() - - if picture_url: - LOG.d("set user profile picture to %s", picture_url) - file = create_file_from_url(user, picture_url) - user.profile_picture_id = file.id - - db.session.commit() - login_user(user) - email_utils.send_welcome_email(user) - - flash(f"Welcome to SimpleLogin {user.name}!", "success") + return redirect(url_for("auth.register")) next_url = None # The activation link contains the original page, for ex authorize page diff --git a/app/auth/views/github.py b/app/auth/views/github.py index d9b467a2..fc37e78d 100644 --- a/app/auth/views/github.py +++ b/app/auth/views/github.py @@ -88,28 +88,12 @@ def github_callback(): email = email.strip().lower() user = User.get_by(email=email) - # create user if not user: - if DISABLE_REGISTRATION: - flash("Registration is closed", "error") - return redirect(url_for("auth.login")) - - if not can_be_used_as_personal_email(email) or email_already_used(email): - flash(f"You cannot use {email} as your personal inbox.", "error") - return redirect(url_for("auth.login")) - - LOG.d("create github user") - user = User.create( - email=email, - name=github_user_data.get("name") or "", - activated=True, - referral=get_referral(), + flash( + "Sorry you cannot sign up via Github, please use email/password sign-up instead", + "error", ) - db.session.commit() - login_user(user) - email_utils.send_welcome_email(user) - - flash(f"Welcome to SimpleLogin {user.name}!", "success") + return redirect(url_for("auth.register")) if not SocialAuth.get_by(user_id=user.id, social="github"): SocialAuth.create(user_id=user.id, social="github") diff --git a/app/auth/views/google.py b/app/auth/views/google.py index 2dc99703..3e44b929 100644 --- a/app/auth/views/google.py +++ b/app/auth/views/google.py @@ -59,7 +59,7 @@ def google_callback(): scope=_scope, redirect_uri=_redirect_uri, ) - token = google.fetch_token( + google.fetch_token( _token_url, client_secret=GOOGLE_CLIENT_SECRET, authorization_response=request.url, @@ -91,35 +91,12 @@ def google_callback(): file = create_file_from_url(user, picture_url) user.profile_picture_id = file.id db.session.commit() - # create user else: - if DISABLE_REGISTRATION: - flash("Registration is closed", "error") - return redirect(url_for("auth.login")) - - if not can_be_used_as_personal_email(email) or email_already_used(email): - flash(f"You cannot use {email} as your personal inbox.", "error") - return redirect(url_for("auth.login")) - - LOG.d("create google user with %s", google_user_data) - user = User.create( - email=email, - name=google_user_data["name"], - activated=True, - referral=get_referral(), + flash( + "Sorry you cannot sign up via Google, please use email/password sign-up instead", + "error", ) - db.session.flush() - - if picture_url: - LOG.d("set user profile picture to %s", picture_url) - file = create_file_from_url(user, picture_url) - user.profile_picture_id = file.id - - db.session.commit() - login_user(user) - email_utils.send_welcome_email(user) - - flash(f"Welcome to SimpleLogin {user.name}!", "success") + return redirect(url_for("auth.register")) next_url = None # The activation link contains the original page, for ex authorize page