Merge pull request #100 from simple-login/mailbox-root-email

support the case user wants to re-add their real email as mailbox
This commit is contained in:
Son Nguyen Kim 2020-03-08 10:14:41 +01:00 committed by GitHub
commit b5637d6415
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -8,10 +8,11 @@ from wtforms.fields.html5 import EmailField
from app.config import EMAIL_DOMAIN, ALIAS_DOMAINS, MAILBOX_SECRET, URL
from app.dashboard.base import dashboard_bp
from app.email_utils import (
send_email,
render,
can_be_used_as_personal_email,
email_already_used,
mailbox_already_used,
render,
send_email,
)
from app.extensions import db
from app.log import LOG
@ -80,7 +81,7 @@ def mailbox_route():
if new_mailbox_form.validate():
mailbox_email = new_mailbox_form.email.data.lower()
if email_already_used(mailbox_email):
if mailbox_already_used(mailbox_email, current_user):
flash(f"{mailbox_email} already used", "error")
elif not can_be_used_as_personal_email(mailbox_email):
flash(f"You cannot use {mailbox_email}.", "error")

View File

@ -348,3 +348,18 @@ def email_already_used(email: str) -> bool:
return True
return False
def mailbox_already_used(email: str, user) -> bool:
if Mailbox.get_by(email=email):
return True
# support the case user wants to re-add their real email as mailbox
# can happen when user changes their root email and wants to add this new email as mailbox
if email == user.email:
return False
if User.get_by(email=email):
return True
return False