v2: убраны v2_ префиксы сессии — user/adminMode/token как в основном коде
This commit is contained in:
+12
-12
@@ -13,10 +13,10 @@ function createUserRouter() {
|
||||
// ── GET / — главная: список записей + форма ────────────────────────────
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const clId = req.v2_clientId;
|
||||
const allCompanies = req.v2_profiles.length > 0
|
||||
? req.v2_profiles
|
||||
: [{ client_id: clId, company_name: req.v2_companyName || clId }];
|
||||
const clId = req.clientId;
|
||||
const allCompanies = req.profiles.length > 0
|
||||
? req.profiles
|
||||
: [{ client_id: clId, company_name: req.companyName || clId }];
|
||||
|
||||
const company = await q.getOrCreateCompany(clId, allCompanies.find(c => c.client_id === clId)?.company_name || clId);
|
||||
const includeDeleted = req.query.deleted === '1';
|
||||
@@ -26,11 +26,11 @@ function createUserRouter() {
|
||||
|
||||
// Переключение компании
|
||||
if (req.query.switchTo && allCompanies.find(c => c.client_id === req.query.switchTo)) {
|
||||
req.session.v2_user.activeClientId = req.query.switchTo;
|
||||
req.session.user.activeClientId = req.query.switchTo;
|
||||
return res.redirect('/v2/app');
|
||||
}
|
||||
|
||||
res.send(renderPage({ entries, company, limit, used, allCompanies, clId, user: req.v2_user, includeDeleted }));
|
||||
res.send(renderPage({ entries, company, limit, used, allCompanies, clId, user: req.user, includeDeleted }));
|
||||
} catch (e) {
|
||||
res.status(500).send('<h2>Ошибка</h2><pre>' + e.message + '</pre><a href="/v2/app">Назад</a>');
|
||||
}
|
||||
@@ -39,9 +39,9 @@ function createUserRouter() {
|
||||
// ── POST /add ───────────────────────────────────────────────────────────
|
||||
router.post('/add', async (req, res) => {
|
||||
try {
|
||||
const clId = req.v2_clientId;
|
||||
const clId = req.clientId;
|
||||
const company = await q.getOrCreateCompany(clId, clId);
|
||||
const result = await q.createEntry(company.id, req.body.cidr || '', req.body.comment || '', req.v2_email, req.v2_impersonatedBy);
|
||||
const result = await q.createEntry(company.id, req.body.cidr || '', req.body.comment || '', req.email, req.impersonatedBy);
|
||||
const msg = result.wasNormalized ? 'Добавлено (адрес нормализован)' : 'Добавлено';
|
||||
res.redirect('/v2/app?msg=' + encodeURIComponent(msg));
|
||||
} catch (e) {
|
||||
@@ -52,9 +52,9 @@ function createUserRouter() {
|
||||
// ── POST /edit/:id ──────────────────────────────────────────────────────
|
||||
router.post('/edit/:id', async (req, res) => {
|
||||
try {
|
||||
const clId = req.v2_clientId;
|
||||
const clId = req.clientId;
|
||||
const company = await q.getOrCreateCompany(clId, clId);
|
||||
const result = await q.updateEntry(parseInt(req.params.id), company.id, req.body.cidr || '', req.body.comment || '', req.v2_email, req.v2_impersonatedBy);
|
||||
const result = await q.updateEntry(parseInt(req.params.id), company.id, req.body.cidr || '', req.body.comment || '', req.email, req.impersonatedBy);
|
||||
const msg = result.wasNormalized ? 'Изменено (адрес нормализован)' : 'Изменено';
|
||||
res.redirect('/v2/app?msg=' + encodeURIComponent(msg));
|
||||
} catch (e) {
|
||||
@@ -65,9 +65,9 @@ function createUserRouter() {
|
||||
// ── POST /delete/:id ────────────────────────────────────────────────────
|
||||
router.post('/delete/:id', async (req, res) => {
|
||||
try {
|
||||
const clId = req.v2_clientId;
|
||||
const clId = req.clientId;
|
||||
const company = await q.getOrCreateCompany(clId, clId);
|
||||
await q.deleteEntry(parseInt(req.params.id), company.id, req.v2_email, req.v2_impersonatedBy);
|
||||
await q.deleteEntry(parseInt(req.params.id), company.id, req.email, req.impersonatedBy);
|
||||
res.redirect('/v2/app?msg=Удалено');
|
||||
} catch (e) {
|
||||
res.redirect('/v2/app?error=' + encodeURIComponent(e.message));
|
||||
|
||||
Reference in New Issue
Block a user