From 508d3c65e8d5559ac07364e8d467a51ae4537b5f Mon Sep 17 00:00:00 2001 From: nipun1234 Date: Tue, 14 May 2024 21:21:38 +0530 Subject: [PATCH] ngo registration signup fix --- package-lock.json | 1 + package.json | 1 + routers/NgoRoutes.js | 20 ++++++++++++++++++-- views/Email.template.handlebars | 8 ++++---- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6f34f69..2e02253 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "express-handlebars": "^7.1.2", "express-session": "^1.17.3", "fs": "^0.0.1-security", + "handlebars": "^4.7.8", "jsonwebtoken": "^9.0.2", "method-override": "^3.0.0", "moment": "^2.29.4", diff --git a/package.json b/package.json index 57d7fc5..804e560 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "express-handlebars": "^7.1.2", "express-session": "^1.17.3", "fs": "^0.0.1-security", + "handlebars": "^4.7.8", "jsonwebtoken": "^9.0.2", "method-override": "^3.0.0", "moment": "^2.29.4", diff --git a/routers/NgoRoutes.js b/routers/NgoRoutes.js index daa98aa..8f7d274 100644 --- a/routers/NgoRoutes.js +++ b/routers/NgoRoutes.js @@ -1,5 +1,8 @@ const express = require("express"); const router = new express.Router(); +const fs = require("fs"); +const path = require('path'); +const Handlebars = require('handlebars'); const bcrypt = require("bcrypt"); const saltRounds = 10; @@ -58,14 +61,27 @@ router.post("/NGO-Registarion", async (req, res) => { // Save the new NGO to the database await newNGO.save(); + const templatePath = path.join(__dirname, '../views', 'Email.template.handlebars'); + const templateContent = fs.readFileSync(templatePath, 'utf8'); + +// Compile the Handlebars template with the provided context data +const compiledHtml = Handlebars.compile(templateContent)({ + user: { + _id: newNGO.NgoID, // Example ID + username: newNGO.NGOName, // Example username + email: newNGO.username, // Example email + fname: newNGO.NGOName // Example first name + } + }); // Send an email to the admin for approval - let mailOptions = { + const mailOptions = { to: newNGO.username, // Admin's email address subject: "New NGO Registration", text: "A new NGO registration is pending approval. Login to the admin panel to review and approve.", + html: compiledHtml // Include any necessary information in the email body }; - transporter.sendMail(mailOptions, function (error, info) { + transporter.transporter.sendMail(mailOptions, function (error, info) { if (error) { console.log(error); } else { diff --git a/views/Email.template.handlebars b/views/Email.template.handlebars index 42c04ab..2d611bb 100644 --- a/views/Email.template.handlebars +++ b/views/Email.template.handlebars @@ -92,12 +92,12 @@

Registration Successful!

-

Thank you {{user.fname}} for registering on Petari. Your account has been successfully created.

+

Thank you {{ user.fname }} for registering on Petari. Your account has been successfully created.

- User ID: {{{ user._id }}}
- Username: {{{ user.username }}}
- Email: {{{ user.email }}} + User ID: {{ user._id }}
+ Username: {{ user.username }}
+ Email: {{ user.email }}