Skip to content

Commit

Permalink
Merge pull request #74 from nipun1234/fix/ngo-registration-fix
Browse files Browse the repository at this point in the history
NGO Registration is not working
  • Loading branch information
Sahil1786 committed May 14, 2024
2 parents 7bb03ec + 508d3c6 commit 5333db5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 18 additions & 2 deletions routers/NgoRoutes.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions views/Email.template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@
<h1>Registration Successful!</h1>
</div>
<div class="content">
<p>Thank you <span class="highlight">{{user.fname}}</span> for registering on Petari. Your account has been successfully created.</p>
<p>Thank you <span class="highlight"> {{ user.fname }}</span> for registering on Petari. Your account has been successfully created.</p>

<div class="details">
<strong>User ID:</strong> {{{ user._id }}}<br>
<strong>Username:</strong> {{{ user.username }}}<br>
<strong>Email:</strong> {{{ user.email }}}
<strong>User ID:</strong> {{ user._id }}<br>
<strong>Username:</strong> {{ user.username }}<br>
<strong>Email:</strong> {{ user.email }}
</div>

<p>
Expand Down

0 comments on commit 5333db5

Please sign in to comment.