hanze/programmeerles-ouderen

added delete-/reset user to admin-page (80690d5b7a336dd6f73d561fc142a0ac3f385b3f)
Repositories

commit 80690d5b7a336dd6f73d561fc142a0ac3f385b3f
parent 700980dda1558520adb8b647ec377148d59e504d
Author: Friedel Schön <[email protected]>
Date:   Sat, 16 Apr 2022 14:58:00 +0200

added delete-/reset user to admin-page

Diffstat:
Mpgmles/routes.py22++++++++++++++++++++++
Mpgmles/site.db0
Mpgmles/templates/admin_user.html22++++++++++++++++++++++
3 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/pgmles/routes.py b/pgmles/routes.py @@ -231,3 +231,25 @@ def admin_user(user_id): elif request.method == 'GET': form.type.data = user.type return render_template('admin_user.html', calendar=make_calendar(), form=form, user=user, image_file=image_file) + [email protected]("/delete_user/<int:user_id>", methods=['GET','POST']) +@login_required +def delete_user(user_id): + if current_user.type != "admin": + abort(403) + user = User.query.get_or_404(user_id) + db.session.delete(user) + db.session.commit() + flash(f'De gebruiker {user.username} werd verwijdert', 'success') + return redirect(url_for('admin')) + [email protected]("/reset_user/<int:user_id>", methods=['GET','POST']) +@login_required +def reset_user(user_id): + if current_user.type != "admin": + abort(403) + user = User.query.get_or_404(user_id) + user.password = bcrypt.generate_password_hash(user.email).decode('utf-8') + db.session.commit() + flash(f'{user.username}\'s is nu zijn/haar e-mail', 'success') + return redirect(url_for('admin')) diff --git a/pgmles/site.db b/pgmles/site.db Binary files differ. diff --git a/pgmles/templates/admin_user.html b/pgmles/templates/admin_user.html @@ -26,7 +26,29 @@ </div> </fieldset> <div class="form-group"> + <button type="button" class="btn btn-danger btn-sm m-1" data-toggle="modal" data-target="#deleteModal">Verwijderen</button> + <a class="btn btn-danger btn-sm m-1" href="{{ url_for('reset_user', user_id=user.id) }}">Wachtwoord terugzetten</a> + <br><br> {{ form.submit(class="btn btn-outline-info") }} </div> </form> + <!-- Modal --> + <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true"> + <div class="modal-dialog" role="document"> + <div class="modal-content"> + <div class="modal-header"> + <h5 class="modal-title" id="deleteModalLabel">Profiel verwijderen?</h5> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"> + <span aria-hidden="true">&times;</span> + </button> + </div> + <div class="modal-footer"> + <button type="button" class="btn btn-secondary" data-dismiss="modal">Sluiten</button> + <form action="{{ url_for('delete_user', user_id=user.id) }}" method="POST"> + <input class="btn btn-danger" type="submit" value="Delete"> + </form> + </div> + </div> + </div> + </div> {% endblock content %} \ No newline at end of file