feat: add password toggle visibility and rename forgot-password to change-password

This commit is contained in:
Wini_Fy
2026-02-10 10:24:35 +07:00
parent 2ddf43c139
commit 5e7de227ec
8 changed files with 116 additions and 27 deletions

View File

@@ -134,22 +134,22 @@ router.post('/register', async (req, res) => {
}
});
// Forgot Password Page
router.get('/forgot-password', (req, res) => {
res.render('auth/forgot-password', {
title: 'Forgot Password',
// Change Password Page
router.get('/change-password', (req, res) => {
res.render('auth/change-password', {
title: 'Change Password',
layout: false
});
});
// Forgot Password Handle
router.post('/forgot-password', async (req, res) => {
// Change Password Handle
router.post('/change-password', async (req, res) => {
const { email } = req.body;
try {
const user = await User.findOne({ email });
if (!user) {
req.flash('error_msg', 'No account with that email address exists.');
return res.redirect('/auth/forgot-password');
return res.redirect('/auth/change-password');
}
const token = crypto.randomBytes(20).toString('hex');
@@ -166,7 +166,7 @@ router.post('/forgot-password', async (req, res) => {
} catch (err) {
console.error(err);
req.flash('error_msg', 'Error processing request');
res.redirect('/auth/forgot-password');
res.redirect('/auth/change-password');
}
});
@@ -180,7 +180,7 @@ router.get('/reset-password/:token', async (req, res) => {
if (!user) {
req.flash('error_msg', 'Password reset token is invalid or has expired.');
return res.redirect('/auth/forgot-password');
return res.redirect('/auth/change-password');
}
res.render('auth/reset-password', {
@@ -190,7 +190,7 @@ router.get('/reset-password/:token', async (req, res) => {
});
} catch (err) {
console.error(err);
res.redirect('/auth/forgot-password');
res.redirect('/auth/change-password');
}
});
@@ -204,7 +204,7 @@ router.post('/reset-password/:token', async (req, res) => {
if (!user) {
req.flash('error_msg', 'Password reset token is invalid or has expired.');
return res.redirect('/auth/forgot-password');
return res.redirect('/auth/change-password');
}
if (req.body.password !== req.body.confirm_password) {