~vpzom/hitide

9439561f835bd6a1ca2196881122f6e2fa9c946c — Colin Reeder 7 months ago ccae2cb
Add password change UI to user edit page
2 files changed, 16 insertions(+), 1 deletions(-)

M res/lang/en.ftl
M src/routes/mod.rs
M res/lang/en.ftl => res/lang/en.ftl +1 -0
@@ 126,6 126,7 @@ to_post = Comment on
url = URL
user_edit_description_prompt = Profile Description:
user_edit_not_you = You can only edit your own profile.
user_edit_password_prompt = Change Password
user_edit_submit = Save
user_edit_title = Edit Profile
user_id_prompt = User ID:

M src/routes/mod.rs => src/routes/mod.rs +15 -1
@@ 1330,6 1330,12 @@ async fn page_user_edit(
                        <textarea name={"description"}>{user.description.as_ref()}</textarea>
                    </label>
                </div>
                <div>
                    <label>
                        {lang.tr("user_edit_password_prompt", None)}<br />
                        <input name={"password"} type={"password"} value={""} autocomplete={"new-password"} />
                    </label>
                </div>
                <button type={"submit"}>{lang.tr("user_edit_submit", None)}</button>
            </form>
        </HTPage>


@@ 1348,7 1354,15 @@ async fn handler_user_edit_submit(
    let cookies = get_cookie_map_for_headers(&req_parts.headers)?;

    let body = hyper::body::to_bytes(body).await?;
    let body: serde_json::Value = serde_urlencoded::from_bytes(&body)?;
    let mut body: serde_json::map::Map<String, serde_json::Value> =
        serde_urlencoded::from_bytes(&body)?;

    // ignore password field if blank
    if let Some(password) = body.get("password") {
        if password == "" {
            body.remove("password");
        }
    }

    res_to_error(
        ctx.http_client