Adding a Change Password option.
This commit is contained in:
@@ -279,3 +279,62 @@ export async function qry_ae_obj_li__user_email(
|
||||
}
|
||||
return ae_promises.qry__user_email;
|
||||
}
|
||||
|
||||
|
||||
// Change user password
|
||||
// endpoint: PATCH /user/{user_id}/change_password
|
||||
// params:
|
||||
// data_kv: password (the new password)
|
||||
// Updated 2025-04-11
|
||||
export async function auth_ae_obj__user_id_change_password(
|
||||
{
|
||||
api_cfg,
|
||||
account_id,
|
||||
user_id,
|
||||
password,
|
||||
params = {},
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
account_id: string,
|
||||
user_id: string,
|
||||
password: string,
|
||||
params?: key_val,
|
||||
log_lvl?: number
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** auth_ae_obj__user_id_change_password() *** account_id=${account_id} user_id=${user_id}`);
|
||||
}
|
||||
|
||||
let endpoint = `/user/${user_id}/change_password`;
|
||||
|
||||
params['user_id'] = user_id; // Required
|
||||
if (log_lvl > 1) {
|
||||
console.log(`auth_ae_obj__user_id_change_password() - params:`, params);
|
||||
}
|
||||
|
||||
ae_promises.change_password__user_id = await api.patch_object({
|
||||
api_cfg: api_cfg,
|
||||
endpoint: endpoint,
|
||||
params: params,
|
||||
data: { password: password },
|
||||
log_lvl: log_lvl
|
||||
})
|
||||
.then(async function (change_password_result) {
|
||||
if (change_password_result) {
|
||||
return change_password_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.change_password__user_id:', ae_promises.change_password__user_id);
|
||||
}
|
||||
return ae_promises.change_password__user_id;
|
||||
}
|
||||
|
||||
@@ -568,6 +568,24 @@ function handle_lookup_user_email({email}: {email: string}) {
|
||||
<span class="text-sm text-gray-500">
|
||||
{$ae_loc?.user.username ?? '-- not set --'}
|
||||
</span>
|
||||
|
||||
<!-- Display change password option if the user is signed in and in Edit Mode -->
|
||||
{#if $ae_loc.edit_mode}
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm variant-filled-warning"
|
||||
title="Change Password"
|
||||
onclick={() => {
|
||||
$ae_sess.show__modal_change_password = true;
|
||||
}}
|
||||
>
|
||||
<LockKeyhole class="mx-1" />
|
||||
<span class="hidden sm:inline">
|
||||
Change Password
|
||||
</span>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<!-- Display sign out option if the user is signed in -->
|
||||
<button
|
||||
type="button"
|
||||
@@ -580,7 +598,9 @@ function handle_lookup_user_email({email}: {email: string}) {
|
||||
}}
|
||||
>
|
||||
<LogOut class="mx-1" />
|
||||
Sign Out
|
||||
<span class="hidden sm:inline">
|
||||
Sign Out
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ async function change_journal_id() {
|
||||
console.error('Error updating journal entry:', error);
|
||||
alert('Failed to update journal entry.');
|
||||
}
|
||||
|
||||
$journals_slct.journal_id = tmp_entry_obj?.journal_id;
|
||||
goto(`/journals/${tmp_entry_obj?.journal_id}`);
|
||||
}
|
||||
</script>
|
||||
@@ -674,6 +674,7 @@ async function change_journal_id() {
|
||||
class="
|
||||
flex-grow
|
||||
flex flex-col items-center justify-center
|
||||
w-full max-w-6xl
|
||||
"
|
||||
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user