mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-22 20:10:40 +03:00
Added last seen info
This commit is contained in:
parent
e0e6dadc14
commit
3a78fd4f6c
7 changed files with 19 additions and 11 deletions
|
@ -42,7 +42,6 @@ Akf-forum has got an API for AJAX (fetch), other clients etc. And, you can learn
|
||||||
- Navbar manuel select
|
- Navbar manuel select
|
||||||
- Version info to footer
|
- Version info to footer
|
||||||
- upload other photos, model for it
|
- upload other photos, model for it
|
||||||
- black theme is broken
|
|
||||||
|
|
||||||
## Major Version History
|
## Major Version History
|
||||||
- V4: Caching
|
- V4: Caching
|
||||||
|
|
5
index.js
5
index.js
|
@ -22,8 +22,9 @@ 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"];
|
if (req.session.userID)
|
||||||
req.user = await UserModel.get(req.session.userID);
|
req.user = await UserModel.findOneAndUpdate({ id: req.session.userID }, { lastSeen: Date.now() });
|
||||||
|
|
||||||
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, forum_name, desp, ...options });
|
.render(page, { user: req.user, theme: req.user?.theme || def_theme, forum_name, desp, ...options });
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,9 @@ const schema = new mongoose.Schema({
|
||||||
edited: { type: Boolean, default: false },
|
edited: { type: Boolean, default: false },
|
||||||
about: { type: String, default: "" },
|
about: { type: String, default: "" },
|
||||||
admin: { type: Boolean, default: false },
|
admin: { type: Boolean, default: false },
|
||||||
theme: { type: String, default: def_theme }
|
theme: { type: String, default: def_theme },
|
||||||
|
lastSeen: { type: Date, default: Date.now,select:false },
|
||||||
|
hideLastSeen: { type: Boolean, default: false }
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -25,6 +27,6 @@ schema.methods.getLink = function (id = this.id) {
|
||||||
|
|
||||||
const model = mongoose.model('user', schema);
|
const model = mongoose.model('user', schema);
|
||||||
|
|
||||||
model.get = id => model.findOne({ id });
|
model.get = (id,select) => model.findOne({ id }).select(select);
|
||||||
|
|
||||||
module.exports = model;
|
module.exports = model;
|
|
@ -20,12 +20,12 @@ app.get("/", async (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/:id", async (req, res) => {
|
app.get("/:id", async (req, res) => {
|
||||||
const {category} = req;
|
const { category } = req;
|
||||||
res.complate(category);
|
res.complate(category);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.patch("/:id", async (req, res) => {
|
app.patch("/:id", async (req, res) => {
|
||||||
const {category} = req;
|
const { category } = req;
|
||||||
if (req.body.name) category.name = req.body.name;
|
if (req.body.name) category.name = req.body.name;
|
||||||
if (req.body.desp) category.name = req.body.name;
|
if (req.body.desp) category.name = req.body.name;
|
||||||
res.complate(await category.save());
|
res.complate(await category.save());
|
||||||
|
@ -36,7 +36,7 @@ app.delete("/:id", async (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/", async (req, res) => {
|
app.post("/", async (req, res) => {
|
||||||
const {name,desp} = req.body;
|
const { name, desp } = req.body;
|
||||||
if (!name) return res.error(400, "You have to give a name for the category.");
|
if (!name) return res.error(400, "You have to give a name for the category.");
|
||||||
|
|
||||||
if (await CategoryModel.exists({ name })) return res.error(400, "This category is already opened.");
|
if (await CategoryModel.exists({ name })) return res.error(400, "This category is already opened.");
|
||||||
|
|
|
@ -6,7 +6,7 @@ const multer = require("multer");
|
||||||
const app = Router();
|
const app = Router();
|
||||||
|
|
||||||
app.param("id", async (req, res, next, id) => {
|
app.param("id", async (req, res, next, id) => {
|
||||||
req.member = await UserModel.get(id);
|
req.member = await UserModel.get(id, req.user.admin ? "+lastSeen": "");
|
||||||
|
|
||||||
if (!req.member) return res.error(404, `We don't have any user with id ${id}.`);
|
if (!req.member) return res.error(404, `We don't have any user with id ${id}.`);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ app.get("/:id/avatar", async (req, res) => {
|
||||||
app.get("/:id", async (req, res) => {
|
app.get("/:id", async (req, res) => {
|
||||||
const user = req.user
|
const user = req.user
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
const member = await UserModel.get(id);
|
const member = await UserModel.get(id,"+lastSeen");
|
||||||
|
|
||||||
if (member && (user?.admin || !member.deleted)) {
|
if (member && (user?.admin || !member.deleted)) {
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,12 @@ color: var(--anti);
|
||||||
<h2 class="box-title">Created at:</h2>
|
<h2 class="box-title">Created at:</h2>
|
||||||
<h2 class="box-value"><%= new Date(member.time).toLocaleString() %></h2>
|
<h2 class="box-value"><%= new Date(member.time).toLocaleString() %></h2>
|
||||||
</div>
|
</div>
|
||||||
|
<% if(!member.hideLastSeen || user?.admin) {%>
|
||||||
|
<div class="box">
|
||||||
|
<h2 class="box-title">Last seen at:</h2>
|
||||||
|
<h2 class="box-value"><%= new Date(member.lastSeen).toLocaleString() %></h2>
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h2 class="box-title">Message:</h2>
|
<h2 class="box-title">Message:</h2>
|
||||||
<h2 class="box-value"><%= counts.message %></h2>
|
<h2 class="box-value"><%= counts.message %></h2>
|
||||||
|
|
Loading…
Reference in a new issue