소스 검색

make sure to remove whitespace in alias

Son NK 4 년 전
부모
커밋
2d395f99bb
4개의 변경된 파일13개의 추가작업 그리고 6개의 파일을 삭제
  1. 4 4
      app/api/views/new_custom_alias.py
  2. 1 1
      app/dashboard/views/custom_alias.py
  3. 6 1
      app/models.py
  4. 2 0
      app/oauth/views/authorize.py

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

@@ -60,8 +60,8 @@ def new_custom_alias():
     if not data:
         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")
     alias_prefix = convert_to_id(alias_prefix)
 
@@ -132,7 +132,7 @@ def new_custom_alias_v2():
     if not data:
         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()
     note = data.get("note")
     alias_prefix = convert_to_id(alias_prefix)
@@ -229,7 +229,7 @@ def new_custom_alias_v3():
     if not data:
         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()
     mailbox_ids = data.get("mailbox_ids")
     note = data.get("note")

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

@@ -64,7 +64,7 @@ def custom_alias():
     mailboxes = current_user.mailboxes()
 
     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")
         mailbox_ids = request.form.getlist("mailboxes")
         alias_note = request.form.get("note")

+ 6 - 1
app/models.py

@@ -847,8 +847,11 @@ class Alias(db.Model, ModelMixin):
     def create(cls, **kw):
         r = cls(**kw)
 
-        # make sure alias is not in global trash, i.e. DeletedAlias table
         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):
             raise AliasInTrashError
 
@@ -860,6 +863,8 @@ class Alias(db.Model, ModelMixin):
 
     @classmethod
     def create_new(cls, user, prefix, note=None, mailbox_id=None):
+        prefix = prefix.lower().strip().replace(" ", "")
+
         if not prefix:
             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():
                     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
                 try:
                     alias_suffix = signer.unsign(signed_suffix, max_age=600).decode()