feat: add self-service password change from user menu
All checks were successful
Deploy / deploy (push) Successful in 11s
All checks were successful
Deploy / deploy (push) Successful in 11s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -758,6 +758,27 @@ app.patch('/api/users/me/profile', requireAuth, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.patch('/api/users/me/password', requireAuth, async (req, res) => {
|
||||
const { currentPassword, newPassword } = req.body;
|
||||
if (!currentPassword || !newPassword) return res.status(400).json({ error: 'Current password and new password are required' });
|
||||
if (newPassword.length < 6) return res.status(400).json({ error: 'New password must be at least 6 characters' });
|
||||
|
||||
try {
|
||||
const cred = authDb.prepare('SELECT * FROM auth_credentials WHERE nocodb_user_id = ?').get(req.session.userId);
|
||||
if (!cred) return res.status(404).json({ error: 'Credentials not found' });
|
||||
|
||||
const valid = await bcrypt.compare(currentPassword, cred.password_hash);
|
||||
if (!valid) return res.status(401).json({ error: 'Current password is incorrect' });
|
||||
|
||||
const hash = await bcrypt.hash(newPassword, 10);
|
||||
authDb.prepare('UPDATE auth_credentials SET password_hash = ? WHERE nocodb_user_id = ?').run(hash, req.session.userId);
|
||||
res.json({ message: 'Password updated successfully' });
|
||||
} catch (err) {
|
||||
console.error('Change password error:', err);
|
||||
res.status(500).json({ error: 'Failed to change password' });
|
||||
}
|
||||
});
|
||||
|
||||
app.patch('/api/users/me/tutorial', requireAuth, async (req, res) => {
|
||||
try {
|
||||
await nocodb.update('Users', req.session.userId, { tutorial_completed: !!req.body.completed });
|
||||
|
||||
Reference in New Issue
Block a user