Add remove profile picture button

This commit is contained in:
rubenwardy 2024-05-26 15:21:57 +01:00
parent 9cb4d13d71
commit 37bff46f33
2 changed files with 18 additions and 2 deletions

@ -259,6 +259,18 @@ def user_check_forums(username):
return redirect(url_for("tasks.check", id=task.id, r=next_url))
@bp.route("/users/<username>/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():

@ -22,18 +22,22 @@
</div>
<div class="col">
{% if user.forums_username %}
<form method="post" action="{{ url_for('users.user_check_forums', username=user.username) }}" class="" style="display:inline-block;">
<form method="post" action="{{ url_for('users.user_check_forums', username=user.username) }}" class="me-2" style="display:inline-block;">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="submit" class="btn btn-primary" value="{{ _('Import from forums') }}" />
</form>
{% endif %}
{% if user.profile_pic %}
<form method="post" action="{{ url_for('users.user_remove_profile_pic', username=user.username) }}" class="me-2" style="display:inline-block;">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="submit" class="btn btn-secondary" value="{{ _('Remove profile picture') }}" />
</form>
{% elif user.email %}
<a class="btn btn-primary" href="https://en.gravatar.com/">
Gravatar
</a>
{% else %}
<a class="btn btn-primary disabled"
<a class="btn btn-secondary disabled"
data-toggle="tooltip" data-placement="bottom"
title="Please add an email address to use Gravatar"
style="pointer-events: all;">