nearly works again :)
This commit is contained in:
parent
8a1e2f14e0
commit
96631d1369
|
@ -7,6 +7,10 @@
|
||||||
<script>document.body.hidden = true;</script>
|
<script>document.body.hidden = true;</script>
|
||||||
|
|
||||||
<div class="js-error" hidden>
|
<div class="js-error" hidden>
|
||||||
|
<h1>Invalid Magic Link</h1>
|
||||||
|
<div class="js-magic-link">'{{magic_link}}' isn't a valid magic link code.
|
||||||
|
<br>Links are only good for 5 minutes, so you gotta act fast.
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="js-magic" hidden>
|
<div class="js-magic" hidden>
|
||||||
|
@ -22,8 +26,3 @@
|
||||||
<script src="js/app.js"></script>
|
<script src="js/app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
res.send("<h1>Invalid Magic Link</h1>"
|
|
||||||
+ "<pre><code>'" + magic + "' isn't a valid link.\nLinks are only good for 5 minutes, so act fast.\n"
|
|
||||||
+ "(" + new Date(1000*((_auths[magic]||{}).dt||0)).toISOString() + ")</code></pre>\n"
|
|
||||||
);
|
|
||||||
|
|
|
@ -9,15 +9,21 @@ if (magic) {
|
||||||
, cors: true
|
, cors: true
|
||||||
}).then(function (resp) {
|
}).then(function (resp) {
|
||||||
return resp.json().then(function (json) {
|
return resp.json().then(function (json) {
|
||||||
|
if (json.error) {
|
||||||
|
document.querySelector('.js-error').hidden = false;
|
||||||
|
document.querySelector('.js-magic-link').innerText = magic;
|
||||||
|
return;
|
||||||
|
}
|
||||||
document.querySelector('body').hidden = false;
|
document.querySelector('body').hidden = false;
|
||||||
document.querySelector('js-magic').hidden = false;
|
document.querySelector('.js-magic').hidden = false;
|
||||||
document.querySelector('js-token-data').innerText = JSON.stringify(json, null, 2);
|
document.querySelector('.js-token-data').innerText = JSON.stringify(json, null, 2);
|
||||||
document.querySelector('js-new-href').href = json.domains[0];
|
document.querySelector('.js-new-href').href = json.domains[0];
|
||||||
document.querySelector('js-new-href').innerText = json.domains[0];
|
document.querySelector('.js-new-href').innerText = json.domains[0];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
document.querySelector('body').hidden = false;
|
document.querySelector('body').hidden = false;
|
||||||
|
document.querySelector('.js-error').hidden = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -74,7 +74,7 @@ module.exports.authenticate = function (opts) {
|
||||||
// TODO use global interval whenever the number of active links is high
|
// TODO use global interval whenever the number of active links is high
|
||||||
var t = setTimeout(function () {
|
var t = setTimeout(function () {
|
||||||
console.log("[Magic Link] Timeout for '" + auth.subject + "'");
|
console.log("[Magic Link] Timeout for '" + auth.subject + "'");
|
||||||
delete _auths[id];
|
delete _auths[auth.id];
|
||||||
var err = new Error("Login Failure: Magic Link was not clicked within 5 minutes");
|
var err = new Error("Login Failure: Magic Link was not clicked within 5 minutes");
|
||||||
err.code = 'E_LOGIN_TIMEOUT';
|
err.code = 'E_LOGIN_TIMEOUT';
|
||||||
reject();
|
reject();
|
||||||
|
@ -83,7 +83,7 @@ module.exports.authenticate = function (opts) {
|
||||||
function authorize() {
|
function authorize() {
|
||||||
console.log("mighty auth'n ranger!");
|
console.log("mighty auth'n ranger!");
|
||||||
clearTimeout(t);
|
clearTimeout(t);
|
||||||
delete _auths[id];
|
delete _auths[auth.id];
|
||||||
var hri = require('human-readable-ids').hri;
|
var hri = require('human-readable-ids').hri;
|
||||||
var hrname = hri.random() + '.' + state.config.sharedDomain;
|
var hrname = hri.random() + '.' + state.config.sharedDomain;
|
||||||
var jwt = require('jsonwebtoken');
|
var jwt = require('jsonwebtoken');
|
||||||
|
@ -92,7 +92,7 @@ module.exports.authenticate = function (opts) {
|
||||||
, ports: [ 1024 + Math.round(Math.random() * 6300) ]
|
, ports: [ 1024 + Math.round(Math.random() * 6300) ]
|
||||||
, aud: state.config.webminDomain
|
, aud: state.config.webminDomain
|
||||||
, iss: Math.round(Date.now() / 1000)
|
, iss: Math.round(Date.now() / 1000)
|
||||||
, id: id
|
, id: auth.id
|
||||||
, hostname: auth.hostname
|
, hostname: auth.hostname
|
||||||
};
|
};
|
||||||
tokenData.jwt = jwt.sign(tokenData, state.secret);
|
tokenData.jwt = jwt.sign(tokenData, state.secret);
|
||||||
|
@ -106,7 +106,7 @@ module.exports.authenticate = function (opts) {
|
||||||
return tokenData;
|
return tokenData;
|
||||||
}
|
}
|
||||||
|
|
||||||
_auths[id] = {
|
_auths[auth.id] = {
|
||||||
dt: Date.now()
|
dt: Date.now()
|
||||||
, resolve: authorize
|
, resolve: authorize
|
||||||
, reject: reject
|
, reject: reject
|
||||||
|
@ -139,7 +139,7 @@ app.get('/api/telebit.cloud/magic/:magic', function (req, res) {
|
||||||
console.log("DEBUG telebit.cloud magic");
|
console.log("DEBUG telebit.cloud magic");
|
||||||
var tokenData;
|
var tokenData;
|
||||||
var magic = req.params.magic || req.query.magic;
|
var magic = req.params.magic || req.query.magic;
|
||||||
console.log("DEBUG telebit.cloud magic 1a");
|
console.log("DEBUG telebit.cloud magic 1a", magic);
|
||||||
if (_auths[magic]) {
|
if (_auths[magic]) {
|
||||||
console.log("DEBUG telebit.cloud magic 1b");
|
console.log("DEBUG telebit.cloud magic 1b");
|
||||||
tokenData = _auths[magic].resolve();
|
tokenData = _auths[magic].resolve();
|
||||||
|
@ -147,7 +147,7 @@ app.get('/api/telebit.cloud/magic/:magic', function (req, res) {
|
||||||
res.send(tokenData);
|
res.send(tokenData);
|
||||||
} else {
|
} else {
|
||||||
console.log("DEBUG telebit.cloud magic 2");
|
console.log("DEBUG telebit.cloud magic 2");
|
||||||
res.send({ error: { code: "E_TOKEN", message: "Invalid or expired magic link." } });
|
res.send({ error: { code: "E_TOKEN", message: "Invalid or expired magic link. (" + magic + ")" } });
|
||||||
console.log("DEBUG telebit.cloud magic 2b");
|
console.log("DEBUG telebit.cloud magic 2b");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue