Working on improved default permissions and allow control per site and site domains.
This commit is contained in:
@@ -115,6 +115,25 @@ if ($ae_loc.site_cfg_json.slct__sponsorship_cfg_id) {
|
||||
console.log(`No Sponsorship Config ID set.`);
|
||||
}
|
||||
|
||||
|
||||
if ($ae_loc.allow_access && !$ae_loc.key_checked) {
|
||||
console.log(`PASS: The access key was checked earlier.`);
|
||||
} else if ($ae_loc.allow_access && $ae_loc.key_checked) {
|
||||
console.log(`PASS: The access key was checked earlier and we just now checked the key.`);
|
||||
} else if (!$ae_loc.allow_access && $ae_loc.key_checked) {
|
||||
console.log(`FAIL: The access key was checked earlier and failed.`);
|
||||
if ($ae_loc.administrator_access) {
|
||||
console.log(`FAIL: The access key was checked earlier and failed, but we have administrator access.`);
|
||||
$ae_loc.allow_access = true;
|
||||
}
|
||||
} else {
|
||||
console.log(`FAIL: The access key was not checked earlier.`);
|
||||
// $ae_loc.key_checked = true;
|
||||
}
|
||||
|
||||
// $: access_key = data.url.searchParams.get('key');
|
||||
// console.log(`access_key = `, access_key);
|
||||
|
||||
if (browser) {
|
||||
// Waiting until the browser exists.
|
||||
if ($ae_loc && $ae_sess && $ae_loc.ver_idb != $ae_sess.ver_idb) {
|
||||
@@ -313,6 +332,8 @@ onMount(() => {
|
||||
}
|
||||
});
|
||||
|
||||
// console.log(`access_key = `, access_key);
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -376,8 +397,24 @@ onMount(() => {
|
||||
</svelte:fragment>
|
||||
|
||||
|
||||
<!-- Page Route Content -->
|
||||
<slot />
|
||||
<!-- !($ae_loc.site_access_key && $ae_loc.site_domain_access_key)
|
||||
|| ($ae_loc.site_access_key == access_key || $ae_loc.site_domain_access_key == access_key)} -->
|
||||
{#if
|
||||
$ae_loc.allow_access}
|
||||
|
||||
<!-- {$ae_loc?.site_access_key ?? '-- site access key not set --'} -->
|
||||
<!-- {$ae_loc?.site_domain_access_key ?? '-- site domain access key not set --'} -->
|
||||
<!-- {access_key ?? '-- param key not set --'} -->
|
||||
|
||||
<!-- Page Route Content -->
|
||||
<slot />
|
||||
|
||||
{:else}
|
||||
<div class="flex flex-col items-center justify-center h-screen">
|
||||
<h1 class="text-4xl font-bold text-red-500">Access Denied</h1>
|
||||
<p class="text-lg text-gray-500">You do not have access to this site.</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
|
||||
@@ -162,6 +162,31 @@ export async function load({ fetch, params, parent, route, url }) { // params, r
|
||||
ae_loc_init['site_google_tracking_id'] = site_domain_results.google_tracking_id;
|
||||
ae_loc_init['site_access_code_kv'] = site_domain_results.access_code_kv_json;
|
||||
ae_loc_init['site_cfg_json'] = site_domain_results.cfg_json;
|
||||
ae_loc_init['site_access_key'] = site_domain_results.access_key; // This is the general site access key
|
||||
ae_loc_init['site_domain_access_key'] = site_domain_results.site_domain_access_key; // This is specific to a (sub)domain.
|
||||
|
||||
if (!ae_loc_init['site_access_key'] && !ae_loc_init['site_domain_access_key']) {
|
||||
ae_loc_init['key_checked'] = true;
|
||||
ae_loc_init['allow_access'] = true; // No access key is required here.
|
||||
} else {
|
||||
let access_key = url.searchParams.get('key');
|
||||
console.log(`root layout.ts: access_key = `, access_key);
|
||||
if (access_key) {
|
||||
if (access_key == ae_loc_init['site_access_key']) {
|
||||
ae_loc_init['key_checked'] = ae_loc_init['site_access_key'];
|
||||
ae_loc_init['allow_access'] = ae_loc_init['site_access_key'];
|
||||
} else if (access_key == ae_loc_init['site_domain_access_key']) {
|
||||
ae_loc_init['key_checked'] = ae_loc_init['site_domain_access_key'];
|
||||
ae_loc_init['allow_access'] = ae_loc_init['site_domain_access_key'];
|
||||
} else {
|
||||
ae_loc_init['key_checked'] = true;
|
||||
ae_loc_init['allow_access'] = false;
|
||||
}
|
||||
} else {
|
||||
ae_loc_init['key_checked'] = true;
|
||||
// ae_loc_init['allow_access'] = false; // An access key is required at this point.
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`root layout.ts: Returning account_id = `, site_domain_results.account_id_random);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user