diff --git a/consumerWebsite/app.js b/consumerWebsite/app.js index ab82e57..382772d 100644 --- a/consumerWebsite/app.js +++ b/consumerWebsite/app.js @@ -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, }); } -}); \ No newline at end of file +}); diff --git a/consumerWebsite/database/mySQL.js b/consumerWebsite/database/mySQL.js index 6bba43b..275674f 100644 --- a/consumerWebsite/database/mySQL.js +++ b/consumerWebsite/database/mySQL.js @@ -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')), }, }, diff --git a/consumerWebsite/functions/nodeMail.js b/consumerWebsite/functions/nodeMail.js index f81a8c4..c54f8b7 100644 --- a/consumerWebsite/functions/nodeMail.js +++ b/consumerWebsite/functions/nodeMail.js @@ -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: ` +

Reset Password

+

From: Eco Saver

+

User Email: ${email}

+

Message: ${message}

+

Kindly click on the link given to reset your password!

+

Regards,

+

EcoSaver Team

+

EcoSaver Website

+

Please do not reply to this email.

+ `, + }); + 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: ` +

API Token

+

Token: ${token}

+

Please do not lose this token and do not share your token with anyone!

+

Thank you for using EcoSaver.

+

Regards,

+

EcoSaver Team

+

EcoSaver Website

+

Please do not reply to this email.

+ + `, + }); + 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 }; diff --git a/consumerWebsite/routes/auth.js b/consumerWebsite/routes/auth.js index 276a5a2..675e72d 100644 --- a/consumerWebsite/routes/auth.js +++ b/consumerWebsite/routes/auth.js @@ -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; diff --git a/consumerWebsite/views/forgotPassword.ejs b/consumerWebsite/views/forgotPassword.ejs index ca37f61..735c74e 100644 --- a/consumerWebsite/views/forgotPassword.ejs +++ b/consumerWebsite/views/forgotPassword.ejs @@ -4,10 +4,9 @@
Reset Password
-
- - - + +

diff --git a/consumerWebsite/views/resetpassword.ejs b/consumerWebsite/views/resetpassword.ejs index 18f140e..960e236 100644 --- a/consumerWebsite/views/resetpassword.ejs +++ b/consumerWebsite/views/resetpassword.ejs @@ -29,7 +29,7 @@