|
@@ -3,7 +3,8 @@ from flask import jsonify, request
|
|
|
from flask_cors import cross_origin
|
|
|
|
|
|
from app.api.base import api_bp, verify_api_key
|
|
|
-from app.config import EMAIL_DOMAIN, MAX_NB_EMAIL_FREE_PLAN
|
|
|
+from app.config import MAX_NB_EMAIL_FREE_PLAN
|
|
|
+from app.dashboard.views.custom_alias import verify_prefix_suffix
|
|
|
from app.extensions import db
|
|
|
from app.log import LOG
|
|
|
from app.models import GenEmail, AliasUsedOn
|
|
@@ -43,35 +44,12 @@ def new_custom_alias():
|
|
|
if not data:
|
|
|
return jsonify(error="request body cannot be empty"), 400
|
|
|
|
|
|
- alias_prefix = data.get("alias_prefix", "")
|
|
|
- alias_suffix = data.get("alias_suffix", "")
|
|
|
-
|
|
|
- # make sure alias_prefix is not empty
|
|
|
- alias_prefix = alias_prefix.strip()
|
|
|
+ alias_prefix = data.get("alias_prefix", "").strip()
|
|
|
+ alias_suffix = data.get("alias_suffix", "").strip()
|
|
|
alias_prefix = convert_to_id(alias_prefix)
|
|
|
- if not alias_prefix: # should be checked on frontend
|
|
|
- LOG.d("user %s submits an empty alias with the prefix %s", user, alias_prefix)
|
|
|
- return jsonify(error="alias prefix cannot be empty"), 400
|
|
|
-
|
|
|
- # make sure alias_suffix is either .random_letters@simplelogin.co or @my-domain.com
|
|
|
- alias_suffix = alias_suffix.strip()
|
|
|
- if alias_suffix.startswith("@"):
|
|
|
- custom_domain = alias_suffix[1:]
|
|
|
- if custom_domain not in user_custom_domains:
|
|
|
- LOG.d("user %s submits a wrong custom domain %s ", user, custom_domain)
|
|
|
- return jsonify(error="error"), 400
|
|
|
- else:
|
|
|
- if not alias_suffix.startswith("."):
|
|
|
- LOG.d("user %s submits a wrong alias suffix %s", user, alias_suffix)
|
|
|
- return jsonify(error="error"), 400
|
|
|
- if not alias_suffix.endswith(EMAIL_DOMAIN):
|
|
|
- LOG.d("user %s submits a wrong alias suffix %s", user, alias_suffix)
|
|
|
- return jsonify(error="error"), 400
|
|
|
|
|
|
- random_letters = alias_suffix[1 : alias_suffix.find("@")]
|
|
|
- if len(random_letters) < 5:
|
|
|
- LOG.d("user %s submits a wrong alias suffix %s", user, alias_suffix)
|
|
|
- return jsonify(error="error"), 400
|
|
|
+ if not verify_prefix_suffix(user, alias_prefix, alias_suffix, user_custom_domains):
|
|
|
+ return jsonify(error="wrong alias prefix or suffix"), 400
|
|
|
|
|
|
full_alias = alias_prefix + alias_suffix
|
|
|
if GenEmail.get_by(email=full_alias):
|