mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-12-01 06:55:45 +01:00
added changing password frontend backend
This commit is contained in:
@@ -365,4 +365,36 @@ export const updateAvailabilities = async (req: AuthRequest, res: Response): Pro
|
||||
console.error('Error updating availabilities:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
};
|
||||
|
||||
export const changePassword = async (req: AuthRequest, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { currentPassword, newPassword } = req.body;
|
||||
|
||||
// Check if employee exists and get password
|
||||
const employee = await db.get<{ password: string }>('SELECT password FROM employees WHERE id = ?', [id]);
|
||||
if (!employee) {
|
||||
res.status(404).json({ error: 'Employee not found' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify current password
|
||||
const isValidPassword = await bcrypt.compare(currentPassword, employee.password);
|
||||
if (!isValidPassword) {
|
||||
res.status(400).json({ error: 'Current password is incorrect' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Hash new password
|
||||
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
||||
|
||||
// Update password
|
||||
await db.run('UPDATE employees SET password = ? WHERE id = ?', [hashedPassword, id]);
|
||||
|
||||
res.json({ message: 'Password updated successfully' });
|
||||
} catch (error) {
|
||||
console.error('Error changing password:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
};
|
||||
@@ -710,7 +710,7 @@ export const getTemplates = async (req: Request, res: Response): Promise<void> =
|
||||
};
|
||||
|
||||
// Neue Funktion: Create from Template
|
||||
export const createFromTemplate = async (req: Request, res: Response): Promise<void> => {
|
||||
/*export const createFromTemplate = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
const { templatePlanId, name, startDate, endDate, description } = req.body;
|
||||
const userId = (req as AuthRequest).user?.userId;
|
||||
@@ -800,4 +800,4 @@ export const createFromTemplate = async (req: Request, res: Response): Promise<v
|
||||
console.error('Error creating plan from template:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
};
|
||||
};*/
|
||||
Reference in New Issue
Block a user