mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 00:48:32 +01:00
Remove /alias/custom/new
This commit is contained in:
parent
ef32998e99
commit
3308919906
1 changed files with 0 additions and 74 deletions
|
@ -7,8 +7,6 @@ from app.api.base import api_bp, require_api_auth
|
||||||
from app.api.serializer import (
|
from app.api.serializer import (
|
||||||
serialize_alias_info_v2,
|
serialize_alias_info_v2,
|
||||||
get_alias_info_v2,
|
get_alias_info_v2,
|
||||||
serialize_alias_info,
|
|
||||||
get_alias_info,
|
|
||||||
)
|
)
|
||||||
from app.config import MAX_NB_EMAIL_FREE_PLAN, ALIAS_LIMIT
|
from app.config import MAX_NB_EMAIL_FREE_PLAN, ALIAS_LIMIT
|
||||||
from app.dashboard.views.custom_alias import verify_prefix_suffix, signer
|
from app.dashboard.views.custom_alias import verify_prefix_suffix, signer
|
||||||
|
@ -27,78 +25,6 @@ from app.models import (
|
||||||
from app.utils import convert_to_id
|
from app.utils import convert_to_id
|
||||||
|
|
||||||
|
|
||||||
@api_bp.route("/alias/custom/new", methods=["POST"])
|
|
||||||
@limiter.limit(ALIAS_LIMIT)
|
|
||||||
@require_api_auth
|
|
||||||
def new_custom_alias():
|
|
||||||
"""
|
|
||||||
Currently used by Safari extension.
|
|
||||||
Create a new custom alias
|
|
||||||
Input:
|
|
||||||
alias_prefix, for ex "www_groupon_com"
|
|
||||||
alias_suffix, either .random_letters@simplelogin.co or @my-domain.com
|
|
||||||
optional "hostname" in args
|
|
||||||
optional "note"
|
|
||||||
Output:
|
|
||||||
201 if success
|
|
||||||
409 if the alias already exists
|
|
||||||
|
|
||||||
"""
|
|
||||||
LOG.w("/alias/custom/new is obsolete. User-Agent:%s", request.headers["User-Agent"])
|
|
||||||
user: User = g.user
|
|
||||||
if not user.can_create_new_alias():
|
|
||||||
LOG.d("user %s cannot create any custom alias", user)
|
|
||||||
return (
|
|
||||||
jsonify(
|
|
||||||
error="You have reached the limitation of a free account with the maximum of "
|
|
||||||
f"{MAX_NB_EMAIL_FREE_PLAN} aliases, please upgrade your plan to create more aliases"
|
|
||||||
),
|
|
||||||
400,
|
|
||||||
)
|
|
||||||
|
|
||||||
hostname = request.args.get("hostname")
|
|
||||||
|
|
||||||
data = request.get_json()
|
|
||||||
if not data:
|
|
||||||
return jsonify(error="request body cannot be empty"), 400
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
if not verify_prefix_suffix(user, alias_prefix, alias_suffix):
|
|
||||||
return jsonify(error="wrong alias prefix or suffix"), 400
|
|
||||||
|
|
||||||
full_alias = alias_prefix + alias_suffix
|
|
||||||
if (
|
|
||||||
Alias.get_by(email=full_alias)
|
|
||||||
or DeletedAlias.get_by(email=full_alias)
|
|
||||||
or DomainDeletedAlias.get_by(email=full_alias)
|
|
||||||
):
|
|
||||||
LOG.d("full alias already used %s", full_alias)
|
|
||||||
return jsonify(error=f"alias {full_alias} already exists"), 409
|
|
||||||
|
|
||||||
alias = Alias.create(
|
|
||||||
user_id=user.id, email=full_alias, mailbox_id=user.default_mailbox_id, note=note
|
|
||||||
)
|
|
||||||
|
|
||||||
if alias_suffix.startswith("@"):
|
|
||||||
alias_domain = alias_suffix[1:]
|
|
||||||
domain = CustomDomain.get_by(domain=alias_domain)
|
|
||||||
if domain:
|
|
||||||
LOG.d("set alias %s to domain %s", full_alias, domain)
|
|
||||||
alias.custom_domain_id = domain.id
|
|
||||||
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
if hostname:
|
|
||||||
AliasUsedOn.create(alias_id=alias.id, hostname=hostname, user_id=alias.user_id)
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
return jsonify(alias=full_alias, **serialize_alias_info(get_alias_info(alias))), 201
|
|
||||||
|
|
||||||
|
|
||||||
@api_bp.route("/v2/alias/custom/new", methods=["POST"])
|
@api_bp.route("/v2/alias/custom/new", methods=["POST"])
|
||||||
@limiter.limit(ALIAS_LIMIT)
|
@limiter.limit(ALIAS_LIMIT)
|
||||||
@require_api_auth
|
@require_api_auth
|
||||||
|
|
Loading…
Reference in a new issue