mirror of
https://github.com/simple-login/app.git
synced 2025-02-24 07:43:54 +08:00
Add Delete Account in setting
This commit is contained in:
parent
a22a635508
commit
ec4d034593
2 changed files with 36 additions and 1 deletions
|
@ -57,7 +57,35 @@
|
|||
<button class="btn btn-outline-primary">Change password</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
<h3 class="mb-0">Delete Account</h3>
|
||||
<div class="small-text mb-3">Please note that this operation is irreversible.
|
||||
|
||||
</div>
|
||||
<form method="post">
|
||||
<input type="hidden" name="form-name" value="delete-account">
|
||||
<span class="delete-account btn btn-outline-danger">Delete account</span>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script>
|
||||
$(".delete-account").on("click", function (e) {
|
||||
notie.confirm({
|
||||
text: "All your data including your aliases will be deleted, " +
|
||||
"other people might not be able to reach you after, " +
|
||||
" please confirm.",
|
||||
cancelCallback: () => {
|
||||
// nothing to do
|
||||
},
|
||||
submitCallback: () => {
|
||||
$(this).closest("form").submit();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from io import BytesIO
|
|||
|
||||
import arrow
|
||||
from flask import render_template, request, redirect, url_for, flash
|
||||
from flask_login import login_required, current_user
|
||||
from flask_login import login_required, current_user, logout_user
|
||||
from flask_wtf import FlaskForm
|
||||
from flask_wtf.file import FileField
|
||||
from wtforms import StringField, validators
|
||||
|
@ -111,6 +111,13 @@ def setting():
|
|||
elif request.form.get("form-name") == "change-password":
|
||||
send_reset_password_email(current_user)
|
||||
|
||||
elif request.form.get("form-name") == "delete-account":
|
||||
User.delete(current_user.id)
|
||||
db.session.commit()
|
||||
flash("Your account has been deleted", "success")
|
||||
logout_user()
|
||||
return redirect(url_for("auth.register"))
|
||||
|
||||
return redirect(url_for("dashboard.setting"))
|
||||
|
||||
return render_template(
|
||||
|
|
Loading…
Reference in a new issue