Ver Fonte

make sure to remove whitespace in alias

Son NK há 4 anos atrás
pai
commit
2d395f99bb

+ 4 - 4
app/api/views/new_custom_alias.py

@@ -60,8 +60,8 @@ def new_custom_alias():
     if not data:
     if not data:
         return jsonify(error="request body cannot be empty"), 400
         return jsonify(error="request body cannot be empty"), 400
 
 
-    alias_prefix = data.get("alias_prefix", "").strip().lower()
-    alias_suffix = data.get("alias_suffix", "").strip().lower()
+    alias_prefix = data.get("alias_prefix", "").strip().lower().replace(" ", "")
+    alias_suffix = data.get("alias_suffix", "").strip().lower().replace(" ", "")
     note = data.get("note")
     note = data.get("note")
     alias_prefix = convert_to_id(alias_prefix)
     alias_prefix = convert_to_id(alias_prefix)
 
 
@@ -132,7 +132,7 @@ def new_custom_alias_v2():
     if not data:
     if not data:
         return jsonify(error="request body cannot be empty"), 400
         return jsonify(error="request body cannot be empty"), 400
 
 
-    alias_prefix = data.get("alias_prefix", "").strip().lower()
+    alias_prefix = data.get("alias_prefix", "").strip().lower().replace(" ", "")
     signed_suffix = data.get("signed_suffix", "").strip()
     signed_suffix = data.get("signed_suffix", "").strip()
     note = data.get("note")
     note = data.get("note")
     alias_prefix = convert_to_id(alias_prefix)
     alias_prefix = convert_to_id(alias_prefix)
@@ -229,7 +229,7 @@ def new_custom_alias_v3():
     if not data:
     if not data:
         return jsonify(error="request body cannot be empty"), 400
         return jsonify(error="request body cannot be empty"), 400
 
 
-    alias_prefix = data.get("alias_prefix", "").strip().lower()
+    alias_prefix = data.get("alias_prefix", "").strip().lower().replace(" ", "")
     signed_suffix = data.get("signed_suffix", "").strip()
     signed_suffix = data.get("signed_suffix", "").strip()
     mailbox_ids = data.get("mailbox_ids")
     mailbox_ids = data.get("mailbox_ids")
     note = data.get("note")
     note = data.get("note")

+ 1 - 1
app/dashboard/views/custom_alias.py

@@ -64,7 +64,7 @@ def custom_alias():
     mailboxes = current_user.mailboxes()
     mailboxes = current_user.mailboxes()
 
 
     if request.method == "POST":
     if request.method == "POST":
-        alias_prefix = request.form.get("prefix").strip().lower()
+        alias_prefix = request.form.get("prefix").strip().lower().replace(" ", "")
         signed_suffix = request.form.get("suffix")
         signed_suffix = request.form.get("suffix")
         mailbox_ids = request.form.getlist("mailboxes")
         mailbox_ids = request.form.getlist("mailboxes")
         alias_note = request.form.get("note")
         alias_note = request.form.get("note")

+ 6 - 1
app/models.py

@@ -847,8 +847,11 @@ class Alias(db.Model, ModelMixin):
     def create(cls, **kw):
     def create(cls, **kw):
         r = cls(**kw)
         r = cls(**kw)
 
 
-        # make sure alias is not in global trash, i.e. DeletedAlias table
         email = kw["email"]
         email = kw["email"]
+        # make sure email is lowercase and doesn't have any whitespace
+        email = email.lower().strip().replace(" ", "")
+
+        # make sure alias is not in global trash, i.e. DeletedAlias table
         if DeletedAlias.get_by(email=email):
         if DeletedAlias.get_by(email=email):
             raise AliasInTrashError
             raise AliasInTrashError
 
 
@@ -860,6 +863,8 @@ class Alias(db.Model, ModelMixin):
 
 
     @classmethod
     @classmethod
     def create_new(cls, user, prefix, note=None, mailbox_id=None):
     def create_new(cls, user, prefix, note=None, mailbox_id=None):
+        prefix = prefix.lower().strip().replace(" ", "")
+
         if not prefix:
         if not prefix:
             raise Exception("alias prefix cannot be empty")
             raise Exception("alias prefix cannot be empty")
 
 

+ 2 - 0
app/oauth/views/authorize.py

@@ -152,6 +152,8 @@ def authorize():
                 if not current_user.can_create_new_alias():
                 if not current_user.can_create_new_alias():
                     raise Exception(f"User {current_user} cannot create custom email")
                     raise Exception(f"User {current_user} cannot create custom email")
 
 
+                alias_prefix = alias_prefix.strip().lower().replace(" ", "")
+
                 # hypothesis: user will click on the button in the 600 secs
                 # hypothesis: user will click on the button in the 600 secs
                 try:
                 try:
                     alias_suffix = signer.unsign(signed_suffix, max_age=600).decode()
                     alias_suffix = signer.unsign(signed_suffix, max_age=600).decode()