Clear online guest, new dc username

This commit is contained in:
Akif9748 2023-08-27 20:22:28 +03:00
parent aace4c6fd4
commit 00ea899fb4
17 changed files with 80 additions and 33635 deletions

View file

@ -44,8 +44,6 @@ Akf-forum has got an API for AJAX (fetch), other clients etc. And, you can learn
![image](https://github.com/Akif9748/akf-forum/assets/70021050/1ad4ad8e-d000-46a6-834e-7d76cdddda60)
## TO-DO list
#### Add used modules etc like: cropper:
https://github.com/akashgiricse/Online-Forum
### Backend:
#### Feature:
@ -62,18 +60,17 @@ permissions: ["see_deleted_message"]
#### Fixes:
- Admin deleting other admins.
- send public to common/public
- disable caching
#### ETC:
- Rewrite apidocs
- Add a feature list to README.md
- add used open source libraries to README.md
### Frontend
#### Features:
- change category name
- Add approval threads page.
- add support for trans around gravatar and upload photo
- add support for switch around gravatar and upload photo
- old contents / titles add to forum interface
- who liked a message
- add ban button to user profile
@ -87,9 +84,10 @@ permissions: ["see_deleted_message"]
- text alling center body
- thread.js unfuction only listener
## We used:
## Special Thanks:
https://github.com/akashgiricse/Online-Forum for bootstrap theme.
@Tokmak for old frontend.
https://fengyuanchen.github.io/cropperjs/examples/crop-a-round-image.html for avatar upload panel.
## Major Version History
- V5: Enchanted Themes
- V4: Caching

View file

@ -13,7 +13,7 @@
},
"global_ratelimit": {
"enabled": true,
"max": 25,
"max": 30,
"windowMs": 60000
},
"discord_auth": false,

View file

@ -20,6 +20,15 @@ const
app.ips = [];
app.onlines = new Map();
setInterval(() => {
const now = Date.now();
for (const [ip, lastSeen] of app.onlines.entries())
if (now - lastSeen > 1000 * 60 * 5)
app.onlines.delete(ip);
}, 1000 * 60 * 5);
app.set("view engine", "ejs");
app.set("limits", limits);
@ -32,16 +41,19 @@ app.use(express.static(join(__dirname, "public")), express.json(), express.urlen
async (req, res, next) => {
if (app.ips.includes(req.clientIp)) return res.status(403).send("You are banned from this forum.");
const lastSeen = Date.now();
req.user = req.session.userID ? await UserModel.findOneAndUpdate({ id: req.session.userID }, {
lastSeen: Date.now(), $addToSet: { ips: req.clientIp }
lastSeen, $addToSet: { ips: req.clientIp }
}) : null;
app.onlines.set(req.clientIp, lastSeen);
let theme = req.user?.theme || def_theme;
if (!themes.some(t => t.codename === theme.codename))
theme = def_theme;
res.reply = (page, options = {}, status = 200) => {
const road = join(__dirname, "themes", theme.codename, "views", `${page}.ejs`);
const renderpage = fs.existsSync(road) ? road : join(__dirname, "themes", "common", "views", `${page}.ejs`);

View file

@ -35,6 +35,7 @@ schema.virtual("active").get(function () {
})
schema.methods.takeId = async function () {
// eslint-disable-next-line no-use-before-define
this.id = String(await model.count() || 0);
return this;
}

View file

@ -1,11 +1,10 @@
const UserModel = require("./User");
const UserCache = [];
const UserCache = new Map();
module.exports.getAuthor = async function () {
const id = this.authorID || this.author?.id;
let user = UserCache.find(user => user?.id == id)
let user = UserCache.get(id);
if (!user)
UserCache.push(user = await UserModel.findOne({ id }))
UserCache.set(user = await UserModel.findOne({ id }));
if (!this.get('authorID', null, { getters: false })) {
this.authorID = user.id;

View file

@ -1,11 +1,11 @@
const { UserModel, ThreadModel, MessageModel, CategoryModel } = require("../models")
const { UserModel, ThreadModel, MessageModel, CategoryModel } = require("../models");
const { Router } = require("express");
const app = Router();
app.get("/", async (req, res) => {
const [
categories, users, threads, messages, newestMember, newestMessages, newestThreads, onlineUserCount, onlineUsers
categories, users, threads, messages, newestMember, newestMessages, newestThreads, onlineMemberCount, onlineMembers
] = await Promise.all([
CategoryModel.count(),
UserModel.count({ deleted: false }),
@ -16,13 +16,14 @@ app.get("/", async (req, res) => {
ThreadModel.find({ state: "OPEN" }).sort({ time: -1 }).limit(10),
UserModel.count({ deleted: false, lastSeen: { $gt: Date.now() - 1000 * 60 * 5 } }),
UserModel.find({ deleted: false, hideLastSeen: false, lastSeen: { $gt: Date.now() - 1000 * 60 * 5 } }, "name id")
])
]),
onlineTotal = req.app.onlines.size,
onlineGuests = onlineTotal - onlineMemberCount;
res.reply("index", {
categories, users, threads, messages,
newestMember, newestMessages, newestThreads,
onlineUserCount, onlineUsers
onlineMemberCount, onlineMembers, onlineGuests, onlineTotal
});
});

View file

@ -53,8 +53,8 @@ app.get("/discord", async (req, res) => {
return res.redirect("/");
}
let name = discord.username + discord.discriminator;
while (await UserModel.findOne({ name }))
let name = discord.username;
while (await UserModel.exists({ name }))
name += Math.floor(Math.random() * 2);
const user2 = new UserModel({

View file

@ -103,18 +103,36 @@
<div class="card mb-3 mb-sm-0 mb-xl-3">
<div class="card-body">
<h2 class="h4 card-title">Members online</h2>
<style>
li.d-inline ~ li.d-inline::before {
content: ', ';
}
</style>
<ul class="list-unstyled mb-0">
<li>
<% onlineUsers.forEach(user => { %>
<% onlineMembers.slice(0, 30).forEach(user => { %>
<li class="d-inline">
<a href="/users/<%=user.id %>"><%= user.name %></a>
<% }); %>
</li>
<% }); %>
<% if (onlineMemberCount > 30) { %>
<li>
<a href="/users/"><%= onlineMemberCount - 30 %></a> more...
</li>
<% } %>
</ul>
</div>
<div class="card-footer">
<dl class="row mb-0">
<dt class="col-8">Total:</dt>
<dd class="col-4 mb-0"><%= onlineUserCount %></dd>
<dd class="col-4 mb-0"><%= onlineTotal %></dd>
</dl>
<dl class="row mb-0">
<dt class="col-8">Members:</dt>
<dd class="col-4 mb-0"><%= onlineMemberCount %></dd>
</dl>
<dl class="row mb-0">
<dt class="col-8">Guests:</dt>
<dd class="col-4 mb-0"><%= onlineGuests %></dd>
</dl>
</div>
</div>
@ -142,7 +160,7 @@
</div>
<div class="card-footer">
<div>Newest member:</div>
<div><a href="/users/<% newestMember.id %>"><%= newestMember.name %></a></div>
<div><a href="/users/<%= newestMember.id %>"><%= newestMember.name %></a></div>
</div>
</div>
</div>

View file

@ -1,6 +0,0 @@
module.exports = {
name: "Xenforo Black Theme",
codename: "xenforo",
description: "Xenforo theme by xenforo, and edited by Akif9748",
author: "Akif9748"
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,47 +0,0 @@
<!DOCTYPE html>
<html id="XF" lang="tr-TR" dir="LTR" data-app="public" data-template="forum_list" data-container-key data-content-key data-logged-in="true" data-cookie-prefix="xf_" data-csrf="1685091272,f052c88e4c4aa12fbe73a08e269625fa" class="has-no-js v_2_0 template-forum_list">
<%- include("extra/meta", {title: "Error" }) %>
<body data-template="forum_list">
<div class="p-pageWrapper" id="top">
<%- include(dataset.getFile(dataset.theme.codename +"/views/extra/navbar")) %>
<div class="p-body">
<div class="p-body-inner">
<div class="p-body-header">
<div class="p-title ">
<h1 class="p-title-value">Hay aksi! Bir sorun yaşıyoruz.</h1>
</div>
</div>
<div class="p-body-main ">
<div class="p-body-contentCol"></div>
<div class="p-body-content">
<div class="p-body-pageContent">
<div class="blockMessage">
İstenen sayfa bulunamadı.
</div>
</div>
</div>
</div>
<ul class="p-breadcrumbs p-breadcrumbs--bottom" itemscope="" itemtype="https://schema.org/BreadcrumbList">
<li itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem">
<a href="https://makale.silicone-forum.com" itemprop="item">
<span itemprop="name">Ana sayfa</span>
</a>
<meta itemprop="position" content="1">
</li>
</ul>
</div>
</div>
<%- include(dataset.getFile(dataset.theme.codename +"/views/extra/footer")) %>
</div>
<div class="u-scrollButtons js-scrollButtons" data-trigger-type="up">
<a href="#top" class="button--scroll button" data-xf-click="scroll-to"><span class="button-text"><i class="fa--xf far fa-arrow-up" aria-hidden="true"></i><span class="u-srOnly">Top</span></span></a>
</div>
</body>
</html>

View file

@ -1,64 +0,0 @@
<footer class="p-footer" id="footer">
<div class="p-footer-inner">
<div class="p-footer-row">
<div class="p-footer-row-main">
<ul class="p-footer-linkList">
<li>
<% if (user){ %>
<select id="theme_select">
<% for(const theme of dataset.themes){%>
<option value="<%= theme.codename %>"><%= theme.name %></option>
<% } %>
</select>
<script>
const theme_select = document.getElementById("theme_select");
theme_select.querySelector(`option[value=<%= user.theme.codename %>]`).selected = true;
theme_select.addEventListener("change", async e => {
const codename = e.target.value;
await fetch('/api/users/<%= user.id %>', {
method: 'PATCH',
body: JSON.stringify({
theme: {
codename
}
}),
headers: {
"Content-Type": "application/json"
}
});
const theme = await fetch("/api/themes/" + codename).then(res => res.json());
const txt = "Theme changed to:\n" +
"Name: " + theme.name + "\n" +
"Description: " + theme.description + "\n" +
"Author: " + theme.author + "\n";
alert(txt)
location.reload();
});
</script>
<% } %>
</li>
</ul>
</div>
<div class="p-footer-row-opposite">
<ul class="p-footer-linkList">
<li><a href="/">Ana sayfa</a></li>
</ul>
</div>
</div>
<div class="p-footer-copyright">
Xenforo theme created <a href="https://xenforo.com" class="u-concealed" dir="ltr" target="_blank" rel="sponsored noopener">by XenForo<sup>&reg;</sup> </a>
and <a href="https://github.com/Akif9748"> edited by Akif9748</a>
<br>This website is powered by <a class="text-white" href="https://github.com/Akif9748/akf-forum">akf-forum</a>
</div>
</div>
</footer>
<footer class="text-center text-white fixed-bottom">
<div class="text-center p-3">
</div>
</footer>

View file

@ -1,20 +0,0 @@
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title><%= title || dataset.forum_name %></title>
<meta name="theme-color" content="#1e1e1e" />
<meta name="apple-mobile-web-app-title" content="Silicone">
<link rel="alternate" type="application/rss+xml" title="RSS feed for <%= title || dataset.forum_name %>" href="/bolum/-/index.rss" />
<meta property="og:site_name" content="<%= title || dataset.forum_name %>" />
<meta property="og:type" content="website" />
<meta property="og:title" content="<%= title || dataset.forum_name %>" />
<meta property="twitter:title" content="<%= title || dataset.forum_name %>" />
<meta name="description" content="<%= dataset.description %>">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<meta property="og:description" content="<%= dataset.description %>" />
<meta property="twitter:description" content="<%= dataset.description %>" />
<link rel="stylesheet" href="/themes/xenforo/s1.css" />
<link rel="stylesheet" href="/themes/xenforo/s2.css" />
</head>

View file

@ -1,95 +0,0 @@
<header class="p-header" id="header">
<div class="p-header-inner">
<div class="p-header-content">
<a style="font-size: 40px;" href="/"><%= dataset.forum_name.toUpperCase() %></a>
</div>
</div>
</header>
<div class="p-navSticky p-navSticky--primary" data-xf-init="sticky-header">
<nav class="p-nav">
<div class="p-nav-inner">
<button type="button" class="button--plain p-nav-menuTrigger button" data-xf-click="off-canvas" data-menu=".js-headerOffCanvasMenu" tabindex="0" aria-label="Menü"><span class="button-text">
<i aria-hidden="true"></i>
</span></button>
<div class="p-nav-scroller hScroller" data-xf-init="h-scroller" data-auto-scroll=".p-navEl.is-selected">
<div class="hScroller-scroll">
<ul class="p-nav-list js-offCanvasNavSource">
<li>
<div class="p-navEl">
<a class="p-navEl-link p-navEl-link--splitMenu " href="/threads/create/">Create Thread</a>
</div>
</li>
<li>
<div class="p-navEl">
<a class="p-navEl-link p-navEl-link--splitMenu " href="/categories">Categories</a>
</div>
</li>
<li>
<div class="p-navEl">
<a class="p-navEl-link p-navEl-link--splitMenu " href="/threads">Threads</a>
</div>
</li>
<li>
<div class="p-navEl">
<a class="p-navEl-link p-navEl-link--splitMenu " href="/users">Users</a>
</div>
</li>
<li>
<div class="p-navEl">
<a class="p-navEl-link p-navEl-link--splitMenu " href="/search">Search</a>
</div>
</li>
<li>
<div class="p-navEl">
<a class="p-navEl-link p-navEl-link--splitMenu " href="/login">Logout</a>
</div>
</li>
<script>
const menuItems = document.getElementsByClassName("p-navEl");
for (let i = 0; i < menuItems.length; i++)
if (window.location.pathname.includes(menuItems[i].children[0].getAttribute("href"))) {
menuItems[i].classList.add("is-selected");
break;
}
</script>
</ul>
</div>
</div>
<div class="p-nav-opposite">
<div class="p-navgroup p-account p-navgroup--member">
<a href="<%=user.getLink()%>" class="p-navgroup-link p-navgroup-link--iconic p-navgroup-link--user" data-xf-click="menu" data-xf-key="m" data-menu-pos-ref="< .p-navgroup" title="Akif" aria-expanded="false" aria-haspopup="true">
<span class="avatar avatar--xxs" data-user-id="116">
<img src="<%=user.avatar %>" alt="Akif" class="avatar-u116-s" width="48" height="48" loading="lazy" />
</span>
<span class="p-navgroup-linkText"><%=user.name %></span>
</a>
</div>
<div class="p-navgroup p-discovery">
<a href="/search" class="p-navgroup-link p-navgroup-link--iconic p-navgroup-link--search" data-xf-click="menu" data-xf-key="/" aria-label="Ara" aria-expanded="false" aria-haspopup="true" title="Ara">
<i aria-hidden="true"></i>
<span class="p-navgroup-linkText">Ara</span>
</a>
</div>
</div>
</div>
</nav>
</div>
<% if (user?.admin){ %>
<div class="p-sectionLinks">
<div class="p-sectionLinks-inner hScroller" data-xf-init="h-scroller">
<div class="hScroller-scroll">
<ul class="p-sectionLinks-list">
<li>
<div class="p-navEl ">
<a href="/admin" class="p-navEl-link ">Admin Page</a>
</div>
</li>
</ul>
</div>
</div>
</div>
<% } %>

View file

@ -1,146 +0,0 @@
<!DOCTYPE html>
<html id="XF">
<%- include("extra/meta", {title: "Welcome to the "+dataset.forum_name+"-forum!" }) %>
<body data-template="forum_list">
<div class="p-pageWrapper" id="top">
<%- include(dataset.getFile(dataset.theme.codename +"/views/extra/navbar")) %>
<div class="p-body">
<div class="p-body-inner">
<div class="p-body-header">
<div class="p-title ">
<h1 class="p-title-value"><%=dataset.forum_name%></h1>
<div class="p-title-pageAction">
<a href="/threads/create" class="button--cta button button--icon button--icon--write" data-xf-click="overlay" rel="nofollow"><span class="button-text">
Create Thread
</span></a>
</div>
</div>
</div>
<div class="p-body-main p-body-main--withSidebar ">
<div class="p-body-contentCol"></div>
<div class="p-body-sidebarCol"></div>
<div class="p-body-content">
<div class="p-body-pageContent">
<div class="block" data-widget-id="24" data-widget-key="new_threads_ust" data-widget-definition="new_threads">
<div class="block-container">
<h3 class="block-header">
<a href="/threads" rel="nofollow">New Threads</a>
</h3>
<div class="block-body">
<div class="structItemContainer">
<% newestThreads.forEach(thread => { %>
<div class="structItem structItem--thread js-inlineModContainer js-threadListItem-14359" data-author="ercncavs">
<div class="structItem-cell structItem-cell--icon">
<div class="structItem-iconContainer">
<a href="" class="avatar avatar--s" data-xf-init="member-tooltip">
<img src="<%= thread.author.avatar %>" class="avatar-u1804-s" width="48" height="48" loading="lazy" />
</a>
</div>
</div>
<div class="structItem-cell structItem-cell--main" data-xf-init="touch-proxy">
<div class="structItem-title">
<a href="<%= thread.getLink() %>" data-tp-primary="on" data-xf-init="preview-tooltip"><%= thread.title %></a>
</div>
<div class="structItem-minor">
<ul class="structItem-parts">
<li>
<a href="/users/<%= thread.authorID %>" class="username " dir="auto" data-user-id="1804" data-xf-init="member-tooltip">
<%= thread.author.name %>
</a>
</li>
<li class="structItem-startDate">
<a>
<time class="u-dt"><%= new Date(thread.time).toLocaleString() %></time>
</a>
</li>
<li><a href="/categories/<%= thread.categoryID %>"><%= thread.categoryID %></a></li>
</ul>
</div>
</div>
<div class="structItem-cell structItem-cell--meta" title="İlk mesajın ifade puanı: 0">
<dl class="pairs pairs--justified">
<dt>Messages</dt>
<dd><%= thread.messages.length %></dd>
</dl>
<dl class="pairs pairs--justified structItem-minor">
<dt>Views</dt>
<dd><%= thread.views %></dd>
</dl>
</div>
</div>
<% }) %>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="p-body-sidebar">
<div class="block" data-widget-section="onlineNow" data-widget-id="6" data-widget-key="forum_overview_members_online" data-widget-definition="members_online">
<div class="block-container">
<h3 class="block-minorHeader"><a href="/">Online Members</a></h3>
<div class="block-body">
<div class="block-row block-row--minor">
<ul class="listInline listInline--comma">
<% onlineUsers.forEach(user => { %>
<li><a href="/users/<%=user.id %>" class="username " dir="auto" data-user-id="116" data-xf-init="member-tooltip"><%= user.name %></a></li>
<% }); %>
</ul>
</div>
</div>
<div class="block-footer">
<span class="block-footer-counter">Total: <%= onlineUserCount %>
</span>
</div>
</div>
</div>
<div class="block" data-widget-id="9" data-widget-key="forum_overview_forum_statistics" data-widget-definition="forum_statistics">
<div class="block-container">
<h3 class="block-minorHeader">Forum statistics</h3>
<div class="block-body block-row">
<dl class="pairs pairs--justified">
<dt>Total categories</dt>
<dd><%= categories %></dd>
</dl>
<dl class="pairs pairs--justified">
<dt>Total threads</dt>
<dd><%= threads %></dd>
</dl>
<dl class="pairs pairs--justified">
<dt>Total messages</dt>
<dd><%= messages %></dd>
</dl>
<dl class="pairs pairs--justified">
<dt>Total members</dt>
<dd><%= users %></dd>
</dl>
<dl class="pairs pairs--justified">
<dt>Newest member</dt>
<dd><a href="/users/<% newestMember.id %>" class="username " dir="auto" data-xf-init="member-tooltip"><%= newestMember.name %></a></dd>
</dl>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<%- include(dataset.getFile(dataset.theme.codename +"/views/extra/footer")) %>
</div>
</body>
</html>

File diff suppressed because it is too large Load diff