From 08833123b2ce7a9fc4f7a55e4a34ab81d36f7956 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 8 Jun 2018 08:23:05 +0000 Subject: [PATCH] update messaging --- lib/extensions.js | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/lib/extensions.js b/lib/extensions.js index 682f3cf..1c73032 100644 --- a/lib/extensions.js +++ b/lib/extensions.js @@ -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 ' , 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:
" + + '
' + + '       Confirm Device
' + + '       https://www.telebit.cloud/login/?magic=' + id + '
' + + '
' + + "(" + auth.os_arch + " " + auth.os_platform + " " + auth.os_release + ")
" + + '
' } }).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("

Your device is authorized for the following:

" + JSON.stringify(tokenData, null, 2) + "
"); + res.send('' + + '' + + '' + + '

Redirecting to your new domain...

' + + '' + + tokenData.domains[0] + + '' + + '
' + + '
' + + '
' + JSON.stringify(tokenData, null, 2) + '
' + + '' + ); } else { res.send("

Invalid Magic Link

" + "
'" + magic + "' isn't a valid link.\nLinks are only good for 5 minutes, so act fast.\n"