redirect to the page after auth
This commit is contained in:
parent
0edac502e0
commit
3a47d54380
69
server.js
69
server.js
@ -336,6 +336,18 @@ function signin(req, res) {
|
|||||||
password: DB_Password,
|
password: DB_Password,
|
||||||
port: DB_Port,
|
port: DB_Port,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let templateData = {
|
||||||
|
Page: ""
|
||||||
|
};
|
||||||
|
|
||||||
|
const page = req.query.page || '';
|
||||||
|
|
||||||
|
if (page) {
|
||||||
|
templateData.Page = page;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pool.query('SELECT COUNT(*) FROM main', (error, result) => {
|
pool.query('SELECT COUNT(*) FROM main', (error, result) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('Ошибка при выполнении запроса к базе данных:', error);
|
console.error('Ошибка при выполнении запроса к базе данных:', error);
|
||||||
@ -348,7 +360,10 @@ function signin(req, res) {
|
|||||||
if (rowCount === 0) {
|
if (rowCount === 0) {
|
||||||
res.redirect('/register');
|
res.redirect('/register');
|
||||||
} else {
|
} else {
|
||||||
res.sendFile(path.join(__dirname, 'static/templates/signin.html'));
|
const source = fs.readFileSync("static/templates/signin.html", "utf8");
|
||||||
|
const template = handlebars.compile(source);
|
||||||
|
const resultT = template(templateData);
|
||||||
|
res.send(resultT);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -487,7 +502,7 @@ app.get('/logout', (req, res) => {
|
|||||||
|
|
||||||
async function live(req, res) {
|
async function live(req, res) {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=live");
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
let templateData = {
|
let templateData = {
|
||||||
@ -771,7 +786,7 @@ async function live(req, res) {
|
|||||||
|
|
||||||
app.post("/devices-geo", async (req, res) => {
|
app.post("/devices-geo", async (req, res) => {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=live");
|
||||||
}
|
}
|
||||||
const selectedDevices = req.body.devices;
|
const selectedDevices = req.body.devices;
|
||||||
|
|
||||||
@ -853,7 +868,7 @@ async function getGroupNameById(pool, groupId) {
|
|||||||
|
|
||||||
async function reports(req, res) {
|
async function reports(req, res) {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=reports");
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
let templateData = {
|
let templateData = {
|
||||||
@ -1102,7 +1117,7 @@ async function reports(req, res) {
|
|||||||
|
|
||||||
app.get("/api/devices", async (req, res) => {
|
app.get("/api/devices", async (req, res) => {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=live");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
@ -1211,11 +1226,11 @@ app.get("/api/devices", async (req, res) => {
|
|||||||
|
|
||||||
|
|
||||||
app.get('/reports/:id', async (req, res) => {
|
app.get('/reports/:id', async (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=reports/" + id);
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
const id = req.params.id;
|
|
||||||
|
|
||||||
let templateData = {
|
let templateData = {
|
||||||
SERVER_IP: process.env.SERVER_IP,
|
SERVER_IP: process.env.SERVER_IP,
|
||||||
@ -1508,11 +1523,11 @@ app.get('/reports/:id', async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/generate-pdf/:id', async (req, res) => {
|
app.get('/generate-pdf/:id', async (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=generate-pdf/" + id);
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
const id = req.params.id;
|
|
||||||
|
|
||||||
let templateData = {
|
let templateData = {
|
||||||
SERVER_IP: process.env.SERVER_IP,
|
SERVER_IP: process.env.SERVER_IP,
|
||||||
@ -1767,7 +1782,7 @@ let data = {
|
|||||||
|
|
||||||
async function devices(req, res) {
|
async function devices(req, res) {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=devices");
|
||||||
}
|
}
|
||||||
|
|
||||||
let userInfo;
|
let userInfo;
|
||||||
@ -1895,14 +1910,14 @@ async function devices(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.get('/devices/device/system/:serial', async (req, res) => {
|
app.get('/devices/device/system/:serial', async (req, res) => {
|
||||||
|
const serial = req.params.serial;
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=devices/device/system/" + serial);
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
if (!userInfo.EditTransport) {
|
if (!userInfo.EditTransport) {
|
||||||
return res.redirect("/devices");
|
return res.redirect("/devices");
|
||||||
}
|
}
|
||||||
const serial = req.params.serial;
|
|
||||||
|
|
||||||
let templateData = {
|
let templateData = {
|
||||||
SERVER_IP: process.env.SERVER_IP,
|
SERVER_IP: process.env.SERVER_IP,
|
||||||
@ -1948,14 +1963,14 @@ app.get('/devices/device/system/:serial', async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/devices/device/:serial', async (req, res) => {
|
app.get('/devices/device/:serial', async (req, res) => {
|
||||||
|
const serial = req.params.serial;
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=devices/device/" + serial);
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
if (!userInfo.EditTransport) {
|
if (!userInfo.EditTransport) {
|
||||||
return res.redirect("/devices");
|
return res.redirect("/devices");
|
||||||
}
|
}
|
||||||
const serial = req.params.serial;
|
|
||||||
|
|
||||||
let templateData = {
|
let templateData = {
|
||||||
SERVER_IP: process.env.SERVER_IP,
|
SERVER_IP: process.env.SERVER_IP,
|
||||||
@ -2084,7 +2099,7 @@ app.get('/devices/device/:serial', async (req, res) => {
|
|||||||
|
|
||||||
async function groups(req, res) {
|
async function groups(req, res) {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=devices/groups");
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
if (!userInfo.EditTransport) {
|
if (!userInfo.EditTransport) {
|
||||||
@ -2139,7 +2154,7 @@ async function groups(req, res) {
|
|||||||
|
|
||||||
app.post('/update-group', async (req, res) => {
|
app.post('/update-group', async (req, res) => {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=devices/groups");
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
if (!userInfo.EditTransport) {
|
if (!userInfo.EditTransport) {
|
||||||
@ -3307,7 +3322,7 @@ app.post("/add-group", async (req, res) => {
|
|||||||
|
|
||||||
async function update(req, res) {
|
async function update(req, res) {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=devices/update");
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
if (!userInfo.Update) {
|
if (!userInfo.Update) {
|
||||||
@ -3346,7 +3361,7 @@ async function update(req, res) {
|
|||||||
|
|
||||||
async function settings(req, res) {
|
async function settings(req, res) {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=settings");
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
let templateData = {
|
let templateData = {
|
||||||
@ -3379,10 +3394,10 @@ async function settings(req, res) {
|
|||||||
|
|
||||||
async function organisation(req, res) {
|
async function organisation(req, res) {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=admin/organisation");
|
||||||
}
|
}
|
||||||
if (req.session.userId != "admin") {
|
if (req.session.userId != "admin") {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=admin/organisation");
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
let templateData = {
|
let templateData = {
|
||||||
@ -3446,10 +3461,10 @@ app.post('/update-organisation', async (req, res) => {
|
|||||||
|
|
||||||
async function adminPanel(req, res) {
|
async function adminPanel(req, res) {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=admin");
|
||||||
}
|
}
|
||||||
if (req.session.userId != "admin") {
|
if (req.session.userId != "admin") {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=admin");
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
let templateData = {
|
let templateData = {
|
||||||
@ -3562,14 +3577,14 @@ app.post("/add-user", async (req, res) => {
|
|||||||
|
|
||||||
|
|
||||||
app.get('/admin/user/:id', async (req, res) => {
|
app.get('/admin/user/:id', async (req, res) => {
|
||||||
|
const id = req.params.id;
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=admin/user/" + id);
|
||||||
}
|
}
|
||||||
if (req.session.userId != "admin") {
|
if (req.session.userId != "admin") {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=admin/user/" + id);
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
const id = req.params.id;
|
|
||||||
|
|
||||||
let templateData = {
|
let templateData = {
|
||||||
SERVER_IP: process.env.SERVER_IP,
|
SERVER_IP: process.env.SERVER_IP,
|
||||||
@ -3794,7 +3809,7 @@ app.post("/updateuser/:id", async (req, res) => {
|
|||||||
|
|
||||||
async function videos(req, res) {
|
async function videos(req, res) {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=videos");
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
let templateData = {
|
let templateData = {
|
||||||
@ -3912,7 +3927,7 @@ async function videos(req, res) {
|
|||||||
|
|
||||||
async function videoExport(req, res) {
|
async function videoExport(req, res) {
|
||||||
if (req.session.userId === undefined) {
|
if (req.session.userId === undefined) {
|
||||||
return res.redirect("/signin");
|
return res.redirect("/signin?page=videos/export");
|
||||||
}
|
}
|
||||||
const userInfo = await getUserInfo(req.session.userId);
|
const userInfo = await getUserInfo(req.session.userId);
|
||||||
let templateData = {
|
let templateData = {
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
<div><img src="../../img/play.svg">Записи</div>
|
<div><img src="../../img/play.svg">Записи</div>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://forms.yandex.ru/cloud/6515ecda3e9d08f17262c332/" target="_blank">
|
<a href="https://forms.yandex.ru/cloud/6515ecda3e9d08f17262c332/" target="_blank">
|
||||||
<div><img src="../img/bug.svg">Собщить об ошибке</div>
|
<div><img src="../../img/bug.svg">Собщить об ошибке</div>
|
||||||
</a>
|
</a>
|
||||||
<a class="admin-panel" href="/admin">
|
<a class="admin-panel" href="/admin">
|
||||||
<div class="selected"><img src="../../img/keyboard.svg">Админка</div>
|
<div class="selected"><img src="../../img/keyboard.svg">Админка</div>
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
if (xhr.status === 200) {
|
if (xhr.status === 200) {
|
||||||
location.href = '/';
|
location.href = '/{{Page}}';
|
||||||
} else if (xhr.status === 401) {
|
} else if (xhr.status === 401) {
|
||||||
alert('Неверный логин или пароль');
|
alert('Неверный логин или пароль');
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user