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 = ` -
If this was sent to you incorrectly, please ignore.
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.