mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-26 05:10:41 +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"),
|
||||
rateLimit = require('express-rate-limit'),
|
||||
{ def_theme } = require("./config.json"),
|
||||
ipBlock = require('express-ip-block'),
|
||||
session = require('express-session'),
|
||||
|
@ -8,7 +9,6 @@ const { UserModel, BanModel } = require("./models"),
|
|||
express = require('express'),
|
||||
fs = require("fs"),
|
||||
app = express();
|
||||
const rateLimit = require('express-rate-limit')
|
||||
|
||||
app.ips = [];
|
||||
|
||||
|
@ -22,7 +22,7 @@ app.use(
|
|||
session({ secret: 'secret', resave: true, saveUninitialized: true }),
|
||||
express.static("public"), express.json(), ipBlock(app.ips),
|
||||
async (req, res, next) => {
|
||||
req.headers["x-forwarded-for"]
|
||||
req.headers["x-forwarded-for"];
|
||||
req.user = await UserModel.get(req.session.userID);
|
||||
res.reply = (page, options = {}, status = 200) => res.status(status)
|
||||
.render(page, { user: req.user, theme: req.user?.theme || def_theme, ...options });
|
||||
|
|
|
@ -4,7 +4,6 @@ const app = Router();
|
|||
|
||||
app.get("/", async (req, res) => {
|
||||
|
||||
|
||||
const
|
||||
mem = process.memoryUsage().heapUsed / Math.pow(2, 20),
|
||||
users = await UserModel.count({ deleted: false }),
|
||||
|
|
|
@ -10,9 +10,11 @@ app.post("/", async (req, res) => {
|
|||
|
||||
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 });
|
||||
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!')
|
||||
const member = await UserModel.findOne({ name: username });
|
||||
|
@ -21,12 +23,6 @@ app.post("/", async (req, res) => {
|
|||
req.session.userID = user.id;
|
||||
|
||||
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);
|
||||
res.reply("users", { users, page: null });
|
||||
});
|
||||
|
||||
app.get("/messages", async (req, res) => {
|
||||
if (!Object.values(req.query).length) return res.error(400, "Missing query parameters in request body.");
|
||||
const query = {};
|
||||
|
@ -18,6 +19,7 @@ app.get("/messages", async (req, res) => {
|
|||
const messages = await MessageModel.find(query).limit(10);
|
||||
res.reply("messages",{messages});
|
||||
});
|
||||
|
||||
app.get("/threads", async (req, res) => {
|
||||
if (!Object.values(req.query).length) return res.error(400, "Missing query parameters in request body.");
|
||||
const query = {};
|
||||
|
|
Loading…
Reference in a new issue