Merge pull request #167 from simple-login/disable-social-login-signup
disable sign-up via social login
This commit is contained in:
commit
18e50e4a28
|
@ -65,7 +65,7 @@ def facebook_callback():
|
||||||
redirect_uri=_redirect_uri,
|
redirect_uri=_redirect_uri,
|
||||||
)
|
)
|
||||||
facebook = facebook_compliance_fix(facebook)
|
facebook = facebook_compliance_fix(facebook)
|
||||||
token = facebook.fetch_token(
|
facebook.fetch_token(
|
||||||
_token_url,
|
_token_url,
|
||||||
client_secret=FACEBOOK_CLIENT_SECRET,
|
client_secret=FACEBOOK_CLIENT_SECRET,
|
||||||
authorization_response=request.url,
|
authorization_response=request.url,
|
||||||
|
@ -107,35 +107,12 @@ def facebook_callback():
|
||||||
user.profile_picture_id = file.id
|
user.profile_picture_id = file.id
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# create user
|
|
||||||
else:
|
else:
|
||||||
if DISABLE_REGISTRATION:
|
flash(
|
||||||
flash("Registration is closed", "error")
|
"Sorry you cannot sign up via Facebook, please use email/password sign-up instead",
|
||||||
return redirect(url_for("auth.login"))
|
"error",
|
||||||
|
|
||||||
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(),
|
|
||||||
)
|
)
|
||||||
db.session.flush()
|
return redirect(url_for("auth.register"))
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
next_url = None
|
next_url = None
|
||||||
# The activation link contains the original page, for ex authorize page
|
# The activation link contains the original page, for ex authorize page
|
||||||
|
|
|
@ -88,28 +88,12 @@ def github_callback():
|
||||||
email = email.strip().lower()
|
email = email.strip().lower()
|
||||||
user = User.get_by(email=email)
|
user = User.get_by(email=email)
|
||||||
|
|
||||||
# create user
|
|
||||||
if not user:
|
if not user:
|
||||||
if DISABLE_REGISTRATION:
|
flash(
|
||||||
flash("Registration is closed", "error")
|
"Sorry you cannot sign up via Github, please use email/password sign-up instead",
|
||||||
return redirect(url_for("auth.login"))
|
"error",
|
||||||
|
|
||||||
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(),
|
|
||||||
)
|
)
|
||||||
db.session.commit()
|
return redirect(url_for("auth.register"))
|
||||||
login_user(user)
|
|
||||||
email_utils.send_welcome_email(user)
|
|
||||||
|
|
||||||
flash(f"Welcome to SimpleLogin {user.name}!", "success")
|
|
||||||
|
|
||||||
if not SocialAuth.get_by(user_id=user.id, social="github"):
|
if not SocialAuth.get_by(user_id=user.id, social="github"):
|
||||||
SocialAuth.create(user_id=user.id, social="github")
|
SocialAuth.create(user_id=user.id, social="github")
|
||||||
|
|
|
@ -59,7 +59,7 @@ def google_callback():
|
||||||
scope=_scope,
|
scope=_scope,
|
||||||
redirect_uri=_redirect_uri,
|
redirect_uri=_redirect_uri,
|
||||||
)
|
)
|
||||||
token = google.fetch_token(
|
google.fetch_token(
|
||||||
_token_url,
|
_token_url,
|
||||||
client_secret=GOOGLE_CLIENT_SECRET,
|
client_secret=GOOGLE_CLIENT_SECRET,
|
||||||
authorization_response=request.url,
|
authorization_response=request.url,
|
||||||
|
@ -91,35 +91,12 @@ def google_callback():
|
||||||
file = create_file_from_url(user, picture_url)
|
file = create_file_from_url(user, picture_url)
|
||||||
user.profile_picture_id = file.id
|
user.profile_picture_id = file.id
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
# create user
|
|
||||||
else:
|
else:
|
||||||
if DISABLE_REGISTRATION:
|
flash(
|
||||||
flash("Registration is closed", "error")
|
"Sorry you cannot sign up via Google, please use email/password sign-up instead",
|
||||||
return redirect(url_for("auth.login"))
|
"error",
|
||||||
|
|
||||||
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(),
|
|
||||||
)
|
)
|
||||||
db.session.flush()
|
return redirect(url_for("auth.register"))
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
next_url = None
|
next_url = None
|
||||||
# The activation link contains the original page, for ex authorize page
|
# The activation link contains the original page, for ex authorize page
|
||||||
|
|
Loading…
Reference in a new issue