From 34509cbbb3a5d494b9806d604b301d44b9963830 Mon Sep 17 00:00:00 2001 From: Son Date: Wed, 1 Dec 2021 10:11:18 +0100 Subject: [PATCH] delete account is protected by password --- app/dashboard/__init__.py | 1 + app/dashboard/views/delete_account.py | 41 +++++++++++++++++++ app/dashboard/views/setting.py | 23 ----------- templates/dashboard/delete_account.html | 53 +++++++++++++++++++++++++ templates/dashboard/setting.html | 36 ++--------------- 5 files changed, 98 insertions(+), 56 deletions(-) create mode 100644 app/dashboard/views/delete_account.py create mode 100644 templates/dashboard/delete_account.html diff --git a/app/dashboard/__init__.py b/app/dashboard/__init__.py index da5703a3..46908096 100644 --- a/app/dashboard/__init__.py +++ b/app/dashboard/__init__.py @@ -29,4 +29,5 @@ from .views import ( batch_import, alias_transfer, app, + delete_account, ) diff --git a/app/dashboard/views/delete_account.py b/app/dashboard/views/delete_account.py new file mode 100644 index 00000000..560bbaa7 --- /dev/null +++ b/app/dashboard/views/delete_account.py @@ -0,0 +1,41 @@ +import arrow +from flask import flash, redirect, url_for, request, render_template +from flask_login import login_required, current_user + +from app.config import JOB_DELETE_ACCOUNT +from app.dashboard.base import dashboard_bp +from app.dashboard.views.enter_sudo import sudo_required +from app.log import LOG +from app.models import Subscription, Job + + +@dashboard_bp.route("/delete_account", methods=["GET", "POST"]) +@login_required +@sudo_required +def delete_account(): + if request.method == "POST" and request.form.get("form-name") == "delete-account": + sub: Subscription = current_user.get_subscription() + # user who has canceled can also re-subscribe + if sub and not sub.cancelled: + flash("Please cancel your current subscription first", "warning") + return redirect(url_for("dashboard.setting")) + + # Schedule delete account job + LOG.w("schedule delete account job for %s", current_user) + Job.create( + name=JOB_DELETE_ACCOUNT, + payload={"user_id": current_user.id}, + run_at=arrow.now(), + commit=True, + ) + + flash( + "Your account deletion has been scheduled. " + "You'll receive an email when the deletion is finished", + "info", + ) + return redirect(url_for("dashboard.setting")) + + return render_template( + "dashboard/delete_account.html", + ) diff --git a/app/dashboard/views/setting.py b/app/dashboard/views/setting.py index 993698b4..c51d4a4d 100644 --- a/app/dashboard/views/setting.py +++ b/app/dashboard/views/setting.py @@ -185,29 +185,6 @@ def setting(): flash("Your notification preference has been updated", "success") return redirect(url_for("dashboard.setting")) - elif request.form.get("form-name") == "delete-account": - sub: Subscription = current_user.get_subscription() - # user who has canceled can also re-subscribe - if sub and not sub.cancelled: - flash("Please cancel your current subscription first", "warning") - return redirect(url_for("dashboard.setting")) - - # Schedule delete account job - LOG.w("schedule delete account job for %s", current_user) - Job.create( - name=JOB_DELETE_ACCOUNT, - payload={"user_id": current_user.id}, - run_at=arrow.now(), - commit=True, - ) - - flash( - "Your account deletion has been scheduled. " - "You'll receive an email when the deletion is finished", - "success", - ) - return redirect(url_for("dashboard.setting")) - elif request.form.get("form-name") == "change-alias-generator": scheme = int(request.form.get("alias-generator-scheme")) if AliasGeneratorEnum.has_value(scheme): diff --git a/templates/dashboard/delete_account.html b/templates/dashboard/delete_account.html new file mode 100644 index 00000000..23777520 --- /dev/null +++ b/templates/dashboard/delete_account.html @@ -0,0 +1,53 @@ +{% extends 'default.html' %} +{% set active_page = "setting" %} +{% block title %} + Delete account +{% endblock %} + + +{% block default_content %} +
+
+
Account Deletion
+
+ Once an account is deleted, it can't be restored. + All its records (aliases, domains, settings, etc.) are immediately deleted. +
+ +
+ + +
+
+
+{% endblock %} + +{% block script %} + +{% endblock %} \ No newline at end of file diff --git a/templates/dashboard/setting.html b/templates/dashboard/setting.html index c63d0907..5d6fd7ce 100644 --- a/templates/dashboard/setting.html +++ b/templates/dashboard/setting.html @@ -492,13 +492,11 @@
Account Deletion
-
Please note that this operation is irreversible. +
+ If SimpleLogin isn't the right fit for you, you can simply delete your account.
-
- - -
+ Delete account
@@ -506,33 +504,5 @@ {% endblock %} -{% block script %} - -{% endblock %}