From 2b1b2b7d0713bb4f361fe537cd7a5a1ab08d6ed8 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 28 Mar 2024 18:55:31 -0400 Subject: [PATCH] Now with ability to email license sign in link --- src/lib/ae_events_stores.ts | 2 +- .../events_leads/exhibit/[slug]/+page.svelte | 80 +++++++++++++++---- .../exhibit/[slug]/leads_manage.svelte | 5 ++ .../exhibit/[slug]/leads_view_lead.svelte | 4 + 4 files changed, 76 insertions(+), 15 deletions(-) diff --git a/src/lib/ae_events_stores.ts b/src/lib/ae_events_stores.ts index 8888f477..d6de7b21 100644 --- a/src/lib/ae_events_stores.ts +++ b/src/lib/ae_events_stores.ts @@ -151,7 +151,7 @@ let events_session_data_struct: key_val = { entered_search_str: null, - lead_data_changed: false, + lead_data_changed: null, qr_scan_start: true, qr_scan_result: null, diff --git a/src/routes/events_leads/exhibit/[slug]/+page.svelte b/src/routes/events_leads/exhibit/[slug]/+page.svelte index a3fa3859..731d359e 100644 --- a/src/routes/events_leads/exhibit/[slug]/+page.svelte +++ b/src/routes/events_leads/exhibit/[slug]/+page.svelte @@ -103,6 +103,51 @@ onMount(() => { goto(new_url, {replaceState: true}); } + // Look for a license key (email address) and passcode in the URL params. The email address may have had a plus symbol and replaced with a space. (example: test+more@example.com) This needs to be fixed. + let url_lic_key = data.url.searchParams.get('key'); + let url_lic_pass = data.url.searchParams.get('pass'); + if (url_lic_key && url_lic_pass) { + // Replace the space with a plus symbol. + url_lic_key = url_lic_key.replace(/ /g, '+'); + + console.log(`ae_events_leads exhibit [slug] +page.svelte: event_exhibit_id=${$events_slct.exhibit_id}; key=${url_lic_key}; pass=${url_lic_pass}`); + + // Check the license key and passcode against the event exhibit object. + console.log($events_slct.exhibit_obj.license_li_json); + // We need to loop through the $events_slct.exhibit_obj.license_li_json list/array and check if the "email" and "passcode" matches. + if ($events_slct.exhibit_obj.license_li_json && $events_slct.exhibit_obj.license_li_json.length) { + for (let i = 0; i < $events_slct.exhibit_obj.license_li_json.length; i++) { + console.log(`${i} License email: ${$events_slct.exhibit_obj.license_li_json[i].email}; License passcode: ${$events_slct.exhibit_obj.license_li_json[i].passcode}`); + + if ($events_slct.exhibit_obj.license_li_json[i].email == url_lic_key && $events_slct.exhibit_obj.license_li_json[i].passcode == url_lic_pass) { + console.log('License key passcode matched'); + $events_loc.leads.auth_exhibit_kv[$events_slct.exhibit_id] = { + key: url_lic_key, + updated_on: new Date().toISOString() + }; + data.url.searchParams.delete('key'); + data.url.searchParams.delete('pass'); + let new_url = data.url.toString() + console.log(new_url); + goto(new_url, {replaceState: true}); + } else { + console.log('License key passcode does not match'); + } + } + + } + // if ($events_slct.exhibit_obj.license_li_json[url_lic_key] && $events_slct.exhibit_obj.license_li_json[url_lic_key].passcode == url_lic_pass) { + // console.log('License key passcode matched'); + // $events_loc.leads.auth_exhibit_kv[$events_slct.exhibit_id] = { + // key: url_lic_key, + // updated_on: new Date().toISOString() + // }; + // } else { + // console.log('License key passcode does not match'); + // return false; + // } + } + // // We need to remove the url_passcode from the URL GET params after we use it. It should be safe to assume that onMount is a safe place to do this. // if (url_passcode) { // // console.log('Remove the passcode from the URL.'); @@ -383,32 +428,36 @@ async function handle_update__exhibit({ -function send_init_confirm_email({to_email}) { - console.log(`*** send_init_confirm_email() *** to ${to_email}.`); +function send_init_confirm_email({index, lic_key, lic_pass}) { + console.log(`*** send_init_confirm_email() *** to ${lic_key}.`); - let license_key = to_email; + let to_email = lic_key; + + let sign_in_url = encodeURI(`${data.url.origin}/events_leads/exhibit/${$events_slct.exhibit_id}?key=${lic_key}&pass=${lic_pass}`); let subject = `Leads License Link for ${$event_exhibit_obj?.name} (ID: ${$events_slct.exhibit_id})`; let body_html = ` -
${$event_exhibit_obj?.license_li_json[license_key].full_name}, +
${$event_exhibit_obj?.license_li_json[index].full_name},

If this was sent to you incorrectly, please ignore.


- Exhibit ID: ${$events_slct.exhibit_id}
-

Use your license key sign in link below.
- Copy and paste link: ${data.url.origin}/events_leads/exhibit/${$events_slct.exhibit_id}?license_key=${license_key}&event_id=${$events_slct.event_id}

-

If the email or passcode for your exhibit is changed, this link will no longer work.

+

Exhibit: ${$event_exhibit_obj?.name}
+ Exhibit ID: ${$events_slct.exhibit_id}

+ +

Use the link below to sign in using your leads license.
+ Copy and paste link: ${sign_in_url}

+

If the email or passcode for your license is changed, this link will no longer work.

`; api.send_email({ api_cfg: $ae_api, from_email: 'noreply+leads@oneskyit.com', - from_name: 'OSIT Events - Leads', + from_name: 'OSIT Exhibit Leads', to_email: to_email, subject: subject, body_html: body_html, @@ -561,7 +610,7 @@ function send_init_confirm_email({to_email}) {

{$event_exhibit_obj?.name ?? 'Welcome to Leads for Exhibits!'} - {$event_exhibit_obj?.code ?? ''} + # {$event_exhibit_obj?.code ?? ''}

{#if $events_loc.leads.auth_exhibit_kv[$events_slct.exhibit_id] && $events_loc.leads.auth_exhibit_kv[$events_slct.exhibit_id].key} @@ -742,18 +791,21 @@ function send_init_confirm_email({to_email}) { on:click={() => { console.log('Send Email'); // Send an email with the login link - send_init_confirm_email({ to_email: license.email }); + if (confirm(`Are you sure you want to send an email with the login link to ${license.email}?`)) { + send_init_confirm_email({ index: index, lic_key: license.email, lic_pass: license.passcode}); + } + // send_init_confirm_email({ index: index, lic_key: license.email, lic_pass: license.passcode}); }} - disabled={!$ae_loc.trusted_access} + disabled={!$ae_loc.trusted_access && 2==4} class="btn btn-sm text-sm variant-soft-secondary" - title={`TEMPORARILY DISABLED: Send an email with the license login link to ${license.email}`} + title={`Send an email with the license login link to ${license.email}`} > Email

+