Add user management for activation, deactivation, and deletion
Introduce API endpoints and storage methods for setting user passwords, soft deactivation (hiding availability), and hard deletion (removing all associated future data). Replit-Commit-Author: Agent Replit-Commit-Session-Id: 3a22ac80-cd1d-4441-9e36-f24fc2f4c3de Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3478f7c3-db8c-4fca-9165-3adbdf1b5829/3a22ac80-cd1d-4441-9e36-f24fc2f4c3de/gBqmpbl
This commit is contained in:
+51
-5
@@ -605,13 +605,11 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
firstName: firstName || '',
|
||||
lastName: lastName || '',
|
||||
displayName: displayName || `${firstName || ''} ${lastName || ''}`.trim(),
|
||||
role: 'dj' as const,
|
||||
isActive: true,
|
||||
tempPassword, // Store temporarily - will be removed after first login
|
||||
needsPasswordChange: true
|
||||
password: tempPassword,
|
||||
isTemporary: true
|
||||
};
|
||||
|
||||
const user = await storage.createUser(userData);
|
||||
const user = await storage.createUserWithPassword(userData);
|
||||
|
||||
res.json({
|
||||
message: "User created successfully",
|
||||
@@ -623,6 +621,54 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
// Set/change user password
|
||||
app.post('/api/users/:id/set-password', isAuthenticated, isAdmin, async (req, res) => {
|
||||
try {
|
||||
const { password, isTemporary } = req.body;
|
||||
if (!password) {
|
||||
return res.status(400).json({ message: "Password is required" });
|
||||
}
|
||||
await storage.setUserPassword(req.params.id, password, isTemporary || false);
|
||||
res.json({ message: "Password updated successfully" });
|
||||
} catch (error) {
|
||||
console.error("Error setting user password:", error);
|
||||
res.status(500).json({ message: "Failed to set user password" });
|
||||
}
|
||||
});
|
||||
|
||||
// Soft deactivate user (hide from scheduling but keep data)
|
||||
app.post('/api/users/:id/deactivate-soft', isAuthenticated, isAdmin, async (req, res) => {
|
||||
try {
|
||||
await storage.deactivateUserSoft(req.params.id);
|
||||
res.json({ message: "User deactivated successfully (data preserved)" });
|
||||
} catch (error) {
|
||||
console.error("Error deactivating user:", error);
|
||||
res.status(500).json({ message: "Failed to deactivate user" });
|
||||
}
|
||||
});
|
||||
|
||||
// Hard delete user (remove user and future data)
|
||||
app.delete('/api/users/:id/delete-hard', isAuthenticated, isAdmin, async (req, res) => {
|
||||
try {
|
||||
await storage.deleteUserHard(req.params.id);
|
||||
res.json({ message: "User and associated future data deleted successfully" });
|
||||
} catch (error) {
|
||||
console.error("Error deleting user:", error);
|
||||
res.status(500).json({ message: "Failed to delete user" });
|
||||
}
|
||||
});
|
||||
|
||||
// Get user active status
|
||||
app.get('/api/users/:id/active-status', isAuthenticated, isAdmin, async (req, res) => {
|
||||
try {
|
||||
const isActive = await storage.getUserActiveStatus(req.params.id);
|
||||
res.json({ isActive });
|
||||
} catch (error) {
|
||||
console.error("Error checking user active status:", error);
|
||||
res.status(500).json({ message: "Failed to check user status" });
|
||||
}
|
||||
});
|
||||
|
||||
// Statistics routes
|
||||
app.get('/api/stats/dashboard', isAuthenticated, async (req: any, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user