Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ee885ac57 |
No files matched your search
Generated
+1
@@ -1442,6 +1442,7 @@
|
|||||||
"version": "7.0.3",
|
"version": "7.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-7.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-7.0.3.tgz",
|
||||||
"integrity": "sha512-Ajq6Sz1x7cIK3pN6KesGTah+1gnwMnx5gKl3piQlQQE/PwyJ4Mbc8is2psWYxK3RJTVeqsDaCv8ZzXLCDHMTZw==",
|
"integrity": "sha512-Ajq6Sz1x7cIK3pN6KesGTah+1gnwMnx5gKl3piQlQQE/PwyJ4Mbc8is2psWYxK3RJTVeqsDaCv8ZzXLCDHMTZw==",
|
||||||
|
"license": "MIT-0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.0.0"
|
"node": ">=6.0.0"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-52
@@ -2,9 +2,7 @@ const express = require('express');
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const joi = require('joi');
|
const joi = require('joi');
|
||||||
const nodeMail = require('nodemailer');
|
const nodeMail = require('nodemailer');
|
||||||
const bcrypt = require('bcrypt');
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const PORT = process.env.PORT;
|
|
||||||
|
|
||||||
const transporter = nodeMail.createTransport({
|
const transporter = nodeMail.createTransport({
|
||||||
service: 'gmail',
|
service: 'gmail',
|
||||||
@@ -18,6 +16,7 @@ module.exports = (users) => {
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.post('/auth/resetPass', async (req, res) => {
|
router.post('/auth/resetPass', async (req, res) => {
|
||||||
|
console.log("we are inside of the post");
|
||||||
const resetSchema = joi.object({
|
const resetSchema = joi.object({
|
||||||
email: joi.string().email().required(),
|
email: joi.string().email().required(),
|
||||||
});
|
});
|
||||||
@@ -45,7 +44,7 @@ module.exports = (users) => {
|
|||||||
$set: { resetToken: token, resetTokenExpires: expiration }
|
$set: { resetToken: token, resetTokenExpires: expiration }
|
||||||
});
|
});
|
||||||
|
|
||||||
const resetUrl = `http://localhost:${PORT}/reset/${token}`;
|
const resetUrl = `http://localhost:3000/reset/${token}`;
|
||||||
|
|
||||||
const mailSend = {
|
const mailSend = {
|
||||||
from: process.env.EMAIL_USER,
|
from: process.env.EMAIL_USER,
|
||||||
@@ -64,55 +63,6 @@ module.exports = (users) => {
|
|||||||
res.status(500).send('email failed to send try again');
|
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;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7,5 +7,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/flowbite@3.1.2/dist/flowbite.min.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
<!-- Get geolocation if not in session and load conversion rates -->
|
<!-- Get geolocation if not in session and load conversion rates -->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/flowbite@3.1.2/dist/flowbite.min.js"></script>
|
|
||||||
<script src="/static/scripts/geolocation.js"></script>
|
<script src="/static/scripts/geolocation.js"></script>
|
||||||
<script>
|
<script>
|
||||||
// If no geoData provided thorugh EJS, send update request to backend
|
// If no geoData provided thorugh EJS, send update request to backend
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
<input type="hidden" name="token" value="<%=token %>">
|
<input type="hidden" name="token" value="<%=token %>">
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<label for="password" class="block text-base mb-2">New Password:</label>
|
<label for="password" class="block text-base mb-2">New Password:</label>
|
||||||
<input type="password" id="password" name="password"
|
<input type="text" 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 "
|
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" />
|
placeholder="Enter Password" />
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<label for="password" class="block text-base mb-2">Confirm Password:</label>
|
<label for="password" class="block text-base mb-2">Confirm Password:</label>
|
||||||
<input type="password" id="Repassword" name="confirmPassword"
|
<input type="text" 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 "
|
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" />
|
placeholder="ReType Password" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user