-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aca14fe
commit 9d10a65
Showing
31 changed files
with
812 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const User = require("../../models/user"); | ||
const bcrypt = require("bcrypt"); | ||
const mongoose = require("mongoose"); | ||
const Vision = require("../../models/vision"); | ||
const { redis } = require("./util"); | ||
|
||
|
||
|
||
class ForgotAndUpdateDetail{ | ||
|
||
async getValue(key) { | ||
return await redis.get(key); | ||
} | ||
|
||
async handleRequest(req, res){ | ||
// console.log(req.body); | ||
|
||
|
||
|
||
const password = req.body.password; | ||
const repassword = req.body.repassword; | ||
const email = req.body.email; | ||
|
||
if(password !== repassword){ | ||
return res.status(200).json({"msg":"Password is not same" , "verified" : false,"code" : "0"}) | ||
} | ||
|
||
let otp; | ||
try { | ||
otp = await this.getValue(req.body.email); | ||
// console.log(otp); | ||
if(otp !== null){ | ||
if(otp === req.body.otp){ | ||
|
||
//Hashing the password | ||
bcrypt.hash(password, 10, (error, hash) => { | ||
if (error) res.status(500).json({ error }); | ||
else { | ||
|
||
|
||
User.updateOne({_id : req.body.user_id},{ | ||
$set: {"password" : hash} | ||
}).then((user)=>{ | ||
return res.status(200).json({ | ||
"msg": "Password is successfully updated!", | ||
"verified" : true, | ||
"code" : "1" | ||
}); | ||
}).catch((err)=>{console.log(err)}); | ||
} | ||
}); | ||
} | ||
else{ | ||
// console.log("inc otp"); | ||
return res.status(200).json({"msg" : "Incorrect OTP","verified" : false,"code" : "0"}); | ||
} | ||
} | ||
else{ | ||
// console.log("otp exp"); | ||
return res.status(200).json({"msg" : "OTP expired","verified" : false,"code" : "0"}); | ||
} | ||
|
||
} catch(error) { | ||
console.log(error); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = {ForgotAndUpdateDetail : ForgotAndUpdateDetail}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const User = require("../../models/user"); | ||
const { generateOTP , initNodeMailer} = require("./util"); | ||
|
||
class ForgotAndVerifyDetail{ | ||
|
||
handleRequest(req, res){ | ||
console.log(req.body); | ||
// const username = req.body.username, | ||
const email = req.body.email; | ||
// password = req.body.password; | ||
User.findOne({ email }) //Checking if the email exist | ||
.then((user) => { | ||
console.log(user); | ||
if (user === null) | ||
{ | ||
return res.status(200).json({"msg" : "Email doesn't exist!","status" : false})} | ||
else { | ||
//for initialise NodeMailer | ||
const transporter = initNodeMailer(); | ||
generateOTP(req,res,transporter); | ||
return res.status(200).json({"user" : req.body,"msg" : "OTP has been sent to your Gmail","status" : true}); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
|
||
module.exports = {ForgotAndVerifyDetail : ForgotAndVerifyDetail}; |
Oops, something went wrong.