Improvements to access type and sign in and out process.

This commit is contained in:
Scott Idem
2025-05-01 17:09:06 -04:00
parent 63cb0f2969
commit 9687fe0c90
4 changed files with 232 additions and 68 deletions

View File

@@ -32,7 +32,7 @@ import {
LogIn, LogOut, LockKeyhole,
Mail, MailCheck,
Menu,
ShieldUser,
ShieldEllipsis, ShieldMinus, ShieldPlus, ShieldUser,
User, UserCheck
} from '@lucide/svelte';
@@ -173,12 +173,16 @@ if ($ae_loc && $ae_sess && ($ae_loc.ver != $ae_sess.ver)) {
// Minutes reference:
// 240 = 4 hours; 720 = 12 hours; 2880 = 48 hours;
// 10080 = 1 week; 20160 = 2 weeks; 43200 = 1 month;
let default_refresh_minutes: number = 60;
let trusted_refresh_minutes: number = 120;
let manager_refresh_minutes: number = 2880;
let default_refresh_minutes: number = 120;
let authenticated_refresh_minutes: number = 240;
let trusted_refresh_minutes: number = 10080;
let manager_refresh_minutes: number = 20160;
if ($ae_loc?.site_cfg_json?.default_refresh_minutes) {
default_refresh_minutes = $ae_loc.site_cfg_json.default_refresh_minutes;
}
if ($ae_loc?.site_cfg_json?.authenticated_refresh_minutes) {
authenticated_refresh_minutes = $ae_loc.site_cfg_json.authenticated_refresh_minutes;
}
if ($ae_loc?.site_cfg_json?.trusted_refresh_minutes) {
trusted_refresh_minutes = $ae_loc.site_cfg_json.trusted_refresh_minutes;
}
@@ -186,13 +190,14 @@ if ($ae_loc?.site_cfg_json?.manager_refresh_minutes) {
manager_refresh_minutes = $ae_loc.site_cfg_json.manager_refresh_minutes;
}
let default_refresh_time = default_refresh_minutes * 60 * 1000; // 48 hours or 2880 minutes? 48 * 60 *
let trusted_refresh_time = trusted_refresh_minutes * 60 * 1000; // 1 week or 10080 minutes?
let manager_refresh_time = manager_refresh_minutes * 60 * 1000; // 1 week or 10080 minutes?
let default_refresh_time = default_refresh_minutes * 60 * 1000;
let authenticated_refresh_time = authenticated_refresh_minutes * 60 * 1000;
let trusted_refresh_time = trusted_refresh_minutes * 60 * 1000;
let manager_refresh_time = manager_refresh_minutes * 60 * 1000;
// IDB caches - Check if the last refresh timestamp for $ae_loc.last_cache_refresh is no more than 15 minutes ago.
let default_idb_refresh_time = 120 * 60 * 60 * 1000; // 15 minutes?
let trusted_idb_refresh_time = 120 * 60 * 60 * 1000; // 4 hours or 120 minutes?
let trusted_idb_refresh_time = 240 * 60 * 60 * 1000; // 4 hours or 120 minutes?
if (!$ae_loc?.last_cache_refresh) { // Default is null, currently...
console.log(`ROOT: Last reload not found. Need to set!`);
@@ -215,7 +220,18 @@ if (!$ae_loc?.last_cache_refresh) { // Default is null, currently...
console.log(`ROOT: Last diff: ${Date.now() - $ae_loc?.last_cache_refresh}`);
}
if ($ae_loc?.trusted_access && (Date.now() - $ae_loc?.last_cache_refresh) > trusted_refresh_time) {
if ($ae_loc?.manager_access && (Date.now() - $ae_loc?.last_cache_refresh) > manager_refresh_time) {
console.log(`ROOT: Last (manager) local config reload too old for all caches: ${$ae_loc.last_cache_refresh}`);
flag_clear_idb = true;
flag_clear_local = true;
flag_clear_sess = true;
flag_reload = true;
flag_expired = true;
$ae_loc.cache_expired = true;
$ae_loc.allow_access = false;
} else if ($ae_loc?.trusted_access && (Date.now() - $ae_loc?.last_cache_refresh) > trusted_refresh_time) {
console.log(`ROOT: Last (trusted) local config reload too old for all caches: ${$ae_loc.last_cache_refresh}`);
flag_clear_idb = true;
@@ -226,8 +242,8 @@ if (!$ae_loc?.last_cache_refresh) { // Default is null, currently...
$ae_loc.cache_expired = true;
$ae_loc.allow_access = false;
} else if (!$ae_loc?.trusted_access && (Date.now() - $ae_loc?.last_cache_refresh) > default_refresh_time) {
console.log(`ROOT: Last (default) local config reload too old for all caches: ${$ae_loc.last_cache_refresh}`);
} else if ($ae_loc?.authenticated_access && (Date.now() - $ae_loc?.last_cache_refresh) > authenticated_refresh_time) {
console.log(`ROOT: Last (authenticated) local config reload too old for all caches: ${$ae_loc.last_cache_refresh}`);
flag_clear_idb = true;
flag_clear_local = true;
@@ -237,8 +253,8 @@ if (!$ae_loc?.last_cache_refresh) { // Default is null, currently...
$ae_loc.cache_expired = true;
$ae_loc.allow_access = false;
} else if ($ae_loc?.manager_access && (Date.now() - $ae_loc?.last_cache_refresh) > manager_refresh_time) {
console.log(`ROOT: Last (manager) local config reload too old for all caches: ${$ae_loc.last_cache_refresh}`);
} else if ((Date.now() - $ae_loc?.last_cache_refresh) > default_refresh_time) {
console.log(`ROOT: Last (default) local config reload too old for all caches: ${$ae_loc.last_cache_refresh}`);
flag_clear_idb = true;
flag_clear_local = true;
@@ -254,6 +270,7 @@ if (!$ae_loc?.last_cache_refresh) { // Default is null, currently...
}
}
// Only clear IDB, not the local or session storage.
if ($ae_loc?.trusted_access && (Date.now() - $ae_loc?.last_cache_refresh) > trusted_idb_refresh_time) {
console.log(`ROOT: Last (trusted) IDB reload too old for IDB: ${$ae_loc.last_cache_refresh}`);
@@ -432,7 +449,7 @@ function clear_idb() {
// indexedDB.deleteDatabase('presenters'); // Events module <-- WARNING
// indexedDB.deleteDatabase('sessions'); // Events module <-- WARNING
// indexedDB.deleteDatabase('file'); // Core - Hosted Files module
indexedDB.deleteDatabase('ae_journals_db');
indexedDB.deleteDatabase('ae_journals_db'); // Journals module
// indexedDB.deleteDatabase('journal_entry');
// indexedDB.deleteDatabase('notes');
indexedDB.deleteDatabase('ae_posts_db'); // Posts module
@@ -913,12 +930,13 @@ max-w-max -->
</button>
{/if}
<div class="transition-all *:hover:inline">
<div class="flex flex-row flex-wrap gap-1 items-center justify-center transition-all *:hover:inline">
{#if $ae_loc.access_type && $ae_loc.access_type != 'anonymous'}
<span
class="*:hover:inline"
>
<span class="fas fa-unlock mx-1"></span>
<!-- <span class="fas fa-unlock mx-1"></span> -->
<ShieldPlus class="inline-block" />
{#if $ae_loc.access_type == 'super'}
@@ -946,25 +964,63 @@ max-w-max -->
{/if}
</span>
<button
type="button"
onclick={() => {
trigger_clear_access = true;
{#if $ae_loc?.user_access_type && $ae_loc?.access_type == $ae_loc?.user_access_type}
<button
type="button"
onclick={() => {
// handle_clear_access();
// trigger_clear_access = true;
// $ae_loc.app_cfg.show_element__passcode_input = !$ae_loc.app_cfg.show_element__passcode_input;
if ($ae_loc?.app_cfg?.show_element__menu_btn) {
$ae_loc.app_cfg.show_element__menu = true;
$ae_loc.app_cfg.show_element__menu_btn = false;
$ae_loc.app_cfg.show_element__access_type = true;
} else {
$ae_loc.app_cfg.show_element__menu = false;
$ae_loc.app_cfg.show_element__menu_btn = true;
}
}}
class="btn btn-sm variant-outline-surface hover:variant-ghost-warning transition-all hidden"
title="Access mode is currently enabled/unlocked. Click to exit and lock."
>
<span class="fas fa-lock mx-1"></span> Lock?
</button>
if ($ae_loc?.app_cfg?.show_element__menu_btn) {
$ae_loc.app_cfg.show_element__menu = true;
$ae_loc.app_cfg.show_element__menu_btn = false;
$ae_loc.app_cfg.show_element__access_type = true;
$ae_loc.app_cfg.show_element__passcode_input = true;
} else {
$ae_loc.app_cfg.show_element__menu = false;
$ae_loc.app_cfg.show_element__menu_btn = true;
}
}}
class="btn btn-sm variant-outline-surface hover:variant-ghost-warning transition-all *:hover:inline"
title="Access mode is currently enabled/unlocked. Click to exit and lock."
>
<!-- <span class="fas fa-lock mx-1"></span> -->
<!-- <ShieldMinus /> -->
<ShieldEllipsis class="inline-block" />
<span class="hidden">Passcode?</span>
</button>
{:else}
<button
type="button"
onclick={() => {
trigger_clear_access = true;
if ($ae_loc?.app_cfg?.show_element__menu_btn) {
$ae_loc.app_cfg.show_element__menu = true;
$ae_loc.app_cfg.show_element__menu_btn = false;
$ae_loc.app_cfg.show_element__access_type = true;
$ae_loc.app_cfg.show_element__passcode_input = true;
// await tick();
// console.log('Layout button click: Focus on passcode input!');
// /** @type {HTMLElement | null} */
// const to_focus = document.getElementById('access_passcode_input');
// to_focus?.focus();
} else {
$ae_loc.app_cfg.show_element__menu = false;
$ae_loc.app_cfg.show_element__menu_btn = true;
}
}}
class="btn btn-sm variant-outline-surface hover:variant-ghost-warning transition-all hidden"
title="Access mode is currently enabled/unlocked. Click to exit and lock."
>
<!-- <span class="fas fa-lock mx-1"></span> Lock? -->
<ShieldMinus class="inline-block" />
Clear?
</button>
{/if}
{:else}
<button
type="button"
@@ -993,7 +1049,7 @@ max-w-max -->
>
<!-- <span class="fas fa-lock mx-1 lock_icon"></span> -->
<!-- <span class="">Unlock?</span> -->
<ShieldUser />
<ShieldUser class="inline-block" />
<span class="hidden">Auth?</span>
</button>
{/if}
@@ -1009,7 +1065,13 @@ max-w-max -->
$ae_loc.app_cfg.show_element__menu = true;
$ae_loc.app_cfg.show_element__menu_btn = false;
$ae_loc.app_cfg.show_element__access_type = true;
$ae_loc.app_cfg.show_element__passcode_input = true;
if ($ae_loc?.access_type == 'anonymous') {
$ae_loc.app_cfg.show_element__passcode_input = true;
} else {
$ae_loc.app_cfg.show_element__passcode_input = false;
}
// $ae_loc.app_cfg.show_element__passcode_input = true;
await tick();
console.log('Layout button click: Focus on passcode input!');
/** @type {HTMLElement | null} */
@@ -1018,6 +1080,7 @@ max-w-max -->
} else {
$ae_loc.app_cfg.show_element__menu = false;
$ae_loc.app_cfg.show_element__menu_btn = true;
$ae_loc.app_cfg.show_element__passcode_input = false;
}
// $ae_loc.app_cfg.show_element__menu_btn = !$ae_loc?.app_cfg?.show_element__menu_btn;
}}
@@ -1039,6 +1102,7 @@ max-w-max -->
</section>
<!-- Show menu on right side of page -->
<!-- min-h-96 -->
<section
class="
ae_app__menu
@@ -1047,7 +1111,7 @@ max-w-max -->
items-center
justify-end
gap-4
min-h-96
min-w-48
absolute right-0 bottom-10
bg-white dark:bg-gray-800