Skip to content

Commit

Permalink
reset password auth endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald-pro committed Apr 12, 2024
1 parent ece5454 commit 338b7bd
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 deletions routes/processes/nishauri_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,44 @@ router.post("/verifyotp", async (req, res) => {
}
});

//Verify reset password otp
router.post("/verifyresetpassotp", async (req, res) => {
let otp_verify = req.body.otp;
let user_name = req.body.user_name;
let today = moment(new Date().toDateString())
.tz("Africa/Nairobi")
.format("YYYY-MM-DD H:M:S");
//Check If User Exists
let check_username = await NUsers.findOne({
where: {
[Op.and]: [
{ otp_number: otp_verify },
{ msisdn: user_name }
]
}
});

if (check_username) {
var l = {
user_id: base64.encode(check_username.id),
page_id: 0
};

//return success on OTP Verification
return res.status(200).json({
success: true,
msg: "OTP Verified Successfully",
data: l
});
} else {
//return success on OTP Verification
return res.status(200).json({
success: false,
msg: "Invalid or Expired OTP"
});
}
});

//update password
router.post("/updatepassword", async (req, res) => {
let password_1 = req.body.password;
Expand Down Expand Up @@ -425,6 +463,35 @@ router.post("/updatepassword", async (req, res) => {
}
});

// change password after reset
router.post("/changepassword", async (req, res) => {
let password_1 = req.body.new_password;
let username = req.body.username;
let today = moment(new Date().toDateString())
.tz("Africa/Nairobi")
.format("YYYY-MM-DD H:M:S");

const password_hash = bcrypt.hashSync(password_1, 10);

try {
const log_login = await NUsers.update(
{ password: password_hash },
{ updated_at: today },
{ where: { msisdn: username } }
);

return res.status(200).json({
success: true,
msg: "Password reset successfully"
});
} catch (err) {
return res.status(200).json({
success: false,
msg: "Failed to update new password"
});
}
});

//Set Programs
//app.get('/protected', passport.authenticate('jwt', { session: false }), (req, res) => {
// res.send('You have accessed a protected route!');
Expand Down Expand Up @@ -2425,8 +2492,6 @@ router.post(
}
});

// console.log(check_order_request);

if (check_order_request) {
return res.status(200).json({
success: false,
Expand Down

0 comments on commit 338b7bd

Please sign in to comment.