Forráskód Böngészése

User can enable/disable catch-all on custom domain

Son NK 5 éve
szülő
commit
96bb37f0f6

+ 35 - 0
app/dashboard/templates/dashboard/domain_detail/info.html

@@ -19,5 +19,40 @@
 
 
   {{ nb_alias }} aliases
   {{ 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 %}
 {% endblock %}
 
 
+{% block script %}
+  <script>
+    $(".custom-switch-input").change(function (e) {
+      $(this).closest("form").submit();
+    })
+  </script>
+{% endblock %}

+ 2 - 1
app/dashboard/views/custom_domain.py

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

+ 19 - 0
app/dashboard/views/domain_detail.py

@@ -119,6 +119,25 @@ def domain_detail(custom_domain_id):
         flash("You cannot see this page", "warning")
         flash("You cannot see this page", "warning")
         return redirect(url_for("dashboard.index"))
         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()
     nb_alias = GenEmail.filter_by(custom_domain_id=custom_domain.id).count()
 
 
     return render_template("dashboard/domain_detail/info.html", **locals())
     return render_template("dashboard/domain_detail/info.html", **locals())