diff --git a/kanken_online/__init__.py b/kanken_online/__init__.py index d926b89..4ae4c23 100644 --- a/kanken_online/__init__.py +++ b/kanken_online/__init__.py @@ -43,41 +43,56 @@ def create_app(test_config=None): def update_settings(form, files): db = get_database() - - if "user_id" in session: - # Set values in the database - settings = db.execute("SELECT * FROM user_settings WHERE user_id = ?", - (session["user_id"],) - ).fetchone() - if settings: - db.execute("UPDATE user_settings SET lang = ?, theme = ? WHERE user_id = ?", - (form["language"], form["theme"], session["user_id"])) - else: - db.execute("INSERT INTO user_settings (user_id, lang, theme) VALUES (?, ?, ?)", - (session["user_id"], form["language"], form["theme"])) - - if "pfp" in files and files["pfp"].filename != "": - stored_filename = str(uuid.uuid4()) - pfp = files["pfp"] - pfp.save(os.path.join(app.config["PFP_STORE"], stored_filename)) - - db.execute("UPDATE user_settings SET pfp_filename = ?", (stored_filename,)) - - db.commit() + # Set values in the database + settings = db.execute("SELECT * FROM user_settings WHERE user_id = ?", + (session["user_id"],) + ).fetchone() + if settings: + db.execute("UPDATE user_settings SET lang = ?, theme = ? WHERE user_id = ?", + (form["language"], form["theme"], session["user_id"])) + else: + db.execute("INSERT INTO user_settings (user_id, lang, theme) VALUES (?, ?, ?)", + (session["user_id"], form["language"], form["theme"])) + if "pfp" in files and files["pfp"].filename != "": + stored_filename = str(uuid.uuid4()) + pfp = files["pfp"] + pfp.save(os.path.join(app.config["PFP_STORE"], stored_filename)) + + db.execute("UPDATE user_settings SET pfp_filename = ?", (stored_filename,)) + + db.commit() + + update_logged_out_settings(form) + + return redirect("/options") + + def update_logged_out_settings(form): # Set values directly in the session session["language"] = form["language"] session["theme"] = form["theme"] - - return redirect("/options") + return redirect("/public_options") @app.route("/options", methods=["GET", "POST"]) def options(): if request.method == "GET": - return render_template("options.html") + if "user_id" in session: + return render_template("options.html") + else: + return redirect("/public_options") else: return update_settings(request.form, request.files) + @app.route("/public_options", methods=["GET", "POST"]) + def public_options(): + if request.method == "GET": + if "user_id" in session: + return redirect("/public_options") + else: + return render_template("logged_out_options.html") + else: + return update_logged_out_settings(request.form) + @app.get("/user/") def user_page(user_id: int): db = get_database() diff --git a/kanken_online/templates/logged_out_options.html b/kanken_online/templates/logged_out_options.html new file mode 100644 index 0000000..7ca85df --- /dev/null +++ b/kanken_online/templates/logged_out_options.html @@ -0,0 +1,25 @@ +{% extends 'base.html' %} + +{% block header %} +

{% block title %}{{ localize("options") }}{% endblock %}

+{% endblock %} + +{% block content %} +
+ + + + + + {% block logged_in_options %}{% endblock %} +
+ +
+ +{% endblock %} \ No newline at end of file diff --git a/kanken_online/templates/options.html b/kanken_online/templates/options.html index b6a5d8c..aed8fa1 100644 --- a/kanken_online/templates/options.html +++ b/kanken_online/templates/options.html @@ -1,27 +1,10 @@ -{% extends 'base.html' %} +{% extends 'logged_out_options.html' %} {% block header %}

{% block title %}{{ localize("options") }}{% endblock %}

{% endblock %} -{% block content %} -
- - - - - - +{% block logged_in_options %} - -
- -
{% endblock %} \ No newline at end of file