mirror of
https://gitlab.com/nekoya/web.git
synced 2024-12-22 14:35:01 +01:00
Update mail module
This commit is contained in:
parent
430eea9777
commit
fdf319eac9
2 changed files with 17 additions and 8 deletions
|
@ -8,7 +8,7 @@ try {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function send(email, token) {
|
function send(to, subject, content) {
|
||||||
var email = email;
|
var email = email;
|
||||||
var token = token;
|
var token = token;
|
||||||
var mail = nodemailer.createTransport({
|
var mail = nodemailer.createTransport({
|
||||||
|
@ -25,9 +25,9 @@ function send(email, token) {
|
||||||
});
|
});
|
||||||
var mailOptions = {
|
var mailOptions = {
|
||||||
from: config.mail.user,
|
from: config.mail.user,
|
||||||
to: email,
|
to: to,
|
||||||
subject: "Account Verification - Nekoya",
|
subject: subject,
|
||||||
html: `<p>Hello!!! Please click this link <a href="${config.host}/verify-email?token=${token}">link</a> to verify your account!!! Thanks!!!</p>`
|
html: content
|
||||||
};
|
};
|
||||||
mail.sendMail(mailOptions, function (error, info) {
|
mail.sendMail(mailOptions, function (error, info) {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
@ -7,6 +7,14 @@ const mail = require('../modules/mail');
|
||||||
|
|
||||||
const saltRounds = 10;
|
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) => {
|
router.get('/getproducts', (req, res) => {
|
||||||
const conn = db.connect();
|
const conn = db.connect();
|
||||||
conn.execute('SELECT * FROM `products`', [], function (err, results) {
|
conn.execute('SELECT * FROM `products`', [], function (err, results) {
|
||||||
|
@ -57,8 +65,7 @@ router.post('/register', async (req, res) => {
|
||||||
'message': 'Bad Request'
|
'message': 'Bad Request'
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
var email = req.body.email;
|
conn.query('SELECT * FROM users WHERE email ="' + req.body.email + '"', function (err, result) {
|
||||||
conn.query('SELECT * FROM users WHERE email ="' + email + '"', function (err, result) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(400);
|
res.status(400);
|
||||||
res.json({
|
res.json({
|
||||||
|
@ -68,12 +75,14 @@ router.post('/register', async (req, res) => {
|
||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
var token = randtoken.generate(20);
|
var token = randtoken.generate(20);
|
||||||
if (result[0].verify == 0) {
|
if (result[0].verify == 0) {
|
||||||
var sent = mail.send(email, token);
|
let subject = "Account Verification - Nekoya";
|
||||||
|
let content = `<p>Hello!!! Please click this link <a href="${config.host}/verify-email?token=${token}">link</a> to verify your account!!! Thanks!!!</p>`;
|
||||||
|
var sent = mail.send(req.body.email, subject, content);
|
||||||
if (sent != "0") {
|
if (sent != "0") {
|
||||||
var data = {
|
var data = {
|
||||||
token: token,
|
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) {
|
if (err) {
|
||||||
res.status(400);
|
res.status(400);
|
||||||
res.json({
|
res.json({
|
||||||
|
|
Loading…
Reference in a new issue