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:
commit
b5637d6415
|
@ -8,10 +8,11 @@ from wtforms.fields.html5 import EmailField
|
||||||
from app.config import EMAIL_DOMAIN, ALIAS_DOMAINS, MAILBOX_SECRET, URL
|
from app.config import EMAIL_DOMAIN, ALIAS_DOMAINS, MAILBOX_SECRET, URL
|
||||||
from app.dashboard.base import dashboard_bp
|
from app.dashboard.base import dashboard_bp
|
||||||
from app.email_utils import (
|
from app.email_utils import (
|
||||||
send_email,
|
|
||||||
render,
|
|
||||||
can_be_used_as_personal_email,
|
can_be_used_as_personal_email,
|
||||||
email_already_used,
|
email_already_used,
|
||||||
|
mailbox_already_used,
|
||||||
|
render,
|
||||||
|
send_email,
|
||||||
)
|
)
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
|
@ -80,7 +81,7 @@ def mailbox_route():
|
||||||
if new_mailbox_form.validate():
|
if new_mailbox_form.validate():
|
||||||
mailbox_email = new_mailbox_form.email.data.lower()
|
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")
|
flash(f"{mailbox_email} already used", "error")
|
||||||
elif not can_be_used_as_personal_email(mailbox_email):
|
elif not can_be_used_as_personal_email(mailbox_email):
|
||||||
flash(f"You cannot use {mailbox_email}.", "error")
|
flash(f"You cannot use {mailbox_email}.", "error")
|
||||||
|
|
|
@ -348,3 +348,18 @@ def email_already_used(email: str) -> bool:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
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
|
||||||
|
|
Loading…
Reference in a new issue