mirror of
https://github.com/sergeyyarkov/digital-store.git
synced 2026-10-11 10:19:15 +03:00
nodemailer
This commit is contained in:
parent
0d4c9cfcb7
commit
83a176543d
@ -11,4 +11,6 @@ SESSION_SECRET=secret
|
||||
DATABASE_URI=подключение к БД MONGODB
|
||||
DATABASE_NAME=имя БД
|
||||
QIWI_SECRET_KEY=секретный ключ QIWI API
|
||||
EMAIL_LOGIN=логин от почты
|
||||
EMAIL_PASSWORD=пароль от почты
|
||||
```
|
||||
13
config/nodemailer.config.js
Normal file
13
config/nodemailer.config.js
Normal file
@ -0,0 +1,13 @@
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
module.exports = {
|
||||
transporter: nodemailer.createTransport({
|
||||
host: "smtp.mail.ru",
|
||||
port: 465,
|
||||
secure: true, // true for 465, false for other ports
|
||||
auth: {
|
||||
user: process.env.EMAIL_LOGIN, // email login
|
||||
pass: process.env.EMAIL_PASSWORD // email password
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
const ObjectID = require('mongodb').ObjectID;
|
||||
const nodemailer = require('../nodemailer.config');
|
||||
|
||||
module.exports = function(server, db, qiwiApi) {
|
||||
server.get('/success', (req, res) => {
|
||||
@ -15,13 +16,13 @@ module.exports = function(server, db, qiwiApi) {
|
||||
amount = parseFloat(data.amount.value);
|
||||
|
||||
if (status === 'PAID') {
|
||||
const ids = query.item_id.split('and');
|
||||
const findBill = await db.collection('buyers').findOne({bill_id: query.bill_id});
|
||||
const ids = query.item_id.split('and'),
|
||||
findBill = await db.collection('buyers').findOne({bill_id: query.bill_id});
|
||||
|
||||
if(findBill == null) {
|
||||
const result = [];
|
||||
|
||||
//выдаем данные и создаем покупателя
|
||||
// создаем покупателя и выдаем данные
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
const item = await db.collection('info').findOne({"_id": ObjectID(ids[i])}),
|
||||
data = item.data;
|
||||
@ -29,8 +30,19 @@ module.exports = function(server, db, qiwiApi) {
|
||||
result.push(data.splice(-1, 1).join(''));
|
||||
db.collection('info').updateOne({"_id": ObjectID(ids[i])}, {$set: {data: data}});
|
||||
}
|
||||
|
||||
db.collection('buyers').insertOne({bill_id, email, method, date, amount, data: result});
|
||||
|
||||
await nodemailer.transporter.sendMail({
|
||||
from: `"Оплата аккаунта." <${process.env.EMAIL_LOGIN}>`, // sender address
|
||||
to: email, // list of receivers
|
||||
subject: "Оплата успешно проведена.", // subject
|
||||
text: "Данные купленного товара находятся в этом письме.", // plain text body
|
||||
html: `<b>Номер заказа: ${bill_id}</b><br>
|
||||
<b>Данные товара:</b><br>
|
||||
<p>${result.join('<br>')}</p>
|
||||
` // html body
|
||||
});
|
||||
|
||||
res.render('main/success', {result, email});
|
||||
} else {
|
||||
res.send('Этот заказ уже был оплачен. Данные были высланы покупателю.');
|
||||
@ -41,7 +53,8 @@ module.exports = function(server, db, qiwiApi) {
|
||||
res.send('Время жизни счета истекло. Счет не оплачен');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
res.render('main/404');
|
||||
});
|
||||
} else {
|
||||
|
||||
5
package-lock.json
generated
5
package-lock.json
generated
@ -5474,6 +5474,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"nodemailer": {
|
||||
"version": "6.4.2",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.4.2.tgz",
|
||||
"integrity": "sha512-g0n4nH1ONGvqYo1v72uSWvF/MRNnnq1LzmSzXb/6EPF3LFb51akOhgG3K2+aETAsJx90/Q5eFNTntu4vBCwyQQ=="
|
||||
},
|
||||
"nodemon": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.2.tgz",
|
||||
|
||||
@ -32,6 +32,7 @@
|
||||
"method-override": "^3.0.0",
|
||||
"mongodb": "^3.3.4",
|
||||
"multer": "^1.4.2",
|
||||
"nodemailer": "^6.4.2",
|
||||
"passport": "^0.4.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"pug": "^2.0.4",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user