Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3dbbebb43 |
No files matched your search
Generated
-1
@@ -1442,7 +1442,6 @@
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-7.0.3.tgz",
|
||||
"integrity": "sha512-Ajq6Sz1x7cIK3pN6KesGTah+1gnwMnx5gKl3piQlQQE/PwyJ4Mbc8is2psWYxK3RJTVeqsDaCv8ZzXLCDHMTZw==",
|
||||
"license": "MIT-0",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
|
||||
+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;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,5 @@
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/flowbite@3.1.2/dist/flowbite.min.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,4 +1,5 @@
|
||||
<!-- 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>
|
||||
// If no geoData provided thorugh EJS, send update request to backend
|
||||
|
||||
@@ -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