feat: полный бэк и фронт (попытки, разбор, импорт, ИИ, назначения)
- Сервисы: testAttemptService, testAccess, document import/gen/extract, LLM, assignment, aiEditor - Конфиг: devAuthor, featureFlags; messages/ru; интеграция V.9 (skip без БД) - API/роуты: app, auth, server; Dockerfile и env example - Фронт: TestAttempt, TestAttemptReview, AttemptReviewBlock, стили, правки App/api/login/vite - compose и README; смоук-тесты расширены Закрывает отсутствие модулей в origin после клона. Made-with: Cursor
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
import { verifyToken } from '../utils/auth.js';
|
||||
import { query } from '../db/db.js';
|
||||
import { RU } from '../messages/ru.js';
|
||||
|
||||
/**
|
||||
* Extract token from cookie
|
||||
@@ -24,13 +25,13 @@ export async function authenticate(req, res, next) {
|
||||
const token = getTokenFromCookie(req);
|
||||
|
||||
if (!token) {
|
||||
return res.status(401).json({ error: 'Authentication required' });
|
||||
return res.status(401).json({ error: RU.authRequired });
|
||||
}
|
||||
|
||||
const decoded = verifyToken(token);
|
||||
|
||||
if (!decoded) {
|
||||
return res.status(401).json({ error: 'Invalid or expired token' });
|
||||
return res.status(401).json({ error: RU.tokenInvalid });
|
||||
}
|
||||
|
||||
const result = await query(
|
||||
@@ -39,7 +40,7 @@ export async function authenticate(req, res, next) {
|
||||
);
|
||||
|
||||
if (result.rows.length === 0) {
|
||||
return res.status(401).json({ error: 'User not found' });
|
||||
return res.status(401).json({ error: RU.userNotFound });
|
||||
}
|
||||
|
||||
const user = result.rows[0];
|
||||
@@ -59,7 +60,7 @@ export async function authenticate(req, res, next) {
|
||||
next();
|
||||
} catch (error) {
|
||||
console.error('Auth middleware error:', error);
|
||||
return res.status(500).json({ error: 'Authentication error' });
|
||||
return res.status(500).json({ error: RU.authError });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,11 +74,11 @@ export function requireRole(roles) {
|
||||
|
||||
return (req, res, next) => {
|
||||
if (!req.user) {
|
||||
return res.status(401).json({ error: 'Authentication required' });
|
||||
return res.status(401).json({ error: RU.authRequired });
|
||||
}
|
||||
|
||||
if (!allowedRoles.includes(req.user.role)) {
|
||||
return res.status(403).json({ error: 'Insufficient permissions' });
|
||||
return res.status(403).json({ error: RU.insufficientPermissions });
|
||||
}
|
||||
|
||||
next();
|
||||
@@ -93,7 +94,7 @@ export function requireRole(roles) {
|
||||
export function requireDepartment(departmentId) {
|
||||
return (req, res, next) => {
|
||||
if (!req.user) {
|
||||
return res.status(401).json({ error: 'Authentication required' });
|
||||
return res.status(401).json({ error: RU.authRequired });
|
||||
}
|
||||
|
||||
// Admins can access all departments
|
||||
@@ -103,7 +104,7 @@ export function requireDepartment(departmentId) {
|
||||
|
||||
// Managers can only access their department
|
||||
if (req.user.role === 'manager' && req.user.departmentId !== departmentId) {
|
||||
return res.status(403).json({ error: 'Access denied to this department' });
|
||||
return res.status(403).json({ error: RU.departmentAccessDenied });
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
Reference in New Issue
Block a user