delete the expired ChangeEmail object

This commit is contained in:
Son NK 2020-08-13 10:59:39 +02:00
parent cb687c4248
commit b7cbaa6e84
3 changed files with 16 additions and 22 deletions

View file

@ -7,26 +7,14 @@
{% block single_content %} {% block single_content %}
<div class="card"> <div class="card">
<div class="card-body p-6"> <div class="card-body p-6">
<div class="h3 text-center">Email Update</div>
{% if incorrect_code %} <div class="text-danger text-center h4">
<div class="text-danger text-center h4"> Incorrect or expired link. <br><br>
The link is incorrect. <br><br> </div>
</div> <div class="text-center">
<div class="text-center"> Please go to <a href="{{ url_for('dashboard.setting') }}">settings</a>
Please go to <a href="{{ url_for('dashboard.setting') }}">settings</a> page to re-send the confirmation email.
page to re-send confirmation email. </div>
</div>
{% endif %}
{% if expired_code %}
<div class="text-danger text-center h4">
The link is already expired. <br><br>
</div>
<div class="text-center">
Please go to <a href="{{ url_for('dashboard.setting') }}">settings</a>
page to re-send confirmation email.
</div>
{% endif %}
</div> </div>
</div> </div>

View file

@ -13,10 +13,13 @@ def change_email():
email_change: EmailChange = EmailChange.get_by(code=code) email_change: EmailChange = EmailChange.get_by(code=code)
if not email_change: 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(): 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_change.user
user.email = email_change.new_email user.email = email_change.new_email

View file

@ -1314,6 +1314,9 @@ class EmailChange(db.Model, ModelMixin):
def is_expired(self): def is_expired(self):
return self.expired < arrow.now() return self.expired < arrow.now()
def __repr__(self):
return f"<EmailChange {self.id} {self.new_email} {self.user_id}>"
class AliasUsedOn(db.Model, ModelMixin): class AliasUsedOn(db.Model, ModelMixin):
"""Used to know where an alias is created""" """Used to know where an alias is created"""