User can enable/disable catch-all on custom domain

This commit is contained in:
Son NK 2019-12-30 18:20:49 +01:00
parent b9908a16b2
commit 96bb37f0f6
3 changed files with 56 additions and 1 deletions

View file

@ -19,5 +19,40 @@
{{ nb_alias }} aliases
<hr>
<div>Catch All</div>
<div class="small-text">
This feature allows you to create aliases <b>on the fly</b>.
Simply use <em>anything@{{ custom_domain.domain }}</em>
next time you need an email address. <br>
The alias will be created the first time it receives an email.
</div>
<div>
<form method="post">
<input type="hidden" name="form-name" value="switch-catch-all">
<label class="custom-switch cursor mt-2 pl-0"
data-toggle="tooltip"
{% if custom_domain.catch_all %}
title="Disable catch-all"
{% else %}
title="Enable catch-all"
{% endif %}
>
<input type="checkbox" class="custom-switch-input"
{{ "checked" if custom_domain.catch_all else "" }}>
<span class="custom-switch-indicator"></span>
</label>
</form>
</div>
{% endblock %}
{% block script %}
<script>
$(".custom-switch-input").change(function (e) {
$(this).closest("form").submit();
})
</script>
{% endblock %}

View file

@ -40,7 +40,8 @@ def custom_domain():
return redirect(
url_for(
"dashboard.domain_detail_dns", custom_domain_id=new_custom_domain.id
"dashboard.domain_detail_dns",
custom_domain_id=new_custom_domain.id,
)
)

View file

@ -119,6 +119,25 @@ def domain_detail(custom_domain_id):
flash("You cannot see this page", "warning")
return redirect(url_for("dashboard.index"))
if request.method == "POST":
if request.form.get("form-name") == "switch-catch-all":
custom_domain.catch_all = not custom_domain.catch_all
db.session.commit()
if custom_domain.catch_all:
flash(
f"The catch-all has been enabled for {custom_domain.domain}",
"success",
)
else:
flash(
f"The catch-all has been disabled for {custom_domain.domain}",
"warning",
)
return redirect(
url_for("dashboard.domain_detail", custom_domain_id=custom_domain.id)
)
nb_alias = GenEmail.filter_by(custom_domain_id=custom_domain.id).count()
return render_template("dashboard/domain_detail/info.html", **locals())