TODO: replaced sendmail by nodemailer to allow using a proper & authenticated smtp endpoint.

pull/4/head
Florian Brede 2021-05-23 02:18:11 +02:00
parent b9cf8e26d9
commit a5871a9783
3 changed files with 32 additions and 8 deletions

View File

@ -13,6 +13,12 @@ var config = {
sslKey: 'certs/retropilot.key',
sslCrt: 'certs/retropilot.crt',
smtpHost: "localhost",
smtpPort: 25,
smtpUser: "root",
smtpPassword: "",
smtpFrom: "no-reply@retropilot.org",
baseUrl: 'http://192.168.1.165:3000/', // base url of the retropilot server
baseUploadUrl: 'http://192.168.1.165:3000/backend/post_upload', // base url sent to devices for POSTing drives & logs
baseDriveDownloadUrl: 'http://192.168.1.165:3000/realdata/', // base download url for drive & log data

View File

@ -29,8 +29,8 @@
"log4js": "^6.3.0",
"mocha": "^8.4.0",
"multer": "^1.4.2",
"nodemailer": "^6.6.0",
"proper-lockfile": "^4.1.2",
"sendmail": "^1.6.1",
"sqlite": "^4.0.22",
"sqlite3": "^5.0.2",
"supertest": "^6.1.3"

View File

@ -1,7 +1,7 @@
const router = require('express').Router();
const bodyParser = require('body-parser');
const crypto = require('crypto');
const sendmail = require('sendmail')({silent: false});
const nodemailer = require('nodemailer');
const htmlspecialchars = require('htmlspecialchars');
const dirTree = require("directory-tree");
const cookieParser = require('cookie-parser');
@ -107,15 +107,33 @@ router.post('/useradmin/register/token', bodyParser.urlencoded({extended: true})
logger.info("USERADMIN REGISTRATION sending token to " + htmlspecialchars(email.trim()) + ": \"" + token + "\"");
infoText = 'Please check your inbox (<b>SPAM</b>) for an email with the registration token.<br>If the token was not delivered, please ask the administrator to check the <i>server.log</i> for the token generated for your email.<br><br>';
sendmail({
from: 'no-reply@retropilot.com',
let transporter = nodemailer.createTransport(
{
host: config.smtpHost,
port: config.smtpPort,
auth: {
user: config.smtpUser,
pass: config.smtpPassword
},
logger: true,
debug: false
},
{from: config.smtpFrom}
);
let message = {
from: config.smtpFrom,
to: email.trim(),
subject: 'RetroPilot Registration Token',
html: 'Your Email Registration Token Is: "' + token + '"',
}, function (err, reply) {
if (err)
logger.error("USERADMIN REGISTRATION - failed to send registration token email " + (err && err.stack) + " " + reply);
text: 'Your Email Registration Token Is: "' + token + '"'
};
transporter.sendMail(message, (error, info) => {
if (error) {
logger.error(error.message);
}
});
} else { // final registration form filled
if (req.body.token != token) {
infoText = 'The registration token you entered was incorrect, please try again.<br><br>';