Disallow empty text, titles
This commit is contained in:
34
main.py
34
main.py
@@ -173,7 +173,11 @@ def new_thread(forum_id):
|
|||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
id = db.add_thread(user_id, forum_id, request.form['title'], trim_text(request.form['text']), time.time_ns())
|
title, text = request.form['title'], trim_text(request.form['text'])
|
||||||
|
if title == '' or text == '':
|
||||||
|
flash('Title and text may not be empty', 'error')
|
||||||
|
return redirect(url_for('forum', forum_id = forum_id))
|
||||||
|
id = db.add_thread(user_id, forum_id, title, text, time.time_ns())
|
||||||
if id is None:
|
if id is None:
|
||||||
flash('Failed to create thread', 'error')
|
flash('Failed to create thread', 'error')
|
||||||
return redirect(url_for('forum', forum_id = forum_id))
|
return redirect(url_for('forum', forum_id = forum_id))
|
||||||
@@ -219,7 +223,10 @@ def add_comment(thread_id):
|
|||||||
if user_id is None:
|
if user_id is None:
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
if db.add_comment_to_thread(thread_id, user_id, trim_text(request.form['text']), time.time_ns()):
|
text = trim_text(request.form['text'])
|
||||||
|
if text == '':
|
||||||
|
flash('Text may not be empty', 'error')
|
||||||
|
elif db.add_comment_to_thread(thread_id, user_id, text, time.time_ns()):
|
||||||
flash('Added comment', 'success')
|
flash('Added comment', 'success')
|
||||||
else:
|
else:
|
||||||
flash('Failed to add comment', 'error')
|
flash('Failed to add comment', 'error')
|
||||||
@@ -231,7 +238,10 @@ def add_comment_parent(comment_id):
|
|||||||
if user_id is None:
|
if user_id is None:
|
||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
if db.add_comment_to_comment(comment_id, user_id, trim_text(request.form['text']), time.time_ns()):
|
text = trim_text(request.form['text'])
|
||||||
|
if text == '':
|
||||||
|
flash('Text may not be empty', 'error')
|
||||||
|
elif db.add_comment_to_comment(comment_id, user_id, text, time.time_ns()):
|
||||||
flash('Added comment', 'success')
|
flash('Added comment', 'success')
|
||||||
else:
|
else:
|
||||||
flash('Failed to add comment', 'error')
|
flash('Failed to add comment', 'error')
|
||||||
@@ -269,11 +279,14 @@ def edit_thread(thread_id):
|
|||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if db.modify_thread(
|
title, text = request.form['title'], trim_text(request.form['text'])
|
||||||
|
if title == '' or text == '':
|
||||||
|
flash('Title and text may not be empty', 'error')
|
||||||
|
elif db.modify_thread(
|
||||||
thread_id,
|
thread_id,
|
||||||
user_id,
|
user_id,
|
||||||
request.form['title'],
|
title,
|
||||||
trim_text(request.form['text']),
|
text,
|
||||||
time.time_ns(),
|
time.time_ns(),
|
||||||
):
|
):
|
||||||
flash('Thread has been edited', 'success')
|
flash('Thread has been edited', 'success')
|
||||||
@@ -299,7 +312,10 @@ def edit_comment(comment_id):
|
|||||||
return redirect(url_for('login'))
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if db.modify_comment(
|
text = trim_text(request.form['text'])
|
||||||
|
if text == '':
|
||||||
|
flash('Text may not be empty', 'error')
|
||||||
|
elif db.modify_comment(
|
||||||
comment_id,
|
comment_id,
|
||||||
user_id,
|
user_id,
|
||||||
trim_text(request.form['text']),
|
trim_text(request.form['text']),
|
||||||
@@ -494,7 +510,9 @@ def admin_unban_user(user_id):
|
|||||||
def admin_new_user():
|
def admin_new_user():
|
||||||
try:
|
try:
|
||||||
name, password = request.form['name'], request.form['password']
|
name, password = request.form['name'], request.form['password']
|
||||||
if db.add_user(name, hash_password(password), time.time_ns()):
|
if name == '' or password == '':
|
||||||
|
flash('Name and password may not be empty')
|
||||||
|
elif db.add_user(name, hash_password(password), time.time_ns()):
|
||||||
flash('Added user', 'success')
|
flash('Added user', 'success')
|
||||||
else:
|
else:
|
||||||
flash('Failed to add user', 'error')
|
flash('Failed to add user', 'error')
|
||||||
|
|||||||
Reference in New Issue
Block a user