🐛 fix style

This commit is contained in:
devStorm 2021-05-13 19:29:26 -07:00
parent 5c74ad2dc0
commit 30183ac8c3
No known key found for this signature in database
GPG Key ID: D52E1B66F336AC57
5 changed files with 16 additions and 6 deletions

View File

@ -375,4 +375,4 @@ ALIAS_LIMIT = os.environ.get("ALIAS_LIMIT") or "100/day;50/hour;5/minute"
ENABLE_SPAM_ASSASSIN = "ENABLE_SPAM_ASSASSIN" in os.environ
ALIAS_RAND_SUFFIX_LENGTH = int(os.environ.get("ALIAS_RAND_SUFFIX_LENGTH", 5))
ALIAS_RAND_SUFFIX_LENGTH = int(os.environ.get("ALIAS_RAND_SUFFIX_LENGTH", 5))

View File

@ -25,7 +25,7 @@ from app.models import (
DomainDeletedAlias,
AliasSuffixEnum,
)
from app.utils import random_word, word_exist, random_string
from app.utils import random_word, random_string
signer = TimestampSigner(CUSTOM_ALIAS_SECRET)
@ -251,6 +251,7 @@ def custom_alias():
mailboxes=mailboxes,
)
def get_suffix(user: User) -> str:
"""Get random suffix for an alias based on user's preference.
@ -261,9 +262,10 @@ def get_suffix(user: User) -> str:
str: the random suffix generated
"""
if user.random_alias_suffix == AliasSuffixEnum.rnd_string.value:
return random_string(ALIAS_RAND_SUFFIX_LENGTH, include_digits = True)
return random_string(ALIAS_RAND_SUFFIX_LENGTH, include_digits=True)
return random_word()
def verify_prefix_suffix(user: User, alias_prefix, alias_suffix) -> bool:
"""verify if user could create an alias with the given prefix and suffix"""
if not alias_prefix or not alias_suffix: # should be caught on frontend

View File

@ -15,7 +15,12 @@ from wtforms import StringField, validators
from wtforms.fields.html5 import EmailField
from app import s3, email_utils
from app.config import URL, FIRST_ALIAS_DOMAIN, JOB_DELETE_ACCOUNT, ALIAS_RAND_SUFFIX_LENGTH
from app.config import (
URL,
FIRST_ALIAS_DOMAIN,
JOB_DELETE_ACCOUNT,
ALIAS_RAND_SUFFIX_LENGTH,
)
from app.dashboard.base import dashboard_bp
from app.email_utils import (
email_can_be_used_as_mailbox,

View File

@ -161,10 +161,12 @@ class AliasGeneratorEnum(EnumE):
word = 1 # aliases are generated based on random words
uuid = 2 # aliases are generated based on uuid
class AliasSuffixEnum(EnumE):
word = 0 # Random word from dictionary file
rnd_string = 1 # Completely random string
class Fido(db.Model, ModelMixin):
__tablename__ = "fido"
credential_id = db.Column(db.String(), nullable=False, unique=True, index=True)
@ -294,7 +296,8 @@ class User(db.Model, ModelMixin, UserMixin):
# Random word from dictionary file -> 0
# Completely random string -> 1
random_alias_suffix = db.Column(
db.Integer, nullable=False,
db.Integer,
nullable=False,
default=AliasSuffixEnum.rnd_string.value,
server_default=str(AliasSuffixEnum.rnd_string.value),
)

View File

@ -32,7 +32,7 @@ def random_string(length=10, include_digits=False):
letters = string.ascii_lowercase
if include_digits:
letters += string.digits
return "".join(random.choice(letters) for _ in range(length))