Separate public and logged-in user settings
This commit is contained in:
parent
6c1e0887b6
commit
009cb6aade
@ -43,8 +43,6 @@ def create_app(test_config=None):
|
|||||||
|
|
||||||
def update_settings(form, files):
|
def update_settings(form, files):
|
||||||
db = get_database()
|
db = get_database()
|
||||||
|
|
||||||
if "user_id" in session:
|
|
||||||
# Set values in the database
|
# Set values in the database
|
||||||
settings = db.execute("SELECT * FROM user_settings WHERE user_id = ?",
|
settings = db.execute("SELECT * FROM user_settings WHERE user_id = ?",
|
||||||
(session["user_id"],)
|
(session["user_id"],)
|
||||||
@ -65,19 +63,36 @@ def create_app(test_config=None):
|
|||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
update_logged_out_settings(form)
|
||||||
|
|
||||||
|
return redirect("/options")
|
||||||
|
|
||||||
|
def update_logged_out_settings(form):
|
||||||
# Set values directly in the session
|
# Set values directly in the session
|
||||||
session["language"] = form["language"]
|
session["language"] = form["language"]
|
||||||
session["theme"] = form["theme"]
|
session["theme"] = form["theme"]
|
||||||
|
return redirect("/public_options")
|
||||||
return redirect("/options")
|
|
||||||
|
|
||||||
@app.route("/options", methods=["GET", "POST"])
|
@app.route("/options", methods=["GET", "POST"])
|
||||||
def options():
|
def options():
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
|
if "user_id" in session:
|
||||||
return render_template("options.html")
|
return render_template("options.html")
|
||||||
|
else:
|
||||||
|
return redirect("/public_options")
|
||||||
else:
|
else:
|
||||||
return update_settings(request.form, request.files)
|
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/<int:user_id>")
|
@app.get("/user/<int:user_id>")
|
||||||
def user_page(user_id: int):
|
def user_page(user_id: int):
|
||||||
db = get_database()
|
db = get_database()
|
||||||
|
25
kanken_online/templates/logged_out_options.html
Normal file
25
kanken_online/templates/logged_out_options.html
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<h1>{% block title %}{{ localize("options") }}{% endblock %}</h1>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form method="post" enctype=multipart/form-data>
|
||||||
|
<label for="language-select">{{ localize("language") }}</label>
|
||||||
|
<select name="language" id="language-select">
|
||||||
|
<option value="ja">日本語</option>
|
||||||
|
<option value="en">English</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label for="theme-select">{{ localize("theme") }}</label>
|
||||||
|
<select name="theme" id="theme-select">
|
||||||
|
<option value="dark">{{ localize("dark_theme") }}</option>
|
||||||
|
<option value="light">{{ localize("light_theme") }}</option>
|
||||||
|
</select>
|
||||||
|
{% block logged_in_options %}{% endblock %}
|
||||||
|
<hr>
|
||||||
|
<button type="submit">Okay</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -1,27 +1,10 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'logged_out_options.html' %}
|
||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
<h1>{% block title %}{{ localize("options") }}{% endblock %}</h1>
|
<h1>{% block title %}{{ localize("options") }}{% endblock %}</h1>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block logged_in_options %}
|
||||||
<form method="post" enctype=multipart/form-data>
|
|
||||||
<label for="language-select">{{ localize("language") }}</label>
|
|
||||||
<select name="language" id="language-select">
|
|
||||||
<option value="ja">日本語</option>
|
|
||||||
<option value="en">English</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<label for="theme-select">{{ localize("theme") }}</label>
|
|
||||||
<select name="theme" id="theme-select">
|
|
||||||
<option value="dark">{{ localize("dark_theme") }}</option>
|
|
||||||
<option value="light">{{ localize("light_theme") }}</option>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<label for="pfp">{{ localize("pfp") }}</label>
|
<label for="pfp">{{ localize("pfp") }}</label>
|
||||||
<input type="file" id="pfp" name="pfp">
|
<input type="file" id="pfp" name="pfp">
|
||||||
|
|
||||||
<hr>
|
|
||||||
<button type="submit">Okay</button>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Reference in New Issue
Block a user