2022-03-21 23:53:22 +03:00
|
|
|
const { User } = require("../classes");
|
|
|
|
|
|
|
|
const { Router } = require("express")
|
|
|
|
const error = require("../errors/error")
|
|
|
|
|
|
|
|
const app = Router();
|
|
|
|
|
2022-04-03 21:01:55 +03:00
|
|
|
app.use(require("../middlewares/login"));
|
|
|
|
|
2022-03-21 23:53:22 +03:00
|
|
|
app.get("/", (req, res) => {
|
|
|
|
const user = new User().getId(req.session.userid)
|
|
|
|
|
2022-03-31 01:01:32 +03:00
|
|
|
if (!user.admin) return error(res, 403, "You have not got permissions for view to this page.");
|
2022-03-21 23:53:22 +03:00
|
|
|
|
|
|
|
res.render("admin", { user, user2: false })
|
2022-04-03 21:01:55 +03:00
|
|
|
});
|
2022-03-21 23:53:22 +03:00
|
|
|
|
|
|
|
app.post("/", (req, res) => {
|
|
|
|
|
|
|
|
const user = new User().getId(req.session.userid)
|
|
|
|
|
2022-03-31 01:01:32 +03:00
|
|
|
if (!user.admin) return error(res, 403, "You have not got permissions for view to this page.");
|
2022-03-21 23:53:22 +03:00
|
|
|
const user2 = new User().getId(req.body.userid)
|
|
|
|
|
|
|
|
if (!user2)
|
|
|
|
return error(res, 404, "We have not got this user in all of the forum. Vesselam.");
|
|
|
|
|
|
|
|
else {
|
|
|
|
user2.admin = true;
|
|
|
|
user2.write()
|
|
|
|
}
|
|
|
|
|
|
|
|
res.render("admin", { user, user2 })
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2022-03-31 01:01:32 +03:00
|
|
|
module.exports = app;
|