// /join: one email form for joining free and for signing in (a one-time link). Lands back on ?to= (the report that was locked). (function () { 'use strict'; var $ = WWI.$, q = new URLSearchParams(location.search); var to = q.get('to') || '/my'; if (!/^\/(?!\/)/.test(to)) to = '/my'; if (q.get('err')) $('msg').textContent = q.get('err'); $('hubBtn').href = '/sso/start?mode=go&to=' + encodeURIComponent(to); fetch('/api/config').then(function (r) { return r.json(); }).then(function (c) { if (c.member) { $('form').classList.add('hide'); $('msg').innerHTML = 'You are signed in. Continue'; } }); $('form').addEventListener('submit', function (e) { e.preventDefault(); $('go').disabled = true; $('msg').textContent = ''; WWI.post('/api/join', { email: $('email').value.trim(), optin: $('optin').checked, to: to }).then(function (j) { $('go').disabled = false; if (!j.ok) { $('msg').textContent = j.error || 'That did not work. Try again.'; return; } if (j.mailed) $('msg').textContent = 'Check your inbox: we sent a link that signs you in (or creates your free account). It works for 30 minutes.'; else if (j.testLink) $('msg').innerHTML = 'Staging test address: no email is sent. Open the sign-in link.'; else $('msg').textContent = j.note || 'No link was sent.'; }); }); })();