feat: Реализован полный CRUD для админ-панели и улучшена функциональность
- Portfolio CRUD: добавление, редактирование, удаление, переключение публикации - Services CRUD: полное управление услугами с возможностью активации/деактивации - Banner system: новая модель Banner с CRUD операциями и аналитикой кликов - Telegram integration: расширенные настройки бота, обнаружение чатов, отправка сообщений - Media management: улучшенная загрузка файлов с оптимизацией изображений и превью - UI improvements: обновлённые админ-панели с rich-text редактором и drag&drop загрузкой - Database: добавлена таблица banners с полями для баннеров и аналитики
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const jwt = require('jsonwebtoken');
|
||||
const User = require('../models/User');
|
||||
const { User } = require('../models');
|
||||
|
||||
/**
|
||||
* Authentication middleware
|
||||
@@ -18,7 +18,9 @@ const authenticateToken = async (req, res, next) => {
|
||||
}
|
||||
|
||||
const decoded = jwt.verify(token, process.env.JWT_SECRET);
|
||||
const user = await User.findById(decoded.userId).select('-password');
|
||||
const user = await User.findByPk(decoded.userId, {
|
||||
attributes: { exclude: ['password'] }
|
||||
});
|
||||
|
||||
if (!user || !user.isActive) {
|
||||
return res.status(401).json({
|
||||
@@ -49,7 +51,9 @@ const authenticateSession = async (req, res, next) => {
|
||||
return res.redirect('/auth/login');
|
||||
}
|
||||
|
||||
const user = await User.findById(req.session.userId).select('-password');
|
||||
const user = await User.findByPk(req.session.userId, {
|
||||
attributes: { exclude: ['password'] }
|
||||
});
|
||||
|
||||
if (!user || !user.isActive) {
|
||||
req.session.destroy();
|
||||
@@ -115,7 +119,9 @@ const optionalAuth = async (req, res, next) => {
|
||||
try {
|
||||
// Check session first
|
||||
if (req.session.userId) {
|
||||
const user = await User.findById(req.session.userId).select('-password');
|
||||
const user = await User.findByPk(req.session.userId, {
|
||||
attributes: { exclude: ['password'] }
|
||||
});
|
||||
if (user && user.isActive) {
|
||||
req.user = user;
|
||||
res.locals.user = user;
|
||||
@@ -129,7 +135,9 @@ const optionalAuth = async (req, res, next) => {
|
||||
|
||||
if (token) {
|
||||
const decoded = jwt.verify(token, process.env.JWT_SECRET);
|
||||
const user = await User.findById(decoded.userId).select('-password');
|
||||
const user = await User.findByPk(decoded.userId, {
|
||||
attributes: { exclude: ['password'] }
|
||||
});
|
||||
|
||||
if (user && user.isActive) {
|
||||
req.user = user;
|
||||
|
||||
Reference in New Issue
Block a user