2023-09-27 11:36:52 +02:00
|
|
|
use leptos::*;
|
|
|
|
|
use crate::backend::data::{ApiResponse, User};
|
|
|
|
|
use crate::backend::user::ChangePwd;
|
2023-09-28 21:42:12 +02:00
|
|
|
use crate::components::data_form::DataForm;
|
|
|
|
|
use crate::components::modal_box::DialogOpener;
|
2023-09-27 11:36:52 +02:00
|
|
|
|
|
|
|
|
#[component]
|
|
|
|
|
pub fn change_password(user: ReadSignal<User>, opener: DialogOpener) -> impl IntoView {
|
|
|
|
|
let change_pwd = create_server_action::<ChangePwd>();
|
|
|
|
|
let empty = create_rw_signal("".to_string());
|
|
|
|
|
|
|
|
|
|
view! {
|
|
|
|
|
{move || {
|
2023-09-28 21:42:12 +02:00
|
|
|
if let Some(res) = change_pwd.value().get() {
|
2023-09-27 11:36:52 +02:00
|
|
|
if let Ok(r) = res {
|
|
|
|
|
if let ApiResponse::Data(_) = r { empty.update(|e| *e = "".to_string())}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
view! {
|
2023-09-28 21:42:12 +02:00
|
|
|
<DataForm opener=opener action=change_pwd title="Change password">
|
2023-09-27 11:36:52 +02:00
|
|
|
<input type="hidden" value={move || user.get().login} name="new_pw[login]"/>
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col mb-3">
|
|
|
|
|
<label for="oldPw" class="form-label">"Old password"</label>
|
|
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
id="oldPw"
|
|
|
|
|
class="form-control"
|
|
|
|
|
name="new_pw[old_password]"
|
|
|
|
|
prop:value={move || empty.get()}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col mb-3">
|
|
|
|
|
<label for="newPw" class="form-label">"New password"</label>
|
|
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
id="newPw"
|
|
|
|
|
class="form-control"
|
|
|
|
|
name="new_pw[password]"
|
|
|
|
|
prop:value={move || empty.get()}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="row">
|
|
|
|
|
<div class="col mb-3">
|
|
|
|
|
<label for="verPw" class="form-label">"Verify password"</label>
|
|
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
id="verPw"
|
|
|
|
|
class="form-control"
|
|
|
|
|
name="new_pw[password_ver]"
|
|
|
|
|
prop:value={move || empty.get()}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-09-28 21:42:12 +02:00
|
|
|
</DataForm>
|
2023-09-27 11:36:52 +02:00
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
}
|
|
|
|
|
}
|