update messaging

This commit is contained in:
AJ ONeal 2018-06-08 08:23:05 +00:00
parent 4b44632f2e
commit 08833123b2
1 changed files with 34 additions and 5 deletions

View File

@ -7,6 +7,7 @@ curl -s --user 'api:YOUR_API_KEY' \
-F subject='Hello' \
-F text='Testing some Mailgun awesomeness!'
*/
var fs = require('fs');
var _auths = module.exports._auths = {};
module.exports.authenticate = function (opts) {
console.log("It's auth'n time!");
@ -34,15 +35,30 @@ module.exports.authenticate = function (opts) {
, formData: {
from: 'Telebit Wizard <wizard@telebit.cloud>'
, to: auth.subject
, subject: 'Telebit: Magic Link Login'
, text: "Here's your magic login link. Just click to confirm your login attempt:\n\n"
+ ' https://www.telebit.cloud/login/?magic=' + id + '\n\n'
+ "The login request came from '" + auth.hostname + "'\n "
, subject: 'Confirm New Device Connection'
, text: "You tried connecting with '" + auth.hostname + "' for the first time. Confirm to continue connecting:\n"
+ '\n'
+ ' https://www.telebit.cloud/login/?magic=' + id + '\n'
+ '\n'
+ "(" + auth.os_arch + " " + auth.os_platform + " " + auth.os_release + ")\n"
+ '\n'
, html: "You tried connecting with '" + auth.hostname + "' for the first time. Confirm to continue connecting:<br>"
+ '<br>'
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://www.telebit.cloud/login/?magic=' + id + '">Confirm Device</a><br>'
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; https://www.telebit.cloud/login/?magic=' + id + '<br>'
+ '<br>'
+ "(" + auth.os_arch + " " + auth.os_platform + " " + auth.os_release + ")<br>"
+ '<br>'
}
}).then(function (resp) {
console.log("[DEBUG] email was sent, or so they say");
console.log(resp.body);
fs.writeFile(path.join(__dirname, 'emails', auth.subject), JSON.stringify(auth), function (err) {
if (err) {
console.error('[ERROR] in writing auth details');
console.error(err);
}
});
return new state.Promise(function (resolve, reject) {
// TODO use global interval whenever the number of active links is high
var t = setTimeout(function () {
@ -102,7 +118,20 @@ app.use('/login', function (req, res) {
var magic = req.query.magic;
if (_auths[magic]) {
tokenData = _auths[magic].resolve();
res.send("<h1>Your device is authorized for the following:</h1><pre><code>" + JSON.stringify(tokenData, null, 2) + "</code></pre>");
res.send('<!DOCTYPE html><html>'
+ '<head><meta http-equiv="refresh" content="5;url='
+ 'https://' + tokenData.domains.join(',') + '/?serviceport=' + tokenData.ports.join(',')
+ '" /></head>'
+ '<body>'
+ '<h1>Redirecting to your new domain...</h1>'
+ '<a href="https://' + tokenData.domains[0] + '">'
+ tokenData.domains[0]
+ '</a>'
+ '<br>'
+ '<br>'
+ '<small><pre><code>' + JSON.stringify(tokenData, null, 2) + '</code></pre></small>'
+ '</body></html>'
);
} else {
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"