commit
884209ee9c
@ -2,11 +2,10 @@ const express = require("express");
|
||||
const { rateLimit } = require("express-rate-limit");
|
||||
const path = require("path");
|
||||
const app = express();
|
||||
const ejs = require("ejs");
|
||||
|
||||
module.exports = app;
|
||||
|
||||
process.nextTick(() => require("./mqttApp"));
|
||||
//process.nextTick(() => require("./mqttApp"));
|
||||
|
||||
app.use(express.json());
|
||||
app.set("json spaces", 2);
|
||||
@ -68,6 +67,7 @@ app.use(function (err, req, res, next) {
|
||||
keyErrors[item.path] = item.message;
|
||||
}
|
||||
}
|
||||
res.status = 422;
|
||||
}
|
||||
|
||||
if (![404, 401, 422].includes(err.status || res.status)) {
|
||||
@ -76,6 +76,7 @@ app.use(function (err, req, res, next) {
|
||||
console.error("=========================================");
|
||||
}
|
||||
res.status(err.status || 500);
|
||||
// res.status(err.status || 500);
|
||||
|
||||
if (req.get('Content-Type') && req.get('Content-Type').includes("json")) {
|
||||
res.json({
|
||||
@ -91,4 +92,4 @@ app.use(function (err, req, res, next) {
|
||||
keyErrors,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -15,7 +15,7 @@ const sequelize = new Sequelize(
|
||||
attributeBehavior: 'escape',
|
||||
dialectOptions: {
|
||||
ssl: {
|
||||
ca: fs.readFileSync(path.resolve(__dirname, '../cert/DigiCertGlobalRootCA.crt_3.pem')),
|
||||
ca: fs.readFileSync(path.resolve(__dirname, '../cert/DigiCertGlobalRootCA.crt.pem')),
|
||||
},
|
||||
|
||||
},
|
||||
|
@ -77,6 +77,67 @@ async function sendTokenEmail(email, token) {
|
||||
}
|
||||
}
|
||||
|
||||
async function sendResetPasswordEmail(email, message) {
|
||||
console.log(email, message);
|
||||
|
||||
try {
|
||||
let resetMessage = await transporter.sendMail({
|
||||
to: process.env.euser,
|
||||
subject: "Reset Password",
|
||||
html: `
|
||||
<h1>Reset Password</h1>
|
||||
<p><strong>From:</strong> Eco Saver</p>
|
||||
<p><strong>User Email:</strong> ${email}</p>
|
||||
<p><strong>Message:</strong> ${message}</p>
|
||||
<p>Kindly click on the link given to reset your password!</p>
|
||||
<p>Regards,</p>
|
||||
<p>EcoSaver Team</p>
|
||||
<p><a href="https://ecosaver.teeseng.uk/">EcoSaver Website</a></p>
|
||||
<p>Please do not reply to this email.</p>
|
||||
`,
|
||||
});
|
||||
transporter.sendMail({ resetMessage }, function (error, info) {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
} else {
|
||||
console.log("Email sent: " + info.response);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function sendResetTokenEmail(email, token) {
|
||||
|
||||
try {
|
||||
let tokenMessage = await transporter.sendMail({
|
||||
to: email,
|
||||
from: process.env.euser,
|
||||
subject: "API Token",
|
||||
html: `
|
||||
<h1>API Token</h1>
|
||||
<p><strong>Token:</strong> ${token}</p>
|
||||
<p>Please do not lose this token and do not share your token with anyone!</p>
|
||||
<p>Thank you for using EcoSaver.</p>
|
||||
<p>Regards,</p>
|
||||
<p>EcoSaver Team</p>
|
||||
<p><a href="https://ecosaver.teeseng.uk/">EcoSaver Website</a></p>
|
||||
<p>Please do not reply to this email.</p>
|
||||
|
||||
`,
|
||||
});
|
||||
transporter.sendMail({ resetMessage }, function (error, info) {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
} else {
|
||||
console.log("Email sent: " + info.response);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports = { sendContactEmail , sendTokenEmail };
|
||||
module.exports = { sendContactEmail , sendTokenEmail, sendResetPasswordEmail, sendResetTokenEmail };
|
||||
|
@ -72,4 +72,28 @@ router.post("/contact", async (req, res, next) => {
|
||||
}
|
||||
});
|
||||
|
||||
//reset
|
||||
router.post("/checkemail", async (req, res, next) => {
|
||||
try{
|
||||
//console.log(req.body);
|
||||
let Res = await checkEmail(req.body.email);
|
||||
if (!Res) {
|
||||
let error = new Error("Email not found");
|
||||
error.status = 400;
|
||||
return next(error);
|
||||
}
|
||||
else{
|
||||
//console.log(Res);
|
||||
send(req.body.email, req.body.name, req.body.message);
|
||||
return res.json({
|
||||
message: "Reset Password Link has successfully sent to your email!",
|
||||
});
|
||||
|
||||
}
|
||||
}catch (error){
|
||||
console.error(error);
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
@ -4,10 +4,9 @@
|
||||
<section class="wrapper">
|
||||
<div class="form">
|
||||
<header>Reset Password</header>
|
||||
<form action="/resetpassword">
|
||||
<input type="text" id="email" placeholder="Email" required />
|
||||
<input type="password" id="password" placeholder="Password" required />
|
||||
<input type="password" id="confirmPassword" placeholder="Confirm Password" required />
|
||||
<form action="auth/checkemail" method="POST" onsubmit="formAJAX(this)">
|
||||
<input type="email" name="email" placeholder="Email" required
|
||||
pattern="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
|
||||
<input type="submit" value="Reset Password" />
|
||||
</form>
|
||||
<br>
|
||||
|
@ -29,7 +29,7 @@
|
||||
<table class="footer">
|
||||
<tr>
|
||||
<td>
|
||||
<p>© 2023 EcoSaver</p>
|
||||
<p>© 2024 EcoSaver</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
Loading…
x
Reference in New Issue
Block a user