daveappserver 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/appserver.js +60 -40
- package/package.json +1 -1
package/appserver.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var myVersion = "0.6.
|
|
1
|
+
var myVersion = "0.6.2", myProductName = "daveAppServer";
|
|
2
2
|
|
|
3
3
|
exports.start = startup;
|
|
4
4
|
exports.notifySocketSubscribers = notifySocketSubscribers;
|
|
@@ -934,61 +934,80 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
934
934
|
});
|
|
935
935
|
}
|
|
936
936
|
//email registration -- 12/7/22 by DW
|
|
937
|
-
function sendConfirmingEmail (email, screenname, callback) {
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
};
|
|
948
|
-
stats.pendingConfirmations.push (obj);
|
|
949
|
-
statsChanged ();
|
|
950
|
-
console.log ("sendConfirmingEmail: obj == " + utils.jsonStringify (obj));
|
|
951
|
-
var params = {
|
|
952
|
-
title: config.confirmEmailSubject,
|
|
953
|
-
operationToConfirm: config.operationToConfirm,
|
|
954
|
-
confirmationUrl: urlWebApp + "userconfirms?emailConfirmCode=" + encodeURIComponent (magicString)
|
|
955
|
-
};
|
|
956
|
-
fs.readFile (config.fnameEmailTemplate, function (err, emailTemplate) {
|
|
937
|
+
function sendConfirmingEmail (email, screenname, flNewUser=false, callback) {
|
|
938
|
+
function getScreenname (callback) {
|
|
939
|
+
if (flNewUser) { //the caller had to provide it
|
|
940
|
+
callback (undefined, screenname);
|
|
941
|
+
}
|
|
942
|
+
else { //we have to look it up
|
|
943
|
+
config.getScreenNameFromEmail (email, callback);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
getScreenname (function (err, screenname) {
|
|
957
947
|
if (err) {
|
|
958
|
-
|
|
959
|
-
console.log ("sendConfirmingEmail: err.message == " + err.message);
|
|
960
|
-
callback ({message});
|
|
948
|
+
callback (err);
|
|
961
949
|
}
|
|
962
950
|
else {
|
|
963
|
-
|
|
964
|
-
|
|
951
|
+
const magicString = utils.getRandomPassword (10);
|
|
952
|
+
const urlWebApp = "http://" + config.myDomain + "/";
|
|
953
|
+
console.log ("sendConfirmingEmail: email == " + email + ", urlWebApp == " + urlWebApp);
|
|
954
|
+
var obj = {
|
|
955
|
+
magicString: magicString,
|
|
956
|
+
email: email,
|
|
957
|
+
flDeleted: false,
|
|
958
|
+
screenname,
|
|
959
|
+
flNewUser, //1/7/23 by DW
|
|
960
|
+
when: new Date ()
|
|
961
|
+
};
|
|
962
|
+
stats.pendingConfirmations.push (obj);
|
|
963
|
+
statsChanged ();
|
|
964
|
+
console.log ("sendConfirmingEmail: obj == " + utils.jsonStringify (obj));
|
|
965
|
+
var params = {
|
|
966
|
+
title: config.confirmEmailSubject,
|
|
967
|
+
operationToConfirm: config.operationToConfirm,
|
|
968
|
+
confirmationUrl: urlWebApp + "userconfirms?emailConfirmCode=" + encodeURIComponent (magicString)
|
|
969
|
+
};
|
|
970
|
+
fs.readFile (config.fnameEmailTemplate, function (err, emailTemplate) {
|
|
965
971
|
if (err) {
|
|
966
|
-
|
|
972
|
+
const message = "Error reading email template.";
|
|
973
|
+
console.log ("sendConfirmingEmail: err.message == " + err.message);
|
|
974
|
+
callback ({message});
|
|
967
975
|
}
|
|
968
976
|
else {
|
|
969
|
-
|
|
977
|
+
var mailtext = utils.multipleReplaceAll (emailTemplate.toString (), params, false, "[%", "%]");
|
|
978
|
+
mail.send (email, params.title, mailtext, config.mailSender, function (err, data) {
|
|
979
|
+
if (err) {
|
|
980
|
+
callback (err);
|
|
981
|
+
}
|
|
982
|
+
else {
|
|
983
|
+
callback (undefined, {message: "Please check your email."});
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
const f = config.dataFolder + "lastmail.html";
|
|
987
|
+
utils.sureFilePath (f, function () {
|
|
988
|
+
fs.writeFile (f, mailtext, function (err) {
|
|
989
|
+
});
|
|
990
|
+
});
|
|
970
991
|
}
|
|
971
992
|
});
|
|
972
|
-
const f = config.dataFolder + "lastmail.html";
|
|
973
|
-
utils.sureFilePath (f, function () {
|
|
974
|
-
fs.writeFile (f, mailtext, function (err) {
|
|
975
|
-
});
|
|
976
|
-
});
|
|
977
993
|
}
|
|
978
994
|
});
|
|
979
995
|
}
|
|
980
996
|
function receiveConfirmation (emailConfirmCode, callback) {
|
|
981
997
|
const urlWebApp = "http://" + config.myDomain + "/";
|
|
982
998
|
var urlRedirect = undefined, flFoundConfirm = false;
|
|
999
|
+
function encode (s) {
|
|
1000
|
+
return (encodeURIComponent (s));
|
|
1001
|
+
}
|
|
983
1002
|
stats.pendingConfirmations.forEach (function (item) {
|
|
984
1003
|
if (item.magicString == emailConfirmCode) {
|
|
985
1004
|
if (config.addEmailToUserInDatabase !== undefined) {
|
|
986
|
-
config.addEmailToUserInDatabase (item.screenname, item.email, item.magicString, function (err, emailSecret) {
|
|
1005
|
+
config.addEmailToUserInDatabase (item.screenname, item.email, item.magicString, item.flNewUser, function (err, emailSecret) {
|
|
987
1006
|
if (err) {
|
|
988
|
-
urlRedirect = urlWebApp + "?failedLogin=true&message=" +
|
|
1007
|
+
urlRedirect = urlWebApp + "?failedLogin=true&message=" + encode (err.message);
|
|
989
1008
|
}
|
|
990
1009
|
else {
|
|
991
|
-
urlRedirect = urlWebApp + "?emailconfirmed=true&email=" + item.email + "&code=" +
|
|
1010
|
+
urlRedirect = urlWebApp + "?emailconfirmed=true&email=" + item.email + "&code=" + encode (emailSecret) + "&screenname=" + encode (item.screenname);
|
|
992
1011
|
item.flDeleted = true;
|
|
993
1012
|
}
|
|
994
1013
|
callback (urlRedirect);
|
|
@@ -999,7 +1018,7 @@ function cleanFileStats (stats) { //4/19/21 by DW
|
|
|
999
1018
|
});
|
|
1000
1019
|
if (!flFoundConfirm) {
|
|
1001
1020
|
if (urlRedirect === undefined) {
|
|
1002
|
-
urlRedirect = urlWebApp + "?failedLogin=true&message=" +
|
|
1021
|
+
urlRedirect = urlWebApp + "?failedLogin=true&message=" + encode ("Can't find the pending confirmation.");
|
|
1003
1022
|
}
|
|
1004
1023
|
callback (urlRedirect);
|
|
1005
1024
|
}
|
|
@@ -1379,9 +1398,10 @@ function startup (options, callback) {
|
|
|
1379
1398
|
});
|
|
1380
1399
|
return (true);
|
|
1381
1400
|
case "/sendconfirmingemail": //12/7/22 by DW
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1401
|
+
sendConfirmingEmail (params.email, undefined, false, httpReturn);
|
|
1402
|
+
return (true);
|
|
1403
|
+
case "/createnewuser": //1/7/23 by DW
|
|
1404
|
+
sendConfirmingEmail (params.email, params.name, true, httpReturn);
|
|
1385
1405
|
return (true);
|
|
1386
1406
|
case "/userconfirms": //12/7/22 by DW
|
|
1387
1407
|
receiveConfirmation (params.emailConfirmCode, httpReturnRedirect);
|