Compare commits

..

No commits in common. "bd722f1651140d7aff0752ad71c2358b8688ceef" and "fa222ad68dba1610bacc1c96266cb4022662ff2f" have entirely different histories.

12 changed files with 46 additions and 54 deletions

View file

@ -55,11 +55,10 @@ Akf-forum has got an API for AJAX (fetch), other clients etc. And, you can learn
- delete admin???
- change category name
- _id
- add support for transition around gravatar
- forum setup page++
- add support for transition aroun gravatar
### theme to do:
- add bootstrap for navbar
- theme change
- routes/api/routes/users.js check,
themes/default/extra/footer.ejs check,
themes/default/extra/meta.ejs check

View file

@ -9,7 +9,6 @@ const
app = express(),
{ mw: IP } = require('request-ip'),
{ RL } = require('./lib'),
{ themes } = require("./config.json"),
SES = require('express-session'),
MS = require("connect-mongo"),
DB = mongoose.connect(process.env.MONGO_DB_URL)
@ -34,14 +33,10 @@ app.use(express.static("public"), express.json(), express.urlencoded({ extended:
res.reply = (page, options = {}, status = 200) => res.status(status).render(page, {
dataset: {
themes,
theme: req.user?.theme || def_theme,
forum_name,
description
},
user: req.user,
...options
theme: req.user?.theme || def_theme,
lang: req.user?.theme?.language || def_theme.language,
forum_name, description, ...options
});

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "akf-forum",
"version": "4.22.1",
"version": "4.22.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "akf-forum",
"version": "4.22.1",
"version": "4.22.0",
"license": "GPL-3.0-or-later",
"dependencies": {
"bcrypt": "^5.1.0",

View file

@ -1,6 +1,6 @@
{
"name": "akf-forum",
"version": "4.22.1",
"version": "4.22.0",
"description": "A Node.js based forum software",
"main": "index.js",
"scripts": {

View file

@ -1,7 +1,7 @@
const { UserModel, BanModel } = require("../../../models");
const { Router } = require("express");
const multer = require("multer");
const { themes } = require("../../../config.json")
const app = Router();
app.param("id", async (req, res, next, id) => {
@ -37,7 +37,7 @@ app.patch("/:id", async (req, res) => {
if (req.user.id !== member.id && !user.admin) return res.error(403, "You have not got permission for this.");
if (!Object.keys(req.body).some(Boolean)) return res.error(400, "Missing member informations in request body.");
const { name, about, admin, deleted, hideLastSeen, theme } = req.body;
const { name, about, admin, deleted, hideLastSeen } = req.body;
if ((admin?.length || "deleted" in req.body) && !req.user.admin) return res.error(403, "You have not got permission for edit 'admin' and 'deleted' information, or bad request.");
const { names, desp } = req.app.get("limits");
@ -51,8 +51,7 @@ app.patch("/:id", async (req, res) => {
if (about.length > desp) return res.error(400, `About must be under ${desp} characters`);
member.about = about;
}
if (theme || themes.some(t => t.name === theme.name).includes(theme))
member.theme = theme;
// if (theme || themes.includes(theme)) member.theme = theme;
if (typeof admin === "boolean" || ["false", "true"].includes(admin)) member.admin = admin;
if (deleted === false) member.deleted = false;
@ -79,6 +78,7 @@ app.post("/:id/ban", async (req, res) => {
res.complate(member);
});
const storage = multer.diskStorage({
destination: function (_req, _file, cb) {
cb(null, './public/images/avatars')
@ -90,7 +90,7 @@ const storage = multer.diskStorage({
const upload = multer({ storage })
app.post("/:id/avatar", upload.single('avatar'), async (req, res) => {
app.put("/:id/", upload.single('avatar'), async (req, res) => {
const { member } = req;
if (req.user.id !== member.id && !req.user.admin) return res.error(403, "You have not got permission for this.");

View file

@ -10,32 +10,31 @@ app.post("/", RL(24 * 60 * 60_000, 5), async (req, res) => {
req.session.userID = null;
let { name, password, about, email } = req.body;
let { name, password, about } = req.body;
if (!name || !password || !email) return res.error(400, "You forgot entering some values");
if (!email || !emailRegEx.test(email)) return res.error(400, "E-mail is not valid");
if (!name || !password) return res.error(400, "You forgot entering some values");
const { names } = req.app.get("limits");
if (name.length < 3 || name.length > names) return res.error(400, "Name must be between 3 - 25 characters");
if (password.length < 3 || password.length > names) return res.error(400, "Password must be between 3 - 25 characters");
if (await UserModel.exists({ name })) return res.error(400, `We have got an user named ${name}!`)
if (await UserModel.exists({ email })) return res.error(400, "E-mail is already in use");
const user = new UserModel({ name });
const user = new UserModel({ name, email });
user.avatar = getGravatar(email, 128);
user.avatar = getGravatar(name, 128);
if (about) {
if (about.length > 256) return res.error(400, "about must be under 256 characters");
user.about = about;
}
await user.takeId();
await user.takeId()
if (user.id === "0")
user.admin = true;
else if (email_auth) {
const email = req.body.email;
if (!email || !emailRegEx.test(email)) return res.error(400, "E-mail is not valid");
if (await UserModel.exists({ email })) return res.error(400, "E-mail is already in use");
user.email = email;
user.email_code = await bcrypt.hash(`${Date.now()}-${Math.floor(Math.random() * 1e20)}`, 10)
transporter.sendMail({

View file

@ -16,8 +16,8 @@
form.addEventListener('submit', async e => {
e.preventDefault();
const res = await fetch('/api/users/<%= member.id %>/avatar', {
method: 'POST',
const res = await fetch('/api/users/<%= member.id %>/', {
method: 'PUT',
body: new FormData(form)
})
if (res.error) return alert(res.error);

View file

@ -1,33 +1,29 @@
<div class="footer">
<% if (user){ %>
<select id="theme_select">
<% for(const theme of dataset.themes){%>
<option value="<%= theme %>"><%= theme %> theme</option>
<% } %>
</select>
<a onclick="invert()" class="btn-primary" style="color:white;"><%=(user.theme.color === "default" ? "black" : "default" ) + " theme!" %></a>
<script>
const theme_select = document.getElementById("theme_select");
theme_select.querySelector(`option[value=<%= user.theme.name %>]`).selected = true;
theme_select.addEventListener("change", async e => {
const name = e.target.value;
async function invert() {
return alert("disabled!")
await fetch('/api/users/<%= user.id %>', {
method: 'PATCH',
body: JSON.stringify({
theme: {
name
}
theme: {color:"<%= user.theme.color === `default` ? `black` : `default` %>"}
}),
headers: {
"Content-Type": "application/json"
}
});
location.reload();
});
location.reload()
}
</script>
<% } %>
<a href="https://github.com/Akif9748/akf-forum" style="color: white;"> This website is powered by
<span style="color: #ffbf00;">akf-forum</span>
</a>
<span style="color: #ffbf00;">akf-forum</span> </a>
<div>
<span style="color:white">Coders</span> <br>
<div style="text-align:center;">
<a href="https://github.com/Akif9748/" style="color: #ffbf00;">Akif</a><br><a href="#" style="color:#ffbf00;">Tokmak</a>
</div>
</div>
</div>

View file

@ -1,9 +1,9 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= title || dataset.forum_name +"-forum" %></title>
<meta name="description" content="<%= dataset.description %>">
<title><%= title || forum_name +"-forum" %></title>
<meta name="description" content="<%= description %>">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<link rel="stylesheet" href="/css/themes/<%= dataset.theme.name %>.css" />
<link rel="stylesheet" href="/css/themes/<%= theme.name %>.css" />
<link rel="stylesheet" href="/css/common.css" />
</head>

View file

@ -1,12 +1,13 @@
<% if (user?.admin){ %>
<div class="admin-bar">
<a href="/admin" class="admin-bar">Click here to reach admin panel</a>
<a href="/admin" class="admin-bar">You are admin, and you can go your page!</a>
</div>
<% } %>
<div class="header">
<a class="logo" href="/"><%= dataset.forum_name.toUpperCase() %> <span>FORUM</span></a>
<a class="logo" href="/"><%= forum_name.toUpperCase() %> <span>FORUM</span></a>
<div class="buttons">
<% if (user){ %>

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<%- include("extra/meta", {title: "Welcome to the "+dataset.forum_name+"-forum!" }) %>
<%- include("extra/meta", {title: "Welcome to the "+forum_name+"-forum!" }) %>
<body>

View file

@ -15,7 +15,9 @@
<form action="/register" method="post">
<% if (mail) { %>
<input type="email" name="email" placeholder="Email" class="input" required>
<% } %>
<input type="text" name="name" placeholder="Username" class="input" required>
<input type="password" name="password" placeholder="Password" class="input" required>
<textarea class="input" name="about" rows="4" placeholder="About you... You can use markdown"></textarea>