From d537096f741ca43e65e6fe97da5d190f4ffe2ce7 Mon Sep 17 00:00:00 2001 From: Stephan Porada <sporada@uni-bielefeld.de> Date: Tue, 10 Sep 2019 14:18:20 +0200 Subject: [PATCH] Add user self delete function --- app/auth/views.py | 10 ++++++++ app/templates/admin/admin_user_page.html.j2 | 2 +- app/templates/auth/edit_profile.html.j2 | 27 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/auth/views.py b/app/auth/views.py index d3535ac2..69d3570f 100644 --- a/app/auth/views.py +++ b/app/auth/views.py @@ -160,3 +160,13 @@ def edit_profile(): change_profile_form=change_profile_form, title='Edit Profile' ) + + +@auth.route('/edit_profile/delete_self/<int:user_id>', methods=['GET', 'POST']) +@login_required +def delete_self(user_id): + selected_user = User.query.filter_by(id=user_id).first() + db.session.delete(selected_user) + db.session.commit() + flash('Your account has been deleted!') + return redirect(url_for('main.index')) diff --git a/app/templates/admin/admin_user_page.html.j2 b/app/templates/admin/admin_user_page.html.j2 index 35246937..ab4772f1 100644 --- a/app/templates/admin/admin_user_page.html.j2 +++ b/app/templates/admin/admin_user_page.html.j2 @@ -70,7 +70,7 @@ <div class="card-content"> <span class="card-title">Administration actions</span> <!-- Confirm deletion of selected user with modal dialogue - Modal Trigger--> + Modal Trigger--> <a href="#modal-confirm-delete" class="waves-effect waves-light btn red modal-trigger"><i class="material-icons left">delete</i>Delete User</a> <!-- Modal Strucutre --> <div id="modal-confirm-delete" class="modal"> diff --git a/app/templates/auth/edit_profile.html.j2 b/app/templates/auth/edit_profile.html.j2 index ab992065..bb2b533d 100644 --- a/app/templates/auth/edit_profile.html.j2 +++ b/app/templates/auth/edit_profile.html.j2 @@ -66,4 +66,31 @@ </form> </div> </div> +<div class="col s12 m4"> + <h3>Delete Account</h3> + <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,</p> +</div> +<div class="col s12 m8"> + <div class="card"> + <div class="card-content"> + <!-- Confirm deletion of selected user with modal dialogue + Modal Trigger--> + </div> + <div class="card-action right-align"> + <a href="#modal-confirm-delete" class="waves-effect waves-light btn red modal-trigger"><i class="material-icons left">delete</i>Delete User</a> + </div> + <!-- Modal Strucutre --> + <div id="modal-confirm-delete" class="modal"> + <div class="modal-content"> + <h4>Confirm deletion</h4> + <p> + Do you really want to delete your account and all associated data? + </p> + </div> + <div class="modal-footer"> + <a href="{{url_for('auth.delete_self', user_id=current_user.id)}}" class="modal-close waves-effect waves-green btn red"><i class="material-icons left">delete</i>Delete User</a></a> + </div> + </div> + </div> +</div> {% endblock %} -- GitLab