Fixed account email verification.

Ylian Saint-Hilaire committed Dec 10, 2020 at 03:25 UTC 8006428bc6a63b65cc3566060d601c4bb2953fc3
3 files changed +6 -6
meshmail.js
+2 -2
@@ -204,7 +204,7 @@ module.exports.CreateMeshMail = function (parent) {
204 };
205
206 // Send account check mail
207 - obj.sendAccountCheckMail = function (domain, username, email, language, loginkey) {
207 + obj.sendAccountCheckMail = function (domain, username, userid, email, language, loginkey) {
208 obj.checkEmail(email, function (checked) {
209 if (checked) {
210 parent.debug('email', "Sending email verification to " + email);
@@ -223,7 +223,7 @@ module.exports.CreateMeshMail = function (parent) {
223 // Set all the options.
224 var options = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral' };
225 if (loginkey != null) { options.urlargs1 = '?key=' + loginkey; options.urlargs2 = '&key=' + loginkey; } else { options.urlargs1 = ''; options.urlargs2 = ''; }
226 - options.cookie = obj.parent.encodeCookie({ u: domain.id + '/' + username.toLowerCase(), e: email, a: 1 }, obj.mailCookieEncryptionKey);
226 + options.cookie = obj.parent.encodeCookie({ u: userid, e: email, a: 1 }, obj.mailCookieEncryptionKey);
227
228 // Send the email
229 obj.pendingMails.push({ to: email, from: parent.config.smtp.from, subject: mailReplacements(template.htmlSubject, domain, options), text: mailReplacements(template.txt, domain, options), html: mailReplacements(template.html, domain, options) });
meshuser.js
+2 -2
@@ -1565,7 +1565,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1565 if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' changed email from ' + oldemail + ' to ' + user.email); }
1566
1567 // Send the verification email
1568 - if (parent.parent.mailserver != null) { parent.parent.mailserver.sendAccountCheckMail(domain, user.name, user.email, parent.getLanguageCodes(req)); }
1568 + if (parent.parent.mailserver != null) { parent.parent.mailserver.sendAccountCheckMail(domain, user.name, user._id, user.email, parent.getLanguageCodes(req)); }
1569 }
1570 });
1571 }
@@ -1585,7 +1585,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1585
1586 if ((parent.parent.mailserver != null) && (obj.user.email.toLowerCase() == command.email)) {
1587 // Send the verification email
1588 - parent.parent.mailserver.sendAccountCheckMail(domain, user.name, user.email, parent.getLanguageCodes(req));
1588 + parent.parent.mailserver.sendAccountCheckMail(domain, user.name, user._id, user.email, parent.getLanguageCodes(req));
1589 }
1590 break;
1591 }
webserver.js
+2 -2
@@ -1245,7 +1245,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
1245 obj.db.SetUser(user);
1246
1247 // Send the verification email
1248 - if ((obj.parent.mailserver != null) && (domain.auth != 'sspi') && (domain.auth != 'ldap') && (obj.common.validateEmail(user.email, 1, 256) == true)) { obj.parent.mailserver.sendAccountCheckMail(domain, user.name, user.email, obj.getLanguageCodes(req), req.query.key); }
1248 + if ((obj.parent.mailserver != null) && (domain.auth != 'sspi') && (domain.auth != 'ldap') && (obj.common.validateEmail(user.email, 1, 256) == true)) { obj.parent.mailserver.sendAccountCheckMail(domain, user.name, user._id, user.email, obj.getLanguageCodes(req), req.query.key); }
1249 }, 0);
1250 var event = { etype: 'user', userid: user._id, username: user.name, account: obj.CloneSafeUser(user), action: 'accountcreate', msg: 'Account created, email is ' + req.body.email, domain: domain.id };
1251 if (obj.db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to create the user. Another event will come.
@@ -1547,7 +1547,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
1547 }
1548
1549 // Send the verification email
1550 - obj.parent.mailserver.sendAccountCheckMail(domain, user.name, user.email, obj.getLanguageCodes(req), req.query.key);
1550 + obj.parent.mailserver.sendAccountCheckMail(domain, user.name, user._id, user.email, obj.getLanguageCodes(req), req.query.key);
1551
1552 // Send the response
1553 req.session.messageid = 2; // Email sent.