mirror of
https://github.com/simple-login/app.git
synced 2024-09-21 07:25:59 +08:00
create unsubscribe view to block quickly an alias
This commit is contained in:
parent
75e07fff04
commit
45cef7a4ef
|
@ -1 +1 @@
|
|||
from .views import index, pricing, setting, custom_alias, billing, alias_log
|
||||
from .views import index, pricing, setting, custom_alias, billing, alias_log, unsubscribe
|
||||
|
|
|
@ -68,15 +68,9 @@ def index():
|
|||
|
||||
gen_email.enabled = not gen_email.enabled
|
||||
if gen_email.enabled:
|
||||
flash(
|
||||
f"The email forwarding for {gen_email.email} has been enabled",
|
||||
"success",
|
||||
)
|
||||
flash(f"Alias {gen_email.email} is enabled", "success")
|
||||
else:
|
||||
flash(
|
||||
f"The email forwarding for {gen_email.email} has been disabled",
|
||||
"warning",
|
||||
)
|
||||
flash(f"Alias {gen_email.email} is disabled", "warning")
|
||||
db.session.commit()
|
||||
|
||||
elif request.form.get("form-name") == "delete-email":
|
||||
|
|
34
app/dashboard/views/unsubscribe.py
Normal file
34
app/dashboard/views/unsubscribe.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
"""
|
||||
Allow user to "unsubscribe", aka block an email alias
|
||||
"""
|
||||
|
||||
from flask import redirect, url_for, flash
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
from app.dashboard.base import dashboard_bp
|
||||
from app.email_utils import notify_admin
|
||||
from app.extensions import db
|
||||
from app.models import GenEmail
|
||||
|
||||
|
||||
@dashboard_bp.route("/unsubscribe/<gen_email_id>", methods=["GET"])
|
||||
@login_required
|
||||
def unsubscribe(gen_email_id):
|
||||
gen_email = GenEmail.get(gen_email_id)
|
||||
if not gen_email:
|
||||
flash("Incorrect link. Redirect you to the home page", "warning")
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
if gen_email.user_id != current_user.id:
|
||||
flash(
|
||||
"You don't have access to this page. Redirect you to the home page",
|
||||
"warning",
|
||||
)
|
||||
return redirect(url_for("dashboard.index"))
|
||||
|
||||
gen_email.enabled = False
|
||||
flash(f"Alias {gen_email.email} has been blocked", "success")
|
||||
db.session.commit()
|
||||
|
||||
notify_admin(f"User {current_user.email} has unsubscribed an alias")
|
||||
return redirect(url_for("dashboard.index"))
|
Loading…
Reference in a new issue