make it betterlkjkfkff

This commit is contained in:
pawan-dot 2022-06-23 12:22:31 +05:30
parent 369c00158b
commit 22fe368d49
3 changed files with 24 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import sendToken from "../Utils/jwtToken.js"
import sendEmail from "../Utils/sendEmail.js" import sendEmail from "../Utils/sendEmail.js"
import crypto from "crypto" import crypto from "crypto"
import cloudinary from "cloudinary" import cloudinary from "cloudinary"
import generator from 'generate-password'
// 1.Register a User // 1.Register a User
export const registerUser = catchAsyncErrors(async (req, res, next) => { export const registerUser = catchAsyncErrors(async (req, res, next) => {
@ -90,15 +91,19 @@ export const forgotPassword = catchAsyncErrors(async (req, res, next) => {
//create link for send mail //create link for send mail
// const resetPasswordUrl = `http://localhost:5000/api/v1/user/password/reset/${resetToken}` //send from localhost // const resetPasswordUrl = `http://localhost:5000/api/v1/user/password/reset/${resetToken}` //send from localhost
//send from anyhost //send from anyhost
const resetPasswordUrl = `${req.protocol}://${req.get( // const resetPasswordUrl = `${req.protocol}://${req.get(
"host" // "host"
)}/api/v1/user/password/reset/${resetToken}`; // )}/api/v1/user/password/reset/${resetToken}`;
//const resetPasswordUrl = `${process.env.FRONTEND_URL}:/api/user/password/reset/${resetToken}`; //const resetPasswordUrl = `${process.env.FRONTEND_URL}:/api/user/password/reset/${resetToken}`;
//const resetPasswordUrl = `${process.env.FRONTEND_URL}/password/reset/${resetToken}`; //const resetPasswordUrl = `${process.env.FRONTEND_URL}/password/reset/${resetToken}`;
const password = generator.generate({
length: 10,
const message = `Your password reset token are :- \n\n ${resetPasswordUrl} \n\nIf you have not requested this email then, please ignore it.`; numbers: true
});
user.password = password;
await user.save()
// const message = `Your password reset token are :- \n\n ${resetPasswordUrl} \n\nyour new password is:${password}\n\nIf you have not requested this email then, please ignore it.`;
const message = `your new password is:${password}\n\nIf you have not requested this email then, please ignore it.`
try { try {
await sendEmail({ await sendEmail({
email: user.email, email: user.email,

11
package-lock.json generated
View File

@ -17,6 +17,7 @@
"dotenv": "^16.0.1", "dotenv": "^16.0.1",
"express": "^4.18.1", "express": "^4.18.1",
"express-fileupload": "^1.4.0", "express-fileupload": "^1.4.0",
"generate-password": "^1.7.0",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"mongoose": "^6.3.5", "mongoose": "^6.3.5",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
@ -704,6 +705,11 @@
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
}, },
"node_modules/generate-password": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/generate-password/-/generate-password-1.7.0.tgz",
"integrity": "sha512-WPCtlfy0jexf7W5IbwxGUgpIDvsZIohbI2DAq2Q6TSlKKis+G4GT9sxvPxrZUGL8kP6WUXMWNqYnxY6DDKAdFA=="
},
"node_modules/get-intrinsic": { "node_modules/get-intrinsic": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
@ -2400,6 +2406,11 @@
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
}, },
"generate-password": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/generate-password/-/generate-password-1.7.0.tgz",
"integrity": "sha512-WPCtlfy0jexf7W5IbwxGUgpIDvsZIohbI2DAq2Q6TSlKKis+G4GT9sxvPxrZUGL8kP6WUXMWNqYnxY6DDKAdFA=="
},
"get-intrinsic": { "get-intrinsic": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",

View File

@ -19,6 +19,7 @@
"dotenv": "^16.0.1", "dotenv": "^16.0.1",
"express": "^4.18.1", "express": "^4.18.1",
"express-fileupload": "^1.4.0", "express-fileupload": "^1.4.0",
"generate-password": "^1.7.0",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"mongoose": "^6.3.5", "mongoose": "^6.3.5",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",