mirror of
https://github.com/simple-login/app.git
synced 2024-09-20 17:01:29 +02:00
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
|
||||
alias_suffix = alias_suffix.strip()
|
||||
# alias_domain_prefix is either a .random_word or ""
|
||||
alias_domain_prefix, alias_domain = alias_suffix.split("@", 1)
|
||||
|
||||
if alias_domain_prefix:
|
||||
if not alias_domain_prefix.startswith(".") or len(alias_domain_prefix) < 2:
|
||||
LOG.exception(
|
||||
"nonsensical alias suffix %s, user %s", alias_domain_prefix, user
|
||||
)
|
||||
# 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
|
||||
|
||||
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)
|
||||
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
|
||||
else:
|
||||
if alias_domain not in user_custom_domains:
|
||||
|
Loading…
Reference in New Issue
Block a user