From 40ce368e59e4f20e3a0ce5686f9c663671ac6935 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Fri, 16 May 2025 13:41:24 -0400 Subject: [PATCH] More style clean up. Less is more info. --- src/lib/ae_core/core__user.ts | 1 - src/lib/e_app_access_type.svelte | 10 +- src/lib/e_app_sign_in_out.svelte | 167 ++++++++++++++++++++++++------- src/lib/e_app_sys_menu.svelte | 8 +- 4 files changed, 143 insertions(+), 43 deletions(-) diff --git a/src/lib/ae_core/core__user.ts b/src/lib/ae_core/core__user.ts index 7c2cae27..419d3285 100644 --- a/src/lib/ae_core/core__user.ts +++ b/src/lib/ae_core/core__user.ts @@ -247,7 +247,6 @@ export async function qry_ae_obj_li__user_email( console.log(`*** qry_ae_obj_li__user_email() *** account_id=${account_id} email=${email}`); } - // /user/lookup_email let endpoint = '/user/lookup_email'; params['email'] = email; // Required diff --git a/src/lib/e_app_access_type.svelte b/src/lib/e_app_access_type.svelte index f80644f1..b30a15d2 100644 --- a/src/lib/e_app_access_type.svelte +++ b/src/lib/e_app_access_type.svelte @@ -290,7 +290,7 @@ function handle_clear_access() { class="ae_header w-64 " >

- Passcode + Passcode Sign In

@@ -359,7 +359,7 @@ function handle_clear_access() { {/if} {/if} - {#if $ae_loc.edit_mode} + {/if} @@ -476,7 +476,7 @@ function handle_clear_access() { trigger_clear_access = true; // show_passcode_input = true; }} - class="btn btn-sm variant-outline-surface hover:variant-ghost-warning transition-all" + class="btn btn-sm variant-outline-warning hover:variant-ghost-warning transition-all" title={`Current access level: "${$ae_loc.access_type}". Click to clear the temporary access level.`} > @@ -490,7 +490,7 @@ function handle_clear_access() { {#if (show_passcode_input)} - Passcode? + Passcode: { }); -let new_password = $state(''); -let confirm_password = $state(''); +let user_email = $state('scott.idem@gmail.com'); // Used for quick lookup of user by email address +let new_password = $state('test12345'); +let confirm_password = $state('test12345'); let is_changing_password = $state(false); let show_password_text = $state('password'); // password or text @@ -241,34 +235,104 @@ function handle_lookup_user_email({email}: {email: string}) { async function handle_change_password() { - if (new_password !== confirm_password) { - alert('Passwords do not match.'); - return; - } - if (!new_password) { alert('Password cannot be empty.'); return; } - is_changing_password = true; + if (new_password !== confirm_password) { + alert('Passwords do not match.'); + return; + } - try { - await core_func.auth_ae_obj__user_id_change_password({ + let use_user_id = $ae_loc.user_id; + let use_password = new_password; + let wait_for_lookup = true; + + // Look up the user by email address to get their user ID + if (user_email) { + wait_for_lookup = true; + // ae_promises.load__user_obj_li = await core_func.qry_ae_obj_li__user_email({ + // api_cfg: $ae_api, + // account_id: $slct.account_id, + // null_account_id: false, + // email: user_email, + // log_lvl: 1 + // }).then((user_response) => { + // if (!user_response) { + // // This means a 404 was returned + // alert('No user found with that email address.'); + // return; + // } else if (user_response?.user_id_random) { + // console.log(`User found for email:`, user_response); + // use_user_id = user_response.user_id_random; + // } else if (user_response.length > 0) { + // console.log(`Multiple users found for email:`, user_response); + // use_user_id = user_response[0].user_id_random; + // } + // }); + + ae_promises.load__user_obj_li = await core_func.qry_ae_obj_li__user_email({ api_cfg: $ae_api, - account_id: $ae_loc.account_id, - user_id: $ae_loc.user_id, - password: new_password, + account_id: $slct.account_id, + null_account_id: false, + email: user_email, log_lvl: 1 }); - alert('Password changed successfully.'); - $ae_sess.show__modal_change_password = false; + + if (!ae_promises.load__user_obj_li) { + // This means a 404 was returned + alert('No user found with that email address.'); + return; + } else if (ae_promises.load__user_obj_li?.user_id_random) { + console.log(`User found for email:`, ae_promises.load__user_obj_li); + use_user_id = ae_promises.load__user_obj_li.user_id_random; + } else if (ae_promises.load__user_obj_li.length > 0) { + console.log(`Multiple users found for email:`, ae_promises.load__user_obj_li); + use_user_id = ae_promises.load__user_obj_li[0].user_id_random; + } + } else { + wait_for_lookup = false; + } + + is_changing_password = true; + + if (user_email && wait_for_lookup) { + console.log('Waiting for user lookup to complete...'); + // await ae_promises.load__user_obj_li; + } + + try { + ae_promises.change_password = await core_func.auth_ae_obj__user_id_change_password({ + api_cfg: $ae_api, + account_id: $ae_loc.account_id, + user_id: use_user_id, + password: use_password, + log_lvl: log_lvl + }); + // await core_func.auth_ae_obj__user_id_change_password({ + // api_cfg: $ae_api, + // account_id: $ae_loc.account_id, + // user_id: use_user_id, + // password: use_password, + // log_lvl: log_lvl + // }); + // alert('Password changed successfully.'); + // $ae_sess.show__modal_change_password = false; } catch (error) { console.error('Error changing password:', error); - alert('Failed to change password.'); + alert('Unexpected Response. Failed to change password.'); } finally { is_changing_password = false; } + if (ae_promises.change_password) { + console.log('Password changed successfully.'); + alert('Password changed successfully.'); + $ae_sess.show__modal_change_password = false; + } else { + console.error('Failed to change password.'); + alert('Failed to change password. Check password length.'); + } } @@ -293,7 +357,7 @@ async function handle_change_password() { > + +
+ + Password must be at least 10 characters long. It is recommend that you use a pass phrase (multiple words as your password) or a complex password (uppercase letter, lowercase letters, numbers, and special characters). + +
diff --git a/src/lib/e_app_sys_menu.svelte b/src/lib/e_app_sys_menu.svelte index 8ecce5e5..210e2d4e 100644 --- a/src/lib/e_app_sys_menu.svelte +++ b/src/lib/e_app_sys_menu.svelte @@ -133,8 +133,10 @@ max-w-max --> overflow-y-auto p-1 + w-full + bg-white/10 dark:dark-gray-800/10 - hover:bg-white/100 dark:hover:bg-gray-800/100 + hover:bg-red-100/50 dark:hover:bg-gray-800/100 relative *:hover:inline @@ -343,7 +345,7 @@ max-w-max --> class:w-48={$ae_loc?.app_cfg?.show_element__menu} class:visible={$ae_loc?.app_cfg?.show_element__menu} class:invisible={!$ae_loc?.app_cfg?.show_element__menu} - class="btn btn-sm variant-outline-surface hover:variant-ghost-success px-6 py-1" + class="btn btn-sm variant-outline-tertiary hover:variant-ghost-success px-6 py-1" title="Show or hide the menu" onclick={async () => { if (!$ae_loc?.app_cfg?.show_element__menu) { @@ -423,7 +425,7 @@ max-w-max -->