Now with ability to email license sign in link
This commit is contained in:
@@ -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 = `
|
||||
<div>${$event_exhibit_obj?.license_li_json[license_key].full_name},
|
||||
<div>${$event_exhibit_obj?.license_li_json[index].full_name},
|
||||
<p>If this was sent to you incorrectly, please ignore.</p>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div>
|
||||
Exhibit ID: ${$events_slct.exhibit_id}<br>
|
||||
<p>Use your license key sign in link below.<br>
|
||||
Copy and paste link: <a href="${data.url.origin}/events_leads/exhibit/${$events_slct.exhibit_id}?license_key=${license_key}">${data.url.origin}/events_leads/exhibit/${$events_slct.exhibit_id}?license_key=${license_key}&event_id=${$events_slct.event_id}</a></p>
|
||||
<p>If the email or passcode for your exhibit is changed, this link will no longer work.</p>
|
||||
<p>Exhibit: ${$event_exhibit_obj?.name}<br>
|
||||
Exhibit ID: ${$events_slct.exhibit_id}</p>
|
||||
|
||||
<p>Use the link below to sign in using your leads license.<br>
|
||||
Copy and paste link: <a href="${sign_in_url}">${sign_in_url}</a></p>
|
||||
<p>If the email or passcode for your license is changed, this link will no longer work.</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
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}) {
|
||||
<h2 class="h3">
|
||||
<!-- {$events_slct.exhibit_obj.name} -->
|
||||
<strong>{$event_exhibit_obj?.name ?? 'Welcome to Leads for Exhibits!'}</strong>
|
||||
<strong>{$event_exhibit_obj?.code ?? ''}</strong>
|
||||
<strong># {$event_exhibit_obj?.code ?? ''}</strong>
|
||||
</h2>
|
||||
<h3 class="h4">
|
||||
{#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}`}
|
||||
>
|
||||
<span class="fas fa-envelope mx-1"></span>
|
||||
Email
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
use:clipboard={$events_slct.exhibit_obj.url}
|
||||
use:clipboard={encodeURI(`${data.url.origin}/events_leads/exhibit/${$events_slct.exhibit_id}?key=${license.email}&pass=${license.passcode}`)}
|
||||
class="btn btn-sm text-sm variant-soft-tertiary"
|
||||
class:hidden={!$ae_loc.trusted_access || !$events_loc.show_details}
|
||||
title={`Copy link to this exhibit (ID: ${$events_slct.exhibit_id})`}
|
||||
|
||||
Reference in New Issue
Block a user