def delete_domain(custom_domain_id: CustomDomain): from server import create_light_app with create_light_app().app_context(): custom_domain = CustomDomain.get(custom_domain_id) if not custom_domain: return domain_name = custom_domain.domain user = custom_domain.user CustomDomain.delete(custom_domain.id) db.session.commit() LOG.d("Domain %s deleted", domain_name) send_email( user.email, f"Your domain {domain_name} has been deleted", f"""Domain {domain_name} along with its aliases are deleted successfully. Regards, SimpleLogin team. """, )
def test_create_subdomain_in_trash(flask_client): user = login(flask_client) sl_domain = setup_sl_domain() subdomain = CustomDomain.create( domain=f"test.{sl_domain.domain}", user_id=user.id, is_sl_subdomain=True, commit=True, ) # delete the subdomain CustomDomain.delete(subdomain.id) assert CustomDomain.get_by(domain=f"test.{sl_domain.domain}") is None r = flask_client.post( url_for("dashboard.subdomain_route"), data={ "form-name": "create", "subdomain": "test", "domain": sl_domain.domain }, follow_redirects=True, ) assert r.status_code == 200 assert ( f"test.{sl_domain.domain} has been used before and cannot be reused" in r.data.decode())
def domain_detail(custom_domain_id): custom_domain = CustomDomain.get(custom_domain_id) if not custom_domain or custom_domain.user_id != current_user.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)) elif request.form.get("form-name") == "delete": name = custom_domain.domain CustomDomain.delete(custom_domain_id) db.session.commit() flash(f"Domain {name} has been deleted", "success") return redirect(url_for("dashboard.custom_domain")) nb_alias = GenEmail.filter_by(custom_domain_id=custom_domain.id).count() return render_template("dashboard/domain_detail/info.html", **locals())
def custom_domain(): # only premium user can add custom domain if not current_user.is_premium(): flash("Only premium user can add custom domains", "warning") return redirect(url_for("dashboard.index")) custom_domains = CustomDomain.query.filter_by(user_id=current_user.id).all() new_custom_domain_form = NewCustomDomainForm() errors = {} if request.method == "POST": if request.form.get("form-name") == "delete": custom_domain_id = request.form.get("custom-domain-id") custom_domain = CustomDomain.get(custom_domain_id) if not custom_domain: flash("Unknown error. Refresh the page", "warning") return redirect(url_for("dashboard.custom_domain")) elif custom_domain.user_id != current_user.id: flash("You cannot delete this domain", "warning") return redirect(url_for("dashboard.custom_domain")) name = custom_domain.domain CustomDomain.delete(custom_domain_id) db.session.commit() flash(f"Domain {name} has been deleted successfully", "success") return redirect(url_for("dashboard.custom_domain")) elif request.form.get("form-name") == "create": if new_custom_domain_form.validate(): new_custom_domain = CustomDomain.create( domain=new_custom_domain_form.domain.data, user_id=current_user.id ) db.session.commit() flash( f"New domain {new_custom_domain.domain} has been created successfully", "success", ) return redirect(url_for("dashboard.custom_domain")) elif request.form.get("form-name") == "check-domain": custom_domain_id = request.form.get("custom-domain-id") custom_domain = CustomDomain.get(custom_domain_id) if not custom_domain: flash("Unknown error. Refresh the page", "warning") return redirect(url_for("dashboard.custom_domain")) elif custom_domain.user_id != current_user.id: flash("You cannot delete this domain", "warning") return redirect(url_for("dashboard.custom_domain")) else: spf_domains = get_spf_domain(custom_domain.domain) for email_server in EMAIL_SERVERS: email_server = email_server[:-1] # remove the trailing . if email_server not in spf_domains: flash( f"{email_server} is not included in your SPF record.", "warning", ) mx_domains = get_mx_domains(custom_domain.domain) if mx_domains != EMAIL_SERVERS: errors[ custom_domain.id ] = f"""Your DNS is not correctly set. The MX record we obtain is: {",".join(mx_domains)}""" else: flash( "Your domain is verified. Now it can be used to create custom alias", "success", ) custom_domain.verified = True db.session.commit() return render_template( "dashboard/custom_domain.html", custom_domains=custom_domains, new_custom_domain_form=new_custom_domain_form, EMAIL_SERVERS_WITH_PRIORITY=EMAIL_SERVERS_WITH_PRIORITY, errors=errors, )
Regards, SimpleLogin team. """, retries=3, ) elif job.name == JOB_DELETE_DOMAIN: custom_domain_id = job.payload.get("custom_domain_id") custom_domain = CustomDomain.get(custom_domain_id) if not custom_domain: continue domain_name = custom_domain.domain user = custom_domain.user CustomDomain.delete(custom_domain.id) Session.commit() LOG.d("Domain %s deleted", domain_name) send_email( user.email, f"Your domain {domain_name} has been deleted", f"""Domain {domain_name} along with its aliases are deleted successfully. Regards, SimpleLogin team. """, retries=3, )