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

@@ -97,14 +97,15 @@ const ae_app_local_data_defaults: key_val = {
// 'trusted_passcode': '19111',
// 'authenticated_passcode': 'auth2024',
'access_type': 'anonymous',
'administrator_access': false,
'trusted_access': false,
'public_access': false,
'authenticated_access': false,
'anonymous_access': true,
access_type: 'anonymous',
administrator_access: false,
trusted_access: false,
public_access: false,
authenticated_access: false,
anonymous_access: true,
'user_email': null, // Currently used with Sponsorships only?
user_email: null, // Currently used with Sponsorships only?
user_access_type: null, // Used to revert back to the user's access type after quick access (temporarily escalate permissions) turned off.
// Added 2025-04-04
person_id: null, // The current person_id of the logged-in user (if any)
@@ -135,8 +136,10 @@ const ae_app_local_data_defaults: key_val = {
super: false, // Is the user a super user
manager: false, // Is the user a global manager (can manage accounts and users)
administrator: false, // Is the user an account administrator
verified: false, // Is the user verified
public: false, // Is the user a public user (can view public content)
person_id: null, // The person ID of the logged-in user
access_type: null, // The access type of the logged-in user
},
'qry__enabled': 'enabled', // all, disabled, enabled

View File

@@ -6,6 +6,10 @@ import { afterNavigate } from '$app/navigation';
// *** Import other supporting libraries
// import { liveQuery } from "dexie";
import {
ShieldEllipsis, ShieldMinus, ShieldPlus, ShieldUser,
User, UserCheck
} from '@lucide/svelte';
// *** Import Aether specific variables and functions
import { ae_util } from '$lib/ae_utils/ae_utils';
@@ -183,13 +187,18 @@ function handle_check_access_type_passcode() {
$ae_loc.access_type = 'authenticated';
} else {
console.log('Passcode does not match');
if (log_lvl > 1) {
console.log('Entered passcode does not match any of the site access codes.');
}
window.localStorage.setItem('access_type', 'anonymous');
if ($ae_loc.access_type != 'anonymous') {
console.log('Access type is not anonymous');
}
// window.localStorage.setItem('access_type', 'anonymous');
$ae_loc.access_type = 'anonymous';
// $ae_loc.access_type = 'anonymous';
trigger = 'process_permission_check';
// trigger = 'process_permission_check';
// $ae_loc = $ae_loc; // Trigger Svelte just in case
// ae_loc.set($ae_loc);
@@ -241,11 +250,12 @@ function handle_clear_access() {
window.localStorage.setItem('access_type', 'anonymous');
// $ae_loc.access_type = null; // 'anonymous';
$ae_loc.access_type = 'anonymous';
// Revert back to the user's access type after quick access (temporarily escalate permissions) is turned off.
$ae_loc.access_type = $ae_loc.user_access_type ?? 'anonymous';
trigger = 'process_permission_check';
entered_passcode = ''; // Clear the entered passcode
show_passcode_input = false;
show_passcode_input = true;
$ae_loc.app_cfg.show_element__menu = false;
$ae_loc.app_cfg.show_element__menu_btn = true;
@@ -382,9 +392,36 @@ function handle_clear_access() {
{/if}
</div>
<div class="transition-all">
{#if $ae_loc.access_type && $ae_loc.access_type != 'anonymous'}
<span class="fas fa-unlock mx-1"></span>
<div class="transition-all flex flex-row flex-wrap gap-1 items-end justify-end">
{#if $ae_loc?.access_type && $ae_loc?.access_type == 'anonymous' && 1==3}
<span>
<button
type="button"
onclick={() => {
// handle_check_access_type_passcode();
trigger = true;
}}
class="btn btn-sm variant-glass-success hover:variant-filled-warning access_type_unlock_btn transition-all"
title="Anonymous public access is currently set. Access mode is disabled/locked."
>
<span class="fas fa-lock mx-1"></span>
<span class="lock_icon">Locked</span>
<span class="fas fa-unlock mx-1 unlock_icon hidden"></span>
{#if (show_passcode_input)}
<span class="unlock_text">Cancel</span>
{:else}
<span class="unlock_text">Access?</span>
{/if}
</button>
</span>
{/if}
{#if ($ae_loc?.access_type && $ae_loc?.access_type != 'anonymous')}
<span class="flex flex-row gap-1 items-center justify-center">
<!-- <span class="fas fa-unlock mx-1"></span> -->
<ShieldPlus class="inline-block" />
<span
class="*:hover:inline"
@@ -414,18 +451,43 @@ function handle_clear_access() {
{/if}
</span>
<button
type="button"
onclick={() => {
// handle_clear_access();
trigger_clear_access = true;
}}
class="btn btn-sm variant-outline-surface hover:variant-ghost-warning transition-all"
title="Access mode is currently enabled/unlocked. Click to exit and lock."
>
<span class="fas fa-lock mx-1"></span> Lock?
</button>
{:else}
{#if $ae_loc?.user_access_type && $ae_loc?.access_type == $ae_loc?.user_access_type && !show_passcode_input}
<button
type="button"
onclick={() => {
// handle_clear_access();
// trigger_clear_access = true;
show_passcode_input = !show_passcode_input;
}}
class="btn btn-sm variant-outline-surface hover:variant-ghost-warning transition-all"
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" />
Passcode?
</button>
{:else if (!show_passcode_input)}
<button
type="button"
onclick={() => {
// handle_clear_access();
trigger_clear_access = true;
// show_passcode_input = true;
}}
class="btn btn-sm variant-outline-surface hover:variant-ghost-warning transition-all"
title="Access mode is currently enabled/unlocked. Click to exit and lock."
>
<!-- <span class="fas fa-lock mx-1"></span> -->
<ShieldMinus class="inline-block" />
Clear?
</button>
{/if}
</span>
{/if}
{#if (show_passcode_input)}
<span class="flex flex-row gap-1 items-center justify-center">
<button
type="button"
onclick={async () => {
@@ -438,7 +500,7 @@ function handle_clear_access() {
entered_passcode = ''; // Clear the entered passcode when showing the input
}
}}
class="btn btn-sm variant-glass-success hover:variant-filled-warning access_type_unlock_btn transition-all"
class="btn btn-sm variant-glass-success hover:variant-filled-warning access_type_unlock_btn transition-all hidden"
title="Anonymous public access is currently set. Access mode is disabled/locked."
>
<span class="fas fa-lock mx-1 lock_icon"></span>
@@ -453,17 +515,22 @@ function handle_clear_access() {
<!-- <span class="unlock_text">Cancel?</span> -->
</button>
<ShieldEllipsis class="inline-block" />
<span class="unlock_text">Passcode?</span>
<input
id="access_passcode_input"
bind:value={entered_passcode}
class="input w-32 transition-all"
class:hidden={!show_passcode_input}
type="text"
placeholder="Access code"
placeholder="Passcode"
autofocus={show_passcode_input}
/>
<!-- <div class="current_text transition-all">{$ae_loc.access_type}</div> -->
</span>
{/if}
</div>
</section>

View File

@@ -2,7 +2,7 @@
// *** Import Svelte specific
import { browser } from '$app/environment';
import { goto } from '$app/navigation';
import { goto, invalidateAll } from '$app/navigation';
import { Modal } from 'flowbite-svelte';
// *** Import other supporting libraries
@@ -90,6 +90,7 @@ function sign_in() {
} else {
$ae_loc.access_type = 'authenticated';
}
$ae_loc.user_access_type = $ae_loc.access_type; // Used to revert back to the user's access type after quick access (temporarily escalate permissions) is turned off.
let access_checks_results = ae_util.process_permission_checks($ae_loc.access_type);
// WARNING: I think this is causing a loop in Svelte or something.
@@ -138,6 +139,35 @@ function sign_out() {
// $ae_sess.auth__entered_username = null; // Keeping the username
$ae_sess.auth__entered_password = null;
indexedDB.deleteDatabase('ae_archives_db'); // Archives module
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db'); // Events module
indexedDB.deleteDatabase('ae_journals_db'); // Journals module
indexedDB.deleteDatabase('ae_posts_db'); // Posts module
indexedDB.deleteDatabase('ae_sponsorships_db'); // Sponsorships module
// $ae_loc.allow_access = false;
$ae_loc.authenticated_access = false;
$ae_loc.edit_mode = false;
localStorage.clear();
sessionStorage.clear();
console.log('Remove the sign out fields from the URL.');
data.url.searchParams.delete('user_id');
data.url.searchParams.delete('user_key');
data.url.searchParams.delete('username');
data.url.searchParams.delete('user_email');
data.url.searchParams.delete('valid_email'); // Part of sign in email for possible future use
let new_url = data.url.toString();
// We need to set browser history and force all load functions to rerun.
// goto(new_url, {replaceState: true, invalidateAll: true});
// invalidateAll();
window.location.reload();
console.log('Signed out successfully.');
}