From b7cbaa6e849f39fc0e0dd55c5d41917061de896d Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Thu, 13 Aug 2020 10:59:39 +0200 Subject: [PATCH] delete the expired ChangeEmail object --- app/auth/templates/auth/change_email.html | 28 +++++++---------------- app/auth/views/change_email.py | 7 ++++-- app/models.py | 3 +++ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/app/auth/templates/auth/change_email.html b/app/auth/templates/auth/change_email.html index 681b6b13..f89c7f40 100644 --- a/app/auth/templates/auth/change_email.html +++ b/app/auth/templates/auth/change_email.html @@ -7,26 +7,14 @@ {% block single_content %}
- - {% if incorrect_code %} -
- The link is incorrect.

-
-
- Please go to settings - page to re-send confirmation email. -
- {% endif %} - - {% if expired_code %} -
- The link is already expired.

-
-
- Please go to settings - page to re-send confirmation email. -
- {% endif %} +
Email Update
+
+ Incorrect or expired link.

+
+
+ Please go to settings + page to re-send the confirmation email. +
diff --git a/app/auth/views/change_email.py b/app/auth/views/change_email.py index 8a7a53ba..803c26f9 100644 --- a/app/auth/views/change_email.py +++ b/app/auth/views/change_email.py @@ -13,10 +13,13 @@ def change_email(): email_change: EmailChange = EmailChange.get_by(code=code) if not email_change: - return render_template("auth/change_email.html", incorrect_code=True) + return render_template("auth/change_email.html") if email_change.is_expired(): - return render_template("auth/change_email.html", expired_code=True) + # delete the expired email + EmailChange.delete(email_change.id) + db.session.commit() + return render_template("auth/change_email.html") user = email_change.user user.email = email_change.new_email diff --git a/app/models.py b/app/models.py index 5894cb33..ecd9c584 100644 --- a/app/models.py +++ b/app/models.py @@ -1314,6 +1314,9 @@ class EmailChange(db.Model, ModelMixin): def is_expired(self): return self.expired < arrow.now() + def __repr__(self): + return f"" + class AliasUsedOn(db.Model, ModelMixin): """Used to know where an alias is created"""