mirror of
https://github.com/simple-login/app.git
synced 2024-09-28 20:51:29 +02:00
handle the case 2 users want to use the same email address
This commit is contained in:
parent
b7cbaa6e84
commit
4434ad62dd
@ -67,6 +67,8 @@ def setting():
|
|||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
if request.form.get("form-name") == "update-email":
|
if request.form.get("form-name") == "update-email":
|
||||||
if change_email_form.validate():
|
if change_email_form.validate():
|
||||||
|
# whether user can proceed with the email update
|
||||||
|
new_email_valid = True
|
||||||
if (
|
if (
|
||||||
change_email_form.email.data.lower().strip() != current_user.email
|
change_email_form.email.data.lower().strip() != current_user.email
|
||||||
and not pending_email
|
and not pending_email
|
||||||
@ -78,12 +80,38 @@ def setting():
|
|||||||
email=new_email
|
email=new_email
|
||||||
):
|
):
|
||||||
flash(f"Email {new_email} already used", "error")
|
flash(f"Email {new_email} already used", "error")
|
||||||
|
new_email_valid = False
|
||||||
elif not email_domain_can_be_used_as_mailbox(new_email):
|
elif not email_domain_can_be_used_as_mailbox(new_email):
|
||||||
flash(
|
flash(
|
||||||
"You cannot use this email address as your personal inbox.",
|
"You cannot use this email address as your personal inbox.",
|
||||||
"error",
|
"error",
|
||||||
)
|
)
|
||||||
else:
|
new_email_valid = False
|
||||||
|
# a pending email change with the same email exists from another user
|
||||||
|
elif EmailChange.get_by(new_email=new_email):
|
||||||
|
other_email_change: EmailChange = EmailChange.get_by(
|
||||||
|
new_email=new_email
|
||||||
|
)
|
||||||
|
LOG.warning(
|
||||||
|
"Another user has a pending %s with the same email address. Current user:%s",
|
||||||
|
other_email_change,
|
||||||
|
current_user,
|
||||||
|
)
|
||||||
|
|
||||||
|
if other_email_change.is_expired():
|
||||||
|
LOG.d(
|
||||||
|
"delete the expired email change %s", other_email_change
|
||||||
|
)
|
||||||
|
EmailChange.delete(other_email_change.id)
|
||||||
|
db.session.commit()
|
||||||
|
else:
|
||||||
|
flash(
|
||||||
|
"You cannot use this email address as your personal inbox.",
|
||||||
|
"error",
|
||||||
|
)
|
||||||
|
new_email_valid = False
|
||||||
|
|
||||||
|
if new_email_valid:
|
||||||
email_change = EmailChange.create(
|
email_change = EmailChange.create(
|
||||||
user_id=current_user.id,
|
user_id=current_user.id,
|
||||||
code=random_string(
|
code=random_string(
|
||||||
|
Loading…
Reference in New Issue
Block a user