Added ability for users to leave anonymous comments

This commit is contained in:
Sn0wCrack 2017-05-15 17:38:03 +10:00 committed by nyaadev
parent 1a9ebc19ed
commit fe6abf33c1
3 changed files with 8 additions and 1 deletions

View File

@ -132,6 +132,8 @@ class CommentForm(FlaskForm):
Required()
])
is_anonymous = BooleanField('Anonymous')
class EditForm(FlaskForm):
display_name = StringField('Torrent display name', [

View File

@ -611,7 +611,11 @@ def submit_comment(torrent_id):
comment_text = (form.comment.data or '').strip()
# Null entry for User just means Anonymous
current_user_id = flask.g.user.id if flask.g.user else None
if flask.g.user is None or form.is_anonymous.data:
current_user_id = None
else:
current_user_id = flask.g.user.id
comment = models.Comment(
torrent=torrent_id,
user_id=current_user_id,

View File

@ -173,6 +173,7 @@
<form method="POST" action="{{ request.url }}/submit_comment">
{{ form.csrf_token }}
{{ render_field(form.comment, class_='form-control') }}
{{ render_field(form.is_anonymous) }}
<input type="submit" value="Submit" class="btn btn-primary">
</form>