fix change pw
This commit is contained in:
parent
68ba7c4a5e
commit
fbd18b8678
25
server.js
25
server.js
@ -295,6 +295,31 @@ app.post('/api/admin/add-punch', authenticateToken, requireRole('admin'), async
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.post('/api/admin/reset-password', authenticateToken, requireRole('admin'), async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { username, newPassword } = req.body;
|
||||||
|
|
||||||
|
if (!username || !newPassword) {
|
||||||
|
return res.status(400).json({ message: "Username and new password are required." });
|
||||||
|
}
|
||||||
|
|
||||||
|
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
||||||
|
|
||||||
|
const result = await db.run('UPDATE users SET password = ? WHERE username = ?', [hashedPassword, username]);
|
||||||
|
|
||||||
|
if (result.changes === 0) {
|
||||||
|
return res.status(404).json({ message: "User not found." });
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({ message: `Password for ${username} has been reset successfully.` });
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Error resetting password:", err);
|
||||||
|
res.status(500).json({ message: 'Failed to reset password.' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Gets all time entries for the detailed log view
|
// Gets all time entries for the detailed log view
|
||||||
app.get('/api/admin/logs', authenticateToken, requireRole('admin'), async (req, res) => {
|
app.get('/api/admin/logs', authenticateToken, requireRole('admin'), async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user