refactor
This commit is contained in:
parent
291b9a7d55
commit
66e7aa7242
|
@ -38,7 +38,8 @@ def available_suffixes(user: User) -> [bool, str, str]:
|
||||||
# for each user domain, generate both the domain and a random suffix version
|
# for each user domain, generate both the domain and a random suffix version
|
||||||
for alias_domain in user_custom_domains:
|
for alias_domain in user_custom_domains:
|
||||||
suffix = "@" + alias_domain.domain
|
suffix = "@" + alias_domain.domain
|
||||||
suffixes.append((True, suffix, signer.sign(suffix).decode()))
|
suffix_info = (True, suffix, signer.sign(suffix).decode())
|
||||||
|
suffixes.append(suffix_info)
|
||||||
if alias_domain.random_prefix_generation:
|
if alias_domain.random_prefix_generation:
|
||||||
suffix = "." + random_word() + "@" + alias_domain.domain
|
suffix = "." + random_word() + "@" + alias_domain.domain
|
||||||
suffixes.append((True, suffix, signer.sign(suffix).decode()))
|
suffixes.append((True, suffix, signer.sign(suffix).decode()))
|
||||||
|
@ -46,16 +47,22 @@ def available_suffixes(user: User) -> [bool, str, str]:
|
||||||
# then SimpleLogin domain
|
# then SimpleLogin domain
|
||||||
for domain in user.available_sl_domains():
|
for domain in user.available_sl_domains():
|
||||||
suffix = ("" if DISABLE_ALIAS_SUFFIX else "." + random_word()) + "@" + domain
|
suffix = ("" if DISABLE_ALIAS_SUFFIX else "." + random_word()) + "@" + domain
|
||||||
suffixes.append((False, suffix, signer.sign(suffix).decode()))
|
suffix_info = (False, suffix, signer.sign(suffix).decode())
|
||||||
|
suffixes.append(suffix_info)
|
||||||
|
|
||||||
return suffixes
|
return suffixes
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class SuffixInfo:
|
class SuffixInfo:
|
||||||
|
"""Alias suffix info"""
|
||||||
|
|
||||||
|
# whether this is a custom domain
|
||||||
is_custom: bool
|
is_custom: bool
|
||||||
suffix: str
|
suffix: str
|
||||||
signed_suffix: str
|
signed_suffix: str
|
||||||
|
|
||||||
|
# whether this is a premium SL domain. Not apply to custom domain
|
||||||
is_premium: bool
|
is_premium: bool
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -508,7 +508,7 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
else:
|
else:
|
||||||
return sub
|
return sub
|
||||||
|
|
||||||
def verified_custom_domains(self) -> ["CustomDomain"]:
|
def verified_custom_domains(self) -> List["CustomDomain"]:
|
||||||
return CustomDomain.query.filter_by(user_id=self.id, verified=True).all()
|
return CustomDomain.query.filter_by(user_id=self.id, verified=True).all()
|
||||||
|
|
||||||
def mailboxes(self) -> List["Mailbox"]:
|
def mailboxes(self) -> List["Mailbox"]:
|
||||||
|
@ -621,7 +621,7 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
"""
|
"""
|
||||||
return [sl_domain.domain for sl_domain in self.get_sl_domains()]
|
return [sl_domain.domain for sl_domain in self.get_sl_domains()]
|
||||||
|
|
||||||
def get_sl_domains(self) -> ["SLDomain"]:
|
def get_sl_domains(self) -> List["SLDomain"]:
|
||||||
if self.is_premium():
|
if self.is_premium():
|
||||||
query = SLDomain.query
|
query = SLDomain.query
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue