1
0
Fork 0
mirror of https://github.com/Lynnesbian/FediBooks/ synced 2024-11-25 08:38:59 +00:00

clean up error handling

This commit is contained in:
Lynne Megido 2019-09-09 22:15:10 +10:00
parent 9d6615b579
commit 49ddde2b9f

View file

@ -67,29 +67,20 @@ def about():
@app.route("/login") @app.route("/login")
def show_login_page(): def show_login_page():
error = None return render_template("login.html", signup = False, error = session.pop('error', None))
if 'error' in session:
error = session.pop('error')
return render_template("login.html", signup = False, error = error)
@app.route("/signup") @app.route("/signup")
def show_signup_page(): def show_signup_page():
error = None return render_template("login.html", signup = True, error = session.pop('error', None))
if 'error' in session:
error = session.pop('error')
return render_template("login.html", signup = True, error = error)
@app.route("/settings", methods=['GET', 'POST']) @app.route("/settings", methods=['GET', 'POST'])
def settings(): def settings():
error = None
if request.method == 'GET': if request.method == 'GET':
dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor) dc = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
dc.execute("SELECT * FROM `users` WHERE id = %s", (session['user_id'],)) dc.execute("SELECT * FROM `users` WHERE id = %s", (session['user_id'],))
user = dc.fetchone() user = dc.fetchone()
dc.close() dc.close()
if 'error' in session: return render_template("settings.html", user = user, error = session.pop('error', None), success = session.pop('success', None))
error = session.pop('error')
return render_template("settings.html", user = user, error = error, success = session.pop('success', None))
else: else:
# update settings # update settings
@ -199,7 +190,6 @@ def bot_accounts(id):
@app.route("/bot/accounts/add", methods = ['GET', 'POST']) @app.route("/bot/accounts/add", methods = ['GET', 'POST'])
def bot_accounts_add(): def bot_accounts_add():
error = None
if request.method == 'POST': if request.method == 'POST':
if session['step'] == 1: if session['step'] == 1:
if request.form['account'] == session['bot']: if request.form['account'] == session['bot']:
@ -245,7 +235,7 @@ def bot_accounts_add():
error = "Couldn't access ActivityPub outbox. {} may require authenticated fetches, which FediBooks doesn't support yet." error = "Couldn't access ActivityPub outbox. {} may require authenticated fetches, which FediBooks doesn't support yet."
return render_template("bot_accounts_add.html", error = error) return render_template("bot_accounts_add.html", error = error)
return render_template("bot_accounts_add.html", error = error) return render_template("bot_accounts_add.html", error = session.pop('error', None))
@app.route("/bot/accounts/toggle/<id>") @app.route("/bot/accounts/toggle/<id>")
def bot_accounts_toggle(id): def bot_accounts_toggle(id):
@ -276,7 +266,6 @@ def bot_accounts_delete(id):
@app.route("/bot/create/", methods=['GET', 'POST']) @app.route("/bot/create/", methods=['GET', 'POST'])
def bot_create(): def bot_create():
error = None
if request.method == 'POST': if request.method == 'POST':
if session['step'] == 1: if session['step'] == 1:
# strip leading https://, if provided # strip leading https://, if provided
@ -382,9 +371,7 @@ def bot_create():
del session['client_id'] del session['client_id']
del session['client_secret'] del session['client_secret']
if 'error' in session: return render_template("bot_create.html", error = session.pop('error', None))
error = session.pop('error')
return render_template("bot_create.html", error = error)
@app.route("/bot/create/back") @app.route("/bot/create/back")
def bot_create_back(): def bot_create_back():