mirror of
https://github.com/simple-login/app.git
synced 2024-11-13 07:31:12 +01:00
Use a shorter suffix in case of custom domain (#1670)
This commit is contained in:
parent
c09b5bc526
commit
1f9d784382
2 changed files with 13 additions and 3 deletions
|
@ -99,7 +99,12 @@ def get_alias_suffixes(user: User) -> [AliasSuffix]:
|
|||
# for each user domain, generate both the domain and a random suffix version
|
||||
for custom_domain in user_custom_domains:
|
||||
if custom_domain.random_prefix_generation:
|
||||
suffix = "." + user.get_random_alias_suffix() + "@" + custom_domain.domain
|
||||
suffix = (
|
||||
"."
|
||||
+ user.get_random_alias_suffix(custom_domain)
|
||||
+ "@"
|
||||
+ custom_domain.domain
|
||||
)
|
||||
alias_suffix = AliasSuffix(
|
||||
is_custom=True,
|
||||
suffix=suffix,
|
||||
|
|
|
@ -1000,16 +1000,21 @@ class User(Base, ModelMixin, UserMixin, PasswordOracle):
|
|||
> 0
|
||||
)
|
||||
|
||||
def get_random_alias_suffix(self):
|
||||
def get_random_alias_suffix(self, custom_domain: Optional["CustomDomain"] = None):
|
||||
"""Get random suffix for an alias based on user's preference.
|
||||
|
||||
Use a shorter suffix in case of custom domain
|
||||
|
||||
Returns:
|
||||
str: the random suffix generated
|
||||
"""
|
||||
if self.random_alias_suffix == AliasSuffixEnum.random_string.value:
|
||||
return random_string(config.ALIAS_RANDOM_SUFFIX_LENGTH, include_digits=True)
|
||||
return random_words(1, 3)
|
||||
|
||||
if custom_domain is None:
|
||||
return random_words(1, 3)
|
||||
|
||||
return random_words(1)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<User {self.id} {self.name} {self.email}>"
|
||||
|
|
Loading…
Reference in a new issue