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
|
||||
- Version info to footer
|
||||
- upload other photos, model for it
|
||||
- black theme is broken
|
||||
|
||||
## Major Version History
|
||||
- V4: Caching
|
||||
|
|
5
index.js
5
index.js
|
@ -22,8 +22,9 @@ 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.user = await UserModel.get(req.session.userID);
|
||||
if (req.session.userID)
|
||||
req.user = await UserModel.findOneAndUpdate({ id: req.session.userID }, { lastSeen: Date.now() });
|
||||
|
||||
res.reply = (page, options = {}, status = 200) => res.status(status)
|
||||
.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 },
|
||||
about: { type: String, default: "" },
|
||||
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);
|
||||
|
||||
model.get = id => model.findOne({ id });
|
||||
model.get = (id,select) => model.findOne({ id }).select(select);
|
||||
|
||||
module.exports = model;
|
|
@ -6,7 +6,7 @@ const multer = require("multer");
|
|||
const app = Router();
|
||||
|
||||
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}.`);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ app.get("/:id/avatar", async (req, res) => {
|
|||
app.get("/:id", async (req, res) => {
|
||||
const user = req.user
|
||||
const { id } = req.params;
|
||||
const member = await UserModel.get(id);
|
||||
const member = await UserModel.get(id,"+lastSeen");
|
||||
|
||||
if (member && (user?.admin || !member.deleted)) {
|
||||
|
||||
|
|
|
@ -115,6 +115,12 @@ color: var(--anti);
|
|||
<h2 class="box-title">Created at:</h2>
|
||||
<h2 class="box-value"><%= new Date(member.time).toLocaleString() %></h2>
|
||||
</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">
|
||||
<h2 class="box-title">Message:</h2>
|
||||
<h2 class="box-value"><%= counts.message %></h2>
|
||||
|
|
Loading…
Reference in a new issue