From 37bff46f33d5f64fb60177279f7c4a14a15bb89e Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 26 May 2024 15:21:57 +0100 Subject: [PATCH] Add remove profile picture button --- app/blueprints/users/profile.py | 12 ++++++++++++ app/templates/users/profile_edit.html | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/blueprints/users/profile.py b/app/blueprints/users/profile.py index cb18fae8..1a327ead 100644 --- a/app/blueprints/users/profile.py +++ b/app/blueprints/users/profile.py @@ -259,6 +259,18 @@ def user_check_forums(username): return redirect(url_for("tasks.check", id=task.id, r=next_url)) +@bp.route("/users//remove-profile-pic/", methods=["POST"]) +@login_required +def user_remove_profile_pic(username): + user = User.query.filter_by(username=username).one_or_404() + if current_user != user and not current_user.rank.at_least(UserRank.MODERATOR): + abort(403) + + user.profile_pic = None + db.session.commit() + return redirect(url_for("users.profile_edit", username=username)) + + @bp.route("/user/stats/") @login_required def statistics_redirect(): diff --git a/app/templates/users/profile_edit.html b/app/templates/users/profile_edit.html index 51ce27f5..953923c3 100644 --- a/app/templates/users/profile_edit.html +++ b/app/templates/users/profile_edit.html @@ -22,18 +22,22 @@
{% if user.forums_username %} -
+
{% endif %} {% if user.profile_pic %} +
+ + +
{% elif user.email %} Gravatar {% else %} -