Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6444d7afa7 | ||
|
|
daa984a48f | ||
|
|
383bd15263 | ||
|
|
1e44e8ddfb | ||
|
|
cc875b4e22 | ||
|
|
f3dbbebb43 |
No files matched your search
@@ -106,53 +106,6 @@ app.get('/reset/:token', async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/resetLink', async (req, res) => {
|
||||
const { token, password, confirmPassword, } = req.body;
|
||||
const passwordSchema = joi.object({
|
||||
password: joi.string().max(20).required(),
|
||||
confirmPassword: joi.string().max(20).required(),
|
||||
});
|
||||
const valid = passwordSchema.validate({ password, confirmPassword });
|
||||
if (valid.error) {
|
||||
console.log("houston we have a problem");
|
||||
req.session.error = 'Invalid input';
|
||||
res.status(status.BadRequest);
|
||||
return res.redirect(`/reset/${token}`);
|
||||
}
|
||||
if (!token || !password || !confirmPassword) {
|
||||
req.session.error = 'field may be missing';
|
||||
return res.redirect(`/reset/${token}`);
|
||||
}
|
||||
if (password !== confirmPassword) {
|
||||
req.session.error = 'passwords do not match';
|
||||
return res.redirect(`/reset/${token}`);
|
||||
}
|
||||
const user = await users.findOne({
|
||||
resetToken: token,
|
||||
resetTokenExpires: { $gt: Date.now() },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
req.session.error = 'Reset link is invalid.';
|
||||
return res.redirect(`/reset`);
|
||||
}
|
||||
const hashPassword = await bcrypt.hash(password, 12);
|
||||
|
||||
await users.updateOne(
|
||||
{
|
||||
email: user.email
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
password: hashPassword,
|
||||
resetToken: '',
|
||||
resetTokenExpires: 0,
|
||||
},
|
||||
}
|
||||
);
|
||||
req.session.success = 'Password has been reset';
|
||||
res.redirect('/login');
|
||||
});
|
||||
|
||||
// 404 handler - keep the actual notFound route please
|
||||
// REALLY DONT DELETE THIS
|
||||
|
||||
+52
-2
@@ -2,7 +2,9 @@ const express = require('express');
|
||||
const crypto = require('crypto');
|
||||
const joi = require('joi');
|
||||
const nodeMail = require('nodemailer');
|
||||
const bcrypt = require('bcrypt');
|
||||
require('dotenv').config();
|
||||
const PORT = process.env.PORT;
|
||||
|
||||
const transporter = nodeMail.createTransport({
|
||||
service: 'gmail',
|
||||
@@ -16,7 +18,6 @@ module.exports = (users) => {
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/auth/resetPass', async (req, res) => {
|
||||
console.log("we are inside of the post");
|
||||
const resetSchema = joi.object({
|
||||
email: joi.string().email().required(),
|
||||
});
|
||||
@@ -44,7 +45,7 @@ module.exports = (users) => {
|
||||
$set: { resetToken: token, resetTokenExpires: expiration }
|
||||
});
|
||||
|
||||
const resetUrl = `http://localhost:3000/reset/${token}`;
|
||||
const resetUrl = `http://localhost:${PORT}/reset/${token}`;
|
||||
|
||||
const mailSend = {
|
||||
from: process.env.EMAIL_USER,
|
||||
@@ -63,6 +64,55 @@ module.exports = (users) => {
|
||||
res.status(500).send('email failed to send try again');
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/resetLink', async (req, res) => {
|
||||
const { token, password, confirmPassword, } = req.body;
|
||||
const passwordSchema = joi.object({
|
||||
password: joi.string().max(20).required(),
|
||||
confirmPassword: joi.string().max(20).required(),
|
||||
});
|
||||
const valid = passwordSchema.validate({ password, confirmPassword });
|
||||
if (valid.error) {
|
||||
console.log("houston we have a problem");
|
||||
req.session.error = 'Invalid input';
|
||||
res.status(status.BadRequest);
|
||||
return res.redirect(`/reset/${token}`);
|
||||
}
|
||||
if (!token || !password || !confirmPassword) {
|
||||
req.session.error = 'field may be missing';
|
||||
return res.redirect(`/reset/${token}`);
|
||||
}
|
||||
if (password !== confirmPassword) {
|
||||
req.session.error = 'passwords do not match';
|
||||
return res.redirect(`/reset/${token}`);
|
||||
}
|
||||
const user = await users.findOne({
|
||||
resetToken: token,
|
||||
resetTokenExpires: { $gt: Date.now() },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
req.session.error = 'Reset link is invalid.';
|
||||
return res.redirect(`/reset`);
|
||||
}
|
||||
const hashPassword = await bcrypt.hash(password, 12);
|
||||
|
||||
await users.updateOne(
|
||||
{
|
||||
email: user.email
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
password: hashPassword,
|
||||
resetToken: '',
|
||||
resetTokenExpires: 0,
|
||||
},
|
||||
}
|
||||
);
|
||||
req.session.success = 'Password has been reset';
|
||||
res.redirect('/login');
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
+8
-2
@@ -163,7 +163,7 @@ module.exports = (middleware, users, plans, assets) => {
|
||||
});
|
||||
|
||||
router.get('/newPlan', (req, res) => {
|
||||
if (!req.session.user.financialData) {
|
||||
if (!req.session.user.financialData || !req.session.user) {
|
||||
req.session.errMessage = "Please complete your financial data before creating a plan.";
|
||||
return res.status(status.Unauthorized).redirect('/questionnaire');
|
||||
}
|
||||
@@ -299,7 +299,13 @@ module.exports = (middleware, users, plans, assets) => {
|
||||
|
||||
req.session.user.financialData = true;
|
||||
req.session.errMessage = "";
|
||||
res.status(status.Ok).redirect("/home");
|
||||
|
||||
req.session.save(err => {
|
||||
if (err) {
|
||||
res.status(status.InternalServerError).redirect("/plans");
|
||||
}
|
||||
res.status(status.Ok).redirect("/plans");
|
||||
});
|
||||
|
||||
}).catch(err => {
|
||||
console.error("Error updating questionnaire in database:", err);
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
<% plans.forEach(plan => { %>
|
||||
<a href="/plans/<%= plan._id %>" class="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow-sm hover:bg-gray-100 dark:bg-gray-800 dark:border-gray-700 dark:hover:bg-gray-700">
|
||||
<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white"><%= plan.name %></h5>
|
||||
<div class="w-full bg-gray-200 rounded-full h-2.5 mb-4 dark:bg-gray-700">
|
||||
<div class="w-full bg-black rounded-full h-2.5 mb-4 dark:bg-black">
|
||||
<div class="bg-green-600 h-2.5 rounded-full dark:bg-green-500" style="width: <%= plan.progress %>%;"></div>
|
||||
</div>
|
||||
<p class="font-normal text-gray-700 dark:text-gray-400"><%= plan.description %></p>
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
<input type="hidden" name="token" value="<%=token %>">
|
||||
<div class="mt-3">
|
||||
<label for="password" class="block text-base mb-2">New Password:</label>
|
||||
<input type="text" id="password" name="password"
|
||||
<input type="password" id="password" name="password"
|
||||
class="border focus:border-gray-600 w-full rounded-md text-base px-2 py-1 focus:outline-none focus:ring-0 "
|
||||
placeholder="Enter Password" />
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
<label for="password" class="block text-base mb-2">Confirm Password:</label>
|
||||
<input type="text" id="Repassword" name="confirmPassword"
|
||||
<input type="password" id="Repassword" name="confirmPassword"
|
||||
class="border focus:border-gray-600 w-full rounded-md text-base px-2 py-1 focus:outline-none focus:ring-0 "
|
||||
placeholder="ReType Password" />
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user