Compare commits

...

1 commit

Author SHA1 Message Date
Son NK 43857495b3 suggestion 2020-10-07 17:57:02 +02:00

View file

@ -174,35 +174,23 @@ def verify_prefix_suffix(user, alias_prefix, alias_suffix) -> bool:
# make sure alias_suffix is either .random_word@simplelogin.co or @my-domain.com
alias_suffix = alias_suffix.strip()
if alias_suffix.startswith("@"):
alias_domain = alias_suffix[1:]
# alias_domain can be either custom_domain or if DISABLE_ALIAS_SUFFIX, one of the default ALIAS_DOMAINS
if DISABLE_ALIAS_SUFFIX:
if (
alias_domain not in user_custom_domains
and alias_domain not in ALIAS_DOMAINS
):
LOG.exception("wrong alias suffix %s, user %s", alias_suffix, user)
return False
else:
if alias_domain not in user_custom_domains:
LOG.exception("wrong alias suffix %s, user %s", alias_suffix, user)
return False
else:
if not alias_suffix.startswith("."):
# alias_domain_prefix is either a .random_word or ""
alias_domain_prefix, alias_domain = alias_suffix.split("@", 1)
# alias_domain must be either one of user custom domains or built-in domains
if alias_domain not in user_custom_domains and alias_domain not in ALIAS_DOMAINS:
LOG.exception("wrong alias suffix %s, user %s", alias_suffix, user)
return False
# built-in domain case:
# 1) alias_suffix must start with "." and
# 2) alias_domain_prefix must come from the word list
if alias_domain in ALIAS_DOMAINS and alias_domain not in user_custom_domains:
if not alias_domain_prefix.startswith("."):
LOG.exception("User %s submits a wrong alias suffix %s", user, alias_suffix)
return False
full_alias = alias_prefix + alias_suffix
if not email_belongs_to_alias_domains(full_alias):
LOG.exception(
"Alias suffix should end with one of the alias domains %s",
user,
alias_suffix,
)
return False
random_word_part = alias_suffix[1 : alias_suffix.find("@")]
random_word_part = alias_domain_prefix[1:]
if not word_exist(random_word_part):
LOG.exception(
"alias suffix %s needs to start with a random word, user %s",