summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-06-14 09:00:13 +0000
committerubq323 <ubq323>2021-06-14 09:00:13 +0000
commitf2f0d79cc7f7058e31c1d4a7836b200327c320f0 (patch)
tree92be72506f1ea6185c58be6fed4f88513f885c6f
parentfda2230b8c3124c3ee616aed77d0f928ce63b285 (diff)
fix permissions bug on create thread page
-rw-r--r--apioforum/forum.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/apioforum/forum.py b/apioforum/forum.py
index 61babbd..f25d0da 100644
--- a/apioforum/forum.py
+++ b/apioforum/forum.py
@@ -3,7 +3,7 @@
from flask import (
Blueprint, render_template, request,
- g, redirect, url_for
+ g, redirect, url_for, flash
)
from .db import get_db
@@ -18,13 +18,16 @@ def view_forum():
@bp.route("/create_thread",methods=("GET","POST"))
def create_thread():
db = get_db()
+
+ if g.user is None:
+ flash("you need to be logged in to create a thread")
+ return redirect(url_for('index'))
+
if request.method == "POST":
title = request.form['title']
content = request.form['content']
err = None
- if g.user is None:
- err = "you need to be logged in to create a thread"
- elif len(title.strip()) == 0 or len(content.strip()) == 0:
+ if len(title.strip()) == 0 or len(content.strip()) == 0:
err = "title and content can't be empty"
if err is None:
@@ -40,6 +43,7 @@ def create_thread():
)
db.commit()
return redirect(url_for('thread.view_thread',thread_id=thread_id))
+ flash(err)
return render_template("create_thread.html")