feat: Enhance task filtering, smart scheduling, audit logs and translations
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
+38
-1
@@ -225,7 +225,7 @@ export function setupAuth(app: Express) {
|
||||
}
|
||||
|
||||
// Valid! Clear code and login
|
||||
await storage.updateUser(user.id, { otpCode: null, otpExpiresAt: null });
|
||||
await storage.updateUser(user.id, { otpCode: null, otpExpiresAt: null, is2faEnabled: true });
|
||||
|
||||
req.login(user, (err) => {
|
||||
if (err) return next(err);
|
||||
@@ -238,6 +238,43 @@ export function setupAuth(app: Express) {
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/api/auth/2fa/generate", async (req, res) => {
|
||||
if (!req.isAuthenticated()) return res.sendStatus(401);
|
||||
const user = req.user as User;
|
||||
|
||||
// Generate and start 2FA flow
|
||||
try {
|
||||
// Enable 2FA flag
|
||||
await storage.updateUser(user.id, { is2faEnabled: true });
|
||||
|
||||
// Send initial code to verify
|
||||
const { EmailService } = await import("./email");
|
||||
const emailService = new EmailService(storage);
|
||||
const code = Math.floor(100000 + Math.random() * 900000).toString();
|
||||
const expiresAt = new Date(Date.now() + 10 * 60 * 1000);
|
||||
|
||||
await storage.updateUser(user.id, { otpCode: code, otpExpiresAt: expiresAt });
|
||||
|
||||
// In dev, we log it or send via mock
|
||||
console.log(`[2FA] Generated code for ${user.username}: ${code}`);
|
||||
await emailService.send2FACode(user, code);
|
||||
|
||||
res.json({ message: "2FA enabled. Please verify code sent to email.", debugCode: code });
|
||||
} catch (e) {
|
||||
res.status(500).json({ error: "Failed to generate 2FA" });
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/api/auth/2fa/disable", async (req, res) => {
|
||||
if (!req.isAuthenticated()) return res.sendStatus(401);
|
||||
try {
|
||||
await storage.updateUser((req.user as User).id, { is2faEnabled: false, otpCode: null, otpExpiresAt: null });
|
||||
res.json({ message: "2FA disabled" });
|
||||
} catch (e) {
|
||||
res.status(500).json({ error: "Failed to disable 2FA" });
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/api/logout", (req, res, next) => {
|
||||
req.logout((err) => {
|
||||
if (err) return next(err);
|
||||
|
||||
Reference in New Issue
Block a user