-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed email bug and Added forgotpassword route to landing page login …
…portal
- Loading branch information
stryder2000
committed
Apr 8, 2021
1 parent
252c382
commit 8300520
Showing
17 changed files
with
1,703 additions
and
549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ const stripe = require('stripe')( | |
const Tour = require('../dev-data/models/tourModel'); | ||
const User = require('../dev-data/models/userModel'); | ||
const Booking = require('../dev-data/models/bookingModel'); | ||
|
||
const Email = require('./../utils/email'); | ||
const factory = require('./handlerFactory'); | ||
const catchAsync = require('../utils/catchAsync'); | ||
|
||
|
@@ -63,6 +63,7 @@ exports.webhookCheckout = async (req, res, next) => { | |
const tour = session.client_reference_id; | ||
const user = (await User.findOne({ email: session.customer_email })).id; | ||
const price = session.display_items[0].amount / 100; | ||
await new Email(user, '[email protected]').sendBookingSuccessful(); | ||
await Booking.create({ tour, user, price }); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ var User = require('../dev-data/models/userModel'); | |
|
||
var Booking = require('../dev-data/models/bookingModel'); | ||
|
||
var Email = require('./../utils/email'); | ||
|
||
var factory = require('./handlerFactory'); | ||
|
||
var catchAsync = require('../utils/catchAsync'); | ||
|
@@ -78,7 +80,7 @@ exports.webhookCheckout = function _callee2(req, res, next) { | |
|
||
case 8: | ||
if (!(event.type === 'checkout.session.completed')) { | ||
_context2.next = 17; | ||
_context2.next = 19; | ||
break; | ||
} | ||
|
||
|
@@ -93,18 +95,22 @@ exports.webhookCheckout = function _callee2(req, res, next) { | |
user = _context2.sent.id; | ||
price = session.display_items[0].amount / 100; | ||
_context2.next = 17; | ||
return regeneratorRuntime.awrap(new Email(user, '[email protected]').sendBookingSuccessful()); | ||
|
||
case 17: | ||
_context2.next = 19; | ||
return regeneratorRuntime.awrap(Booking.create({ | ||
tour: tour, | ||
user: user, | ||
price: price | ||
})); | ||
|
||
case 17: | ||
case 19: | ||
res.status(200).json({ | ||
received: true | ||
}); | ||
|
||
case 18: | ||
case 20: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
"use strict"; | ||
|
||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
|
||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
|
||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
|
||
var nodemailer = require('nodemailer'); | ||
|
||
var pug = require('pug'); | ||
|
||
var htmlToText = require('html-to-text'); | ||
|
||
module.exports = | ||
/*#__PURE__*/ | ||
function () { | ||
function Email(user, url) { | ||
_classCallCheck(this, Email); | ||
|
||
this.from = "Siddharth Singh ".concat(process.env.EMAIL_FROM); | ||
this.url = url; | ||
this.name = user.name; | ||
this.to = user.email; | ||
} | ||
|
||
_createClass(Email, [{ | ||
key: "newTransport", | ||
value: function newTransport() { | ||
return regeneratorRuntime.async(function newTransport$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", nodemailer.createTransport({ | ||
service: 'Gmail', | ||
auth: { | ||
user: process.env.GMAIL_USERNAME, | ||
pass: process.env.GMAIL_PASSWORD | ||
} | ||
})); | ||
|
||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}); | ||
} //Send the actual email | ||
|
||
}, { | ||
key: "send", | ||
value: function send(template, subject) { | ||
var html, mailOptions, transporter; | ||
return regeneratorRuntime.async(function send$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
// 1) Render HTML based on a pug template | ||
html = pug.renderFile("".concat(__dirname, "/../views/email/").concat(template, ".pug"), { | ||
firstName: this.name, | ||
url: this.url, | ||
subject: subject | ||
}); // 2) Define email options | ||
|
||
mailOptions = { | ||
from: this.from, | ||
to: this.to, | ||
subject: subject, | ||
html: html, | ||
text: htmlToText.fromString(html) | ||
}; // 3) Create a transport and send email | ||
|
||
_context2.next = 4; | ||
return regeneratorRuntime.awrap(this.newTransport()); | ||
|
||
case 4: | ||
transporter = _context2.sent; | ||
_context2.next = 7; | ||
return regeneratorRuntime.awrap(transporter.sendMail(mailOptions)); | ||
|
||
case 7: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, null, this); | ||
} | ||
}, { | ||
key: "sendWelcome", | ||
value: function sendWelcome() { | ||
return regeneratorRuntime.async(function sendWelcome$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.next = 2; | ||
return regeneratorRuntime.awrap(this.send('welcome', 'Welcome to the Natours Family!')); | ||
|
||
case 2: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, null, this); | ||
} | ||
}, { | ||
key: "sendPasswordReset", | ||
value: function sendPasswordReset() { | ||
return regeneratorRuntime.async(function sendPasswordReset$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
_context4.next = 2; | ||
return regeneratorRuntime.awrap(this.send('passwordReset', 'Your password reset token (valid for only 10 minutes.)')); | ||
|
||
case 2: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
} | ||
}, null, this); | ||
} | ||
}, { | ||
key: "sendBookingSuccessful", | ||
value: function sendBookingSuccessful() { | ||
return regeneratorRuntime.async(function sendBookingSuccessful$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
_context5.next = 2; | ||
return regeneratorRuntime.awrap(this.send('bookingSuccess', 'Booking Confirmation')); | ||
|
||
case 2: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
} | ||
}, null, this); | ||
} | ||
}]); | ||
|
||
return Email; | ||
}(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
extends baseEmail | ||
|
||
block content | ||
p Hi #{firstName}! | ||
p Good news🤗, Your booking has been confirmed. | ||
p We will be happy to host you. | ||
p This is an automated email, you are not required to reply to this. | ||
p If you have any questions or need any help, please reach out to | ||
table.btn.btn-primary(role='presentation', border='0', cellpadding='0', cellspacing='0') | ||
tbody | ||
tr | ||
td(align='left') | ||
table(role='presentation', border='0', cellpadding='0', cellspacing='0') | ||
tbody | ||
tr | ||
td | ||
a(href=`${url}`, target='_blank') Natours support | ||
p and let us know. |
Oops, something went wrong.