From fdf319eac9fd942d4480c6b245f13dd381c038d5 Mon Sep 17 00:00:00 2001 From: moepoi Date: Wed, 17 Nov 2021 15:32:44 +0700 Subject: [PATCH] Update mail module --- modules/mail.js | 8 ++++---- routes/api.js | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/modules/mail.js b/modules/mail.js index c8e968c..10d7c30 100644 --- a/modules/mail.js +++ b/modules/mail.js @@ -8,7 +8,7 @@ try { process.exit(0); } -function send(email, token) { +function send(to, subject, content) { var email = email; var token = token; var mail = nodemailer.createTransport({ @@ -25,9 +25,9 @@ function send(email, token) { }); var mailOptions = { from: config.mail.user, - to: email, - subject: "Account Verification - Nekoya", - html: `

Hello!!! Please click this link link to verify your account!!! Thanks!!!

` + to: to, + subject: subject, + html: content }; mail.sendMail(mailOptions, function (error, info) { if (error) { diff --git a/routes/api.js b/routes/api.js index bdbe3b7..0c52177 100644 --- a/routes/api.js +++ b/routes/api.js @@ -7,6 +7,14 @@ const mail = require('../modules/mail'); const saltRounds = 10; +let config; +try { + config = require('../config'); +} catch (e) { + console.log('No config file found'); + process.exit(0); +} + router.get('/getproducts', (req, res) => { const conn = db.connect(); conn.execute('SELECT * FROM `products`', [], function (err, results) { @@ -57,8 +65,7 @@ router.post('/register', async (req, res) => { 'message': 'Bad Request' }) } else { - var email = req.body.email; - conn.query('SELECT * FROM users WHERE email ="' + email + '"', function (err, result) { + conn.query('SELECT * FROM users WHERE email ="' + req.body.email + '"', function (err, result) { if (err) { res.status(400); res.json({ @@ -68,12 +75,14 @@ router.post('/register', async (req, res) => { if (result.length > 0) { var token = randtoken.generate(20); if (result[0].verify == 0) { - var sent = mail.send(email, token); + let subject = "Account Verification - Nekoya"; + let content = `

Hello!!! Please click this link link to verify your account!!! Thanks!!!

`; + var sent = mail.send(req.body.email, subject, content); if (sent != "0") { var data = { token: token, }; - conn.query('UPDATE users SET ? WHERE email ="' + email + '"', data, function (err, result) { + conn.query('UPDATE users SET ? WHERE email ="' + req.body.email + '"', data, function (err, result) { if (err) { res.status(400); res.json({