Merge branch 'main' of https://gits.techvanguard.vn/UKSOURCE/cms.hailearning.edu.vn into fea/bao-10022026-AuditLog

This commit is contained in:
nguyenvanbao
2026-02-10 16:46:39 +07:00
9 changed files with 148 additions and 32 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) {