Implement banning

This commit is contained in:
David Hoppenbrouwers
2022-10-09 13:48:44 +02:00
parent f73f2b405c
commit eaa77d363b
5 changed files with 139 additions and 55 deletions

View File

@@ -76,30 +76,35 @@
<th>Name</th>
<th>Join date</th>
<th>Role</th>
<th>Banned until</th>
<th>Actions</th>
<th>Banned</th>
</tr>
{%- for id, name, join_date, role, banned_until in users -%}
<tr>
<td>{{ id }}</td>
<td>{{ name }}</td>
<td>{{ format_time(join_date) }}</td>
<td>{{ ['user', 'moderator', 'admin'][role] if role >= 0 and role <= 2 else role }}</td>
<td>{{ '' if banned_until is none else format_time(banned_until) }}</td>
<td>
<form method=post action="user/{{ id }}/edit/ban/">
<form method=post action="user/{{ id }}/edit/role/">
<select name=role>
<option value=0 {{ 'selected' if role == 0 else '' }}>user</option>
<option value=1 {{ 'selected' if role == 1 else '' }}>moderator</option>
<option value=2 {{ 'selected' if role == 2 else '' }}>admin</option>
</select>
<input type=submit value="Set role">
</form>
</td>
<td>
{% if banned_until is not none %}
<form method=post action="user/{{ id }}/unban/">
{{- format_time(banned_until) }}
<input type=submit value=Unban>
</form>
{% endif %}
<form method=post action="user/{{ id }}/ban/">
<input type=number name=days placeholder=days>
<input type=time name=time>
<input type=submit value=Ban>
</form>
<form method=post action="user/{{ id }}/edit/role/">
<select name=role>
<option value=0>user</option>
<option value=1>moderator</option>
<option value=2>admin</option>
</select>
<input type=submit value="Set role">
</form>
</td>
</tr>
{%- endfor -%}

View File

@@ -10,7 +10,10 @@
<a class=logo href="{{ url_for('index') }}">A</a>
<div style="margin:auto"></div>
{%- if user is not none -%}
<a href="{{ url_for('user_edit') }}">{{ user.name }}</a>
<a href="{{ url_for('user_edit') }}">
{{- user.name }}
{%- if user.is_banned() %} (banned for {{ format_until(user.banned_until) }}){% endif -%}
</a>
<span> | </span>
{%- if user.is_admin() -%}
<a href="{{ url_for('admin') }}">Admin panel</a>

View File

@@ -10,7 +10,7 @@
{%- if comment.parent_id is not none -%}
<a href="{{ url_for('comment', comment_id = comment.parent_id) }}#"> parent</a>
{%- endif -%}
{%- if user is not none and (comment.author_id == user.id or user.is_moderator()) -%}
{%- if user is not none and (comment.author_id == user.id or user.is_moderator()) and not user.is_banned() -%}
<a href="{{ url_for('edit_comment', comment_id = comment.id) }}"> edit</a>
{%- if can_delete -%}
<a href="{{ url_for('confirm_delete_comment', comment_id = comment.id) }}"> delete</a>
@@ -22,7 +22,7 @@
{%- macro thread_author(author_id, name, ctime, mtime) -%}
<p><sub>
{{- author(author_id, name, ctime, mtime) -}}
{%- if user is not none and (author_id == user.id or user.is_moderator()) -%}
{%- if user is not none and (author_id == user.id or user.is_moderator()) and not user.is_banned() -%}
<a href="{{ url_for('edit_thread', thread_id = thread_id) }}"> edit</a>
<a href="{{ url_for('confirm_delete_thread', thread_id = thread_id) }}"> delete</a>
{%- endif -%}
@@ -49,7 +49,7 @@
{%- endmacro -%}
{%- macro reply() -%}
{%- if user is not none -%}
{%- if user is not none and not user.is_banned() -%}
<form method="post" action="comment/">
<p><textarea name="text"></textarea></p>
<p><input type="submit" value="Post comment"></p>