refactor verify_prefix
This commit is contained in:
parent
6b085960cb
commit
5486f54955
|
@ -175,20 +175,29 @@ def verify_prefix_suffix(user, alias_prefix, alias_suffix) -> bool:
|
||||||
|
|
||||||
# make sure alias_suffix is either .random_word@simplelogin.co or @my-domain.com
|
# make sure alias_suffix is either .random_word@simplelogin.co or @my-domain.com
|
||||||
alias_suffix = alias_suffix.strip()
|
alias_suffix = alias_suffix.strip()
|
||||||
|
# alias_domain_prefix is either a .random_word or ""
|
||||||
alias_domain_prefix, alias_domain = alias_suffix.split("@", 1)
|
alias_domain_prefix, alias_domain = alias_suffix.split("@", 1)
|
||||||
|
|
||||||
if alias_domain_prefix:
|
# alias_domain must be either one of user custom domains or built-in domains
|
||||||
if not alias_domain_prefix.startswith(".") or len(alias_domain_prefix) < 2:
|
if alias_domain not in user_custom_domains and alias_domain not in ALIAS_DOMAINS:
|
||||||
LOG.exception(
|
LOG.exception("wrong alias suffix %s, user %s", alias_suffix, user)
|
||||||
"nonsensical alias suffix %s, user %s", alias_domain_prefix, user
|
|
||||||
)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if (
|
# built-in domain case:
|
||||||
alias_domain not in user_custom_domains
|
# 1) alias_suffix must start with "." and
|
||||||
and alias_domain not in ALIAS_DOMAINS
|
# 2) alias_domain_prefix must come from the word list
|
||||||
):
|
if alias_domain in ALIAS_DOMAINS and alias_domain not in user_custom_domains:
|
||||||
LOG.exception("wrong alias suffix %s, user %s", alias_suffix, user)
|
if not alias_domain_prefix.startswith("."):
|
||||||
|
LOG.exception("User %s submits a wrong alias suffix %s", user, alias_suffix)
|
||||||
|
return False
|
||||||
|
|
||||||
|
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",
|
||||||
|
alias_suffix,
|
||||||
|
user,
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if alias_domain not in user_custom_domains:
|
if alias_domain not in user_custom_domains:
|
||||||
|
|
Loading…
Reference in a new issue