mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-26 21:30:42 +03:00
Fixes
Co-authored-by: kayraegek18 <kayraegek18@users.noreply.github.com>
This commit is contained in:
parent
1d4e04035f
commit
0fba3dca03
4 changed files with 16 additions and 19 deletions
4
index.js
4
index.js
|
@ -1,4 +1,5 @@
|
||||||
const { UserModel, BanModel } = require("./models"),
|
const { UserModel, BanModel } = require("./models"),
|
||||||
|
rateLimit = require('express-rate-limit'),
|
||||||
{ def_theme } = require("./config.json"),
|
{ def_theme } = require("./config.json"),
|
||||||
ipBlock = require('express-ip-block'),
|
ipBlock = require('express-ip-block'),
|
||||||
session = require('express-session'),
|
session = require('express-session'),
|
||||||
|
@ -8,7 +9,6 @@ const { UserModel, BanModel } = require("./models"),
|
||||||
express = require('express'),
|
express = require('express'),
|
||||||
fs = require("fs"),
|
fs = require("fs"),
|
||||||
app = express();
|
app = express();
|
||||||
const rateLimit = require('express-rate-limit')
|
|
||||||
|
|
||||||
app.ips = [];
|
app.ips = [];
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ app.use(
|
||||||
session({ secret: 'secret', resave: true, saveUninitialized: true }),
|
session({ secret: 'secret', resave: true, saveUninitialized: true }),
|
||||||
express.static("public"), express.json(), ipBlock(app.ips),
|
express.static("public"), express.json(), ipBlock(app.ips),
|
||||||
async (req, res, next) => {
|
async (req, res, next) => {
|
||||||
req.headers["x-forwarded-for"]
|
req.headers["x-forwarded-for"];
|
||||||
req.user = await UserModel.get(req.session.userID);
|
req.user = await UserModel.get(req.session.userID);
|
||||||
res.reply = (page, options = {}, status = 200) => res.status(status)
|
res.reply = (page, options = {}, status = 200) => res.status(status)
|
||||||
.render(page, { user: req.user, theme: req.user?.theme || def_theme, ...options });
|
.render(page, { user: req.user, theme: req.user?.theme || def_theme, ...options });
|
||||||
|
|
|
@ -4,7 +4,6 @@ const app = Router();
|
||||||
|
|
||||||
app.get("/", async (req, res) => {
|
app.get("/", async (req, res) => {
|
||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
mem = process.memoryUsage().heapUsed / Math.pow(2, 20),
|
mem = process.memoryUsage().heapUsed / Math.pow(2, 20),
|
||||||
users = await UserModel.count({ deleted: false }),
|
users = await UserModel.count({ deleted: false }),
|
||||||
|
|
|
@ -10,9 +10,11 @@ app.post("/", async (req, res) => {
|
||||||
|
|
||||||
const { username = null, password = null } = req.body;
|
const { username = null, password = null } = req.body;
|
||||||
|
|
||||||
if (username && password) {
|
if (!username || !password)
|
||||||
|
return res.error(400, "You forgot entering some values")
|
||||||
|
|
||||||
const user = await SecretModel.findOne({ username });
|
const user = await SecretModel.findOne({ username });
|
||||||
if (user) {
|
if (!user) return res.error(403, 'Incorrect Username and/or Password!');
|
||||||
|
|
||||||
if (!await bcrypt.compare(password, user.password)) return res.error(403, 'Incorrect Password!')
|
if (!await bcrypt.compare(password, user.password)) return res.error(403, 'Incorrect Password!')
|
||||||
const member = await UserModel.findOne({ name: username });
|
const member = await UserModel.findOne({ name: username });
|
||||||
|
@ -21,12 +23,6 @@ app.post("/", async (req, res) => {
|
||||||
req.session.userID = user.id;
|
req.session.userID = user.id;
|
||||||
|
|
||||||
res.redirect(req.query.redirect || '/');
|
res.redirect(req.query.redirect || '/');
|
||||||
} else
|
|
||||||
res.error(403, 'Incorrect Username and/or Password!')
|
|
||||||
|
|
||||||
|
|
||||||
} else
|
|
||||||
res.error(400, "You forgot entering some values")
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ app.get("/users", async (req, res) => {
|
||||||
const users = await UserModel.find({ name: { $regex: req.query.q, $options: "i" } }).limit(10);
|
const users = await UserModel.find({ name: { $regex: req.query.q, $options: "i" } }).limit(10);
|
||||||
res.reply("users", { users, page: null });
|
res.reply("users", { users, page: null });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/messages", async (req, res) => {
|
app.get("/messages", async (req, res) => {
|
||||||
if (!Object.values(req.query).length) return res.error(400, "Missing query parameters in request body.");
|
if (!Object.values(req.query).length) return res.error(400, "Missing query parameters in request body.");
|
||||||
const query = {};
|
const query = {};
|
||||||
|
@ -18,6 +19,7 @@ app.get("/messages", async (req, res) => {
|
||||||
const messages = await MessageModel.find(query).limit(10);
|
const messages = await MessageModel.find(query).limit(10);
|
||||||
res.reply("messages",{messages});
|
res.reply("messages",{messages});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/threads", async (req, res) => {
|
app.get("/threads", async (req, res) => {
|
||||||
if (!Object.values(req.query).length) return res.error(400, "Missing query parameters in request body.");
|
if (!Object.values(req.query).length) return res.error(400, "Missing query parameters in request body.");
|
||||||
const query = {};
|
const query = {};
|
||||||
|
|
Loading…
Reference in a new issue