update messaging
This commit is contained in:
parent
4b44632f2e
commit
08833123b2
|
@ -7,6 +7,7 @@ curl -s --user 'api:YOUR_API_KEY' \
|
||||||
-F subject='Hello' \
|
-F subject='Hello' \
|
||||||
-F text='Testing some Mailgun awesomeness!'
|
-F text='Testing some Mailgun awesomeness!'
|
||||||
*/
|
*/
|
||||||
|
var fs = require('fs');
|
||||||
var _auths = module.exports._auths = {};
|
var _auths = module.exports._auths = {};
|
||||||
module.exports.authenticate = function (opts) {
|
module.exports.authenticate = function (opts) {
|
||||||
console.log("It's auth'n time!");
|
console.log("It's auth'n time!");
|
||||||
|
@ -34,15 +35,30 @@ module.exports.authenticate = function (opts) {
|
||||||
, formData: {
|
, formData: {
|
||||||
from: 'Telebit Wizard <wizard@telebit.cloud>'
|
from: 'Telebit Wizard <wizard@telebit.cloud>'
|
||||||
, to: auth.subject
|
, to: auth.subject
|
||||||
, subject: 'Telebit: Magic Link Login'
|
, subject: 'Confirm New Device Connection'
|
||||||
, text: "Here's your magic login link. Just click to confirm your login attempt:\n\n"
|
, text: "You tried connecting with '" + auth.hostname + "' for the first time. Confirm to continue connecting:\n"
|
||||||
+ ' https://www.telebit.cloud/login/?magic=' + id + '\n\n'
|
+ '\n'
|
||||||
+ "The login request came from '" + auth.hostname + "'\n "
|
+ ' https://www.telebit.cloud/login/?magic=' + id + '\n'
|
||||||
|
+ '\n'
|
||||||
+ "(" + auth.os_arch + " " + auth.os_platform + " " + auth.os_release + ")\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>'
|
||||||
|
+ ' <a href="https://www.telebit.cloud/login/?magic=' + id + '">Confirm Device</a><br>'
|
||||||
|
+ ' https://www.telebit.cloud/login/?magic=' + id + '<br>'
|
||||||
|
+ '<br>'
|
||||||
|
+ "(" + auth.os_arch + " " + auth.os_platform + " " + auth.os_release + ")<br>"
|
||||||
|
+ '<br>'
|
||||||
}
|
}
|
||||||
}).then(function (resp) {
|
}).then(function (resp) {
|
||||||
console.log("[DEBUG] email was sent, or so they say");
|
console.log("[DEBUG] email was sent, or so they say");
|
||||||
console.log(resp.body);
|
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) {
|
return new state.Promise(function (resolve, reject) {
|
||||||
// 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 () {
|
||||||
|
@ -102,7 +118,20 @@ app.use('/login', function (req, res) {
|
||||||
var magic = req.query.magic;
|
var magic = req.query.magic;
|
||||||
if (_auths[magic]) {
|
if (_auths[magic]) {
|
||||||
tokenData = _auths[magic].resolve();
|
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 {
|
} else {
|
||||||
res.send("<h1>Invalid Magic Link</h1>"
|
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"
|
+ "<pre><code>'" + magic + "' isn't a valid link.\nLinks are only good for 5 minutes, so act fast.\n"
|
||||||
|
|
Loading…
Reference in New Issue