Add support for a profile change page

This commit is contained in:
Jonas Schäfer
2020-03-07 11:16:29 +01:00
parent 513cb0949b
commit 944cd333b3
5 changed files with 216 additions and 39 deletions

View File

@@ -44,6 +44,12 @@ class LogoutForm(FlaskForm):
pass
class ProfileForm(FlaskForm):
nickname = wtforms.TextField(
"Display name",
)
@user_bp.route("/")
async def index():
user_info = await client.get_user_info()
@@ -71,6 +77,22 @@ async def change_pw():
return await render_template("user_passwd.html", form=form)
@user_bp.route("/profile", methods=["GET", "POST"])
async def profile():
form = ProfileForm()
if request.method != "POST":
user_info = await client.get_user_info()
form.nickname.data = user_info.get("nickname", "")
if form.validate_on_submit():
user_info = await client.get_user_info()
if user_info.get("nickname") != form.nickname.data:
await client.set_user_nickname(form.nickname.data)
return redirect(url_for(".profile"))
return await render_template("user_profile.html", form=form)
@user_bp.route("/logout", methods=["GET", "POST"])
async def logout():
form = LogoutForm()