mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-01 03:25:04 +03:00
Not login support
This commit is contained in:
parent
fc8d4c1c68
commit
4209822c74
13 changed files with 123 additions and 112 deletions
|
@ -18,12 +18,10 @@ And, you can learn informations about API in `APIDOCS.md`.
|
||||||
* [Camroku](https://github.com/Camroku) - Made stylesheets
|
* [Camroku](https://github.com/Camroku) - Made stylesheets
|
||||||
|
|
||||||
## To Do (Backend, bug fixes)
|
## To Do (Backend, bug fixes)
|
||||||
- Middleware. For logged in etc.
|
|
||||||
- Better error codes, example 400 for bad request
|
- Better error codes, example 400 for bad request
|
||||||
- Database change. (To MongoDB)
|
- Database change. (To MongoDB)
|
||||||
- Better DB writing. Example, not `message.author.id`, `messsage.authorID`
|
- Better DB writing. Example, not `message.author.id`, `messsage.authorID`
|
||||||
- `/errors/error` will change, better error page.
|
- `/errors/error` will change, better error page.
|
||||||
- Support for not logins...
|
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
- [x] User
|
- [x] User
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
const { Router } = require("express");
|
module.exports = (req, res) => {
|
||||||
|
|
||||||
const app = Router();
|
|
||||||
|
|
||||||
app.get("/", (req, res, next) => {
|
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
if (!req.session.loggedin) return res.redirect('/login');
|
||||||
next();
|
}
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = app;
|
|
|
@ -1,2 +0,0 @@
|
||||||
const admin = () => document.getElementById("admin").innerHTML =
|
|
||||||
'<div class="admin"><a class="admin" href="/admin"><p>You are admin, and you can go your page!</p></a></div><hr>';
|
|
17
routes/.js
17
routes/.js
|
@ -6,17 +6,12 @@ const app = Router();
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
|
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
const
|
||||||
|
mem = process.memoryUsage().heapUsed / Math.pow(2, 20),
|
||||||
const mem = process.memoryUsage().heapUsed / Math.pow(2, 20);
|
users = get("users").length,
|
||||||
|
threads = get("threads").length,
|
||||||
const users = get("users").length;
|
messages = get("messages").length,
|
||||||
|
user = new User().getId(req.session.userid);
|
||||||
const threads = get("threads").length;
|
|
||||||
|
|
||||||
const messages = get("messages").length;
|
|
||||||
|
|
||||||
const user = new User().getId(req.session.userid)
|
|
||||||
|
|
||||||
res.render("index", { mem, user, users, threads, messages })
|
res.render("index", { mem, user, users, threads, messages })
|
||||||
|
|
||||||
|
|
|
@ -5,18 +5,17 @@ const error = require("../errors/error")
|
||||||
|
|
||||||
const app = Router();
|
const app = Router();
|
||||||
|
|
||||||
|
app.use(require("../middlewares/login"));
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
const user = new User().getId(req.session.userid)
|
const user = new User().getId(req.session.userid)
|
||||||
|
|
||||||
if (!user.admin) return error(res, 403, "You have not got permissions for view to this page.");
|
if (!user.admin) return error(res, 403, "You have not got permissions for view to this page.");
|
||||||
|
|
||||||
res.render("admin", { user, user2: false })
|
res.render("admin", { user, user2: false })
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
app.post("/", (req, res) => {
|
app.post("/", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
|
|
||||||
const user = new User().getId(req.session.userid)
|
const user = new User().getId(req.session.userid)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ const { Router } = require("express");
|
||||||
const app = Router();
|
const app = Router();
|
||||||
|
|
||||||
app.get("/:id", (req, res) => {
|
app.get("/:id", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
const message = new Message().getId(req.params.id);
|
const message = new Message().getId(req.params.id);
|
||||||
|
|
||||||
if (!message || message.deleted) return error(res, 404, "We have not got any message declared as this id.");
|
if (!message || message.deleted) return error(res, 404, "We have not got any message declared as this id.");
|
||||||
|
@ -15,10 +14,9 @@ app.get("/:id", (req, res) => {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(require("../middlewares/login"));
|
||||||
|
|
||||||
app.post("/", (req, res) => {
|
app.post("/", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
|
|
||||||
|
|
||||||
const thread = new Thread().getId(req.body.threadID);
|
const thread = new Thread().getId(req.body.threadID);
|
||||||
|
|
||||||
if (thread) {
|
if (thread) {
|
||||||
|
@ -35,8 +33,6 @@ app.post("/", (req, res) => {
|
||||||
|
|
||||||
|
|
||||||
app.post("/:id/delete", (req, res) => {
|
app.post("/:id/delete", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
|
|
||||||
const message = new Message().getId(req.params.id)
|
const message = new Message().getId(req.params.id)
|
||||||
if (!message || message.deleted) return error(res, 404, "We have not got any message declared as this id.");
|
if (!message || message.deleted) return error(res, 404, "We have not got any message declared as this id.");
|
||||||
const user = new User().getId(req.session.userid);
|
const user = new User().getId(req.session.userid);
|
||||||
|
@ -50,8 +46,6 @@ app.post("/:id/delete", (req, res) => {
|
||||||
|
|
||||||
})
|
})
|
||||||
app.post("/:id/react", (req, res) => {
|
app.post("/:id/react", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
|
|
||||||
const { id = null } = req.params;
|
const { id = null } = req.params;
|
||||||
const info = req.body;
|
const info = req.body;
|
||||||
const message = new Message().getId(id);
|
const message = new Message().getId(id);
|
||||||
|
|
|
@ -6,16 +6,8 @@ const { Router } = require("express");
|
||||||
|
|
||||||
const app = Router();
|
const app = Router();
|
||||||
|
|
||||||
app.get("/open*", (req, res) => {
|
|
||||||
|
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
const user = new User().getId(req.session.userid)
|
|
||||||
res.render("openThread", { user })
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
|
|
||||||
const user = new User().getId(req.session.userid);
|
const user = new User().getId(req.session.userid);
|
||||||
|
|
||||||
|
@ -28,7 +20,6 @@ app.get("/", (req, res) => {
|
||||||
|
|
||||||
|
|
||||||
app.get("/:id", (req, res) => {
|
app.get("/:id", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
|
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
|
||||||
|
@ -42,8 +33,19 @@ app.get("/:id", (req, res) => {
|
||||||
error(res, 404, "We have not got this thread.");
|
error(res, 404, "We have not got this thread.");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
app.use(require("../middlewares/login"));
|
||||||
|
|
||||||
|
|
||||||
|
app.get("/open*", (req, res) => {
|
||||||
|
|
||||||
|
const user = new User().getId(req.session.userid)
|
||||||
|
res.render("openThread", { user })
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
app.post("/", (req, res) => {
|
app.post("/", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
|
|
||||||
const user = new User().getId(req.session.userid);
|
const user = new User().getId(req.session.userid);
|
||||||
|
|
||||||
|
|
|
@ -7,26 +7,21 @@ const error = require("../errors/error")
|
||||||
const app = Router();
|
const app = Router();
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
const user = new User().getId(req.session.userid)
|
const user = new User().getId(req.session.userid)
|
||||||
|
|
||||||
|
|
||||||
const users = db.get("users").slice(0);
|
const users = db.get("users").slice(0);
|
||||||
|
|
||||||
const links = users.filter(user => !user.deleted).map(user => "/users/" + user.id);
|
const links = users.filter(user => !user.deleted).map(user => "/users/" + user.id);
|
||||||
return res.render("users", { users, links, user })
|
return res.render("users", { users, links, user })
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/:id", (req, res) => {
|
app.get("/:id", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
const user = new User().getId(req.session.userid)
|
const user = new User().getId(req.session.userid)
|
||||||
const { id = null } = req.params;
|
const { id = null } = req.params;
|
||||||
const member = new User().getId(req.params.id);
|
const member = new User().getId(req.params.id);
|
||||||
|
|
||||||
|
|
||||||
if (member && (user.admin || !member.deleted)) {
|
if (member && (user?.admin || !member.deleted)) {
|
||||||
const message = db.get("messages").filter(message => message.author.id === Number(id)).length
|
const message = db.get("messages").filter(message => message.author.id === Number(id)).length
|
||||||
const thread = db.get("threads").filter(thread => thread.author.id === Number(id)).length
|
const thread = db.get("threads").filter(thread => thread.author.id === Number(id)).length
|
||||||
|
|
||||||
|
@ -36,10 +31,13 @@ app.get("/:id", (req, res) => {
|
||||||
else error(res, 404, "We have not got this user.");
|
else error(res, 404, "We have not got this user.");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.use(require("../middlewares/login"));
|
||||||
|
|
||||||
|
|
||||||
app.post("/:id/delete/", (req, res) => {
|
app.post("/:id/delete/", (req, res) => {
|
||||||
if (!req.session.loggedin) return res.redirect('/login');
|
|
||||||
const user = new User().getId(req.session.userid);
|
const user = new User().getId(req.session.userid);
|
||||||
if (!user.admin)
|
if (!user?.admin)
|
||||||
return error(res, 403, "You have not got permission for this.");
|
return error(res, 403, "You have not got permission for this.");
|
||||||
|
|
||||||
const id = req.url.slice(9 + 3)
|
const id = req.url.slice(9 + 3)
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
|
|
||||||
<!-- Navbar: -->
|
<!-- Navbar: -->
|
||||||
|
|
||||||
<script src="/js/scripts.js"></script>
|
|
||||||
|
|
||||||
<div id="admin"></div>
|
<% if (user?.admin){ %>
|
||||||
<script> if (<%= user.admin %>) admin(); </script>
|
<div class="admin">
|
||||||
|
<a class="admin" href="/admin"><p>You are admin, and you can go your page!</p></a>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<a href="/"><img class="logo" src="/images/logo.jpg" alt="AKF-FORUM"></a>
|
<a href="/"><img class="logo" src="/images/logo.jpg" alt="AKF-FORUM"></a>
|
||||||
|
|
||||||
<div class="navbar" id="navbar">
|
<div class="navbar" id="navbar">
|
||||||
|
@ -14,6 +18,7 @@
|
||||||
<a href="/search">SEARCH</a>
|
<a href="/search">SEARCH</a>
|
||||||
<a href="/threads/open/">OPEN THREAD</a>
|
<a href="/threads/open/">OPEN THREAD</a>
|
||||||
|
|
||||||
|
<% if (user){ %>
|
||||||
<div style="float: right;" class="user" id="user">
|
<div style="float: right;" class="user" id="user">
|
||||||
<a href=<%=user.getLink() %>>
|
<a href=<%=user.getLink() %>>
|
||||||
<h1>
|
<h1>
|
||||||
|
@ -22,6 +27,16 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% } else { %>
|
||||||
|
<a style="float: right; background-color: #5F875F;" href="/register">REGISTER</a>
|
||||||
|
|
||||||
|
<a style="float: right; background-color:#5F87AF; " href="/login">LOGIN</a>
|
||||||
|
|
||||||
|
|
||||||
|
<% } %>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
<%- include("extra/header", {title: "Main page!" }) %>
|
<%- include("extra/header", {title: "Main page!" }) %>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<%- include("extra/navbar", {user}) %>
|
<%- include("extra/navbar") %>
|
||||||
|
|
||||||
|
|
||||||
|
<% if (user) { %>
|
||||||
<h1>Welcome, <a href=<%=user.getLink() %>> <%= user.name %></a>
|
<h1>Welcome, <a href=<%=user.getLink() %>> <%= user.name %></a>
|
||||||
<img class="yuvarlak" src=<%=user.avatar %> alt=<%= user.name %>>
|
<img class="yuvarlak" src=<%=user.avatar %> alt=<%= user.name %>>
|
||||||
<br>
|
<br>
|
||||||
|
@ -16,6 +16,11 @@
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
<% } else { %>
|
||||||
|
<h1>Welcome, Guest!<br>You can press for register here:
|
||||||
|
<button class="buyuk" onclick= "window.location.href = '/register'">REGISTER</button>
|
||||||
|
</h1>
|
||||||
|
<% } %>
|
||||||
<h1>Statistics:</h1>
|
<h1>Statistics:</h1>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -12,13 +12,18 @@
|
||||||
<%= thread.title %>
|
<%= thread.title %>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
<h2>By <a style="color: #bcbcbc;" href=<%="/users/" + thread.author.id %>> <%= thread.author.name %></a>
|
||||||
|
<img class="yuvarlak" src=<%= thread.author.avatar %> alt=<%= thread.author.name %>>
|
||||||
|
</h2>
|
||||||
<br>
|
<hr>
|
||||||
<% messages.forEach(message=>{ %>
|
<% messages.forEach(message=>{ %>
|
||||||
|
|
||||||
<div id=<%="message-" + message.id %> style="border: 2px solid #444444; padding: 5px;">
|
<div id="message-<%= message.id %>" style="border: 2px solid #444444; padding: 10px;">
|
||||||
|
|
||||||
|
<h3 style="float:right;">
|
||||||
|
<%=new Date(message.time).toLocaleString() %>
|
||||||
|
</h3>
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
<img class="yuvarlak" src=<%=message.author.avatar %> alt=<%= message.author.name %>>
|
<img class="yuvarlak" src=<%=message.author.avatar %> alt=<%= message.author.name %>>
|
||||||
<a style="color: #bcbcbc;" href=<%="/users/" + message.author.id %>> <%= message.author.name %></a>:
|
<a style="color: #bcbcbc;" href=<%="/users/" + message.author.id %>> <%= message.author.name %></a>:
|
||||||
|
@ -27,11 +32,15 @@
|
||||||
<h2>
|
<h2>
|
||||||
<%= message.content %>
|
<%= message.content %>
|
||||||
</h2>
|
</h2>
|
||||||
<form style="text-align:right;display:inline;" action="/message/<%= message.id %>/delete/" method="post">
|
|
||||||
<button style="display:inline;" class="button" type="submit">DELETE</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form style="text-align:right;" action="/message/<%= message.id %>/react/" method="POST">
|
<br>
|
||||||
|
|
||||||
|
<% if (user){ %>
|
||||||
|
|
||||||
|
<form style="display:inline;" action="/message/<%= message.id %>/delete/" method="post">
|
||||||
|
</a><button type="submit">DELETE</button>
|
||||||
|
</form>
|
||||||
|
<form style="float: right;" action="/message/<%= message.id %>/react/" method="POST">
|
||||||
|
|
||||||
<h3 style="display:inline;">
|
<h3 style="display:inline;">
|
||||||
<%= Object.values(message.react).filter(Boolean).length - Object.values(message.react).filter(x=>
|
<%= Object.values(message.react).filter(Boolean).length - Object.values(message.react).filter(x=>
|
||||||
|
@ -39,12 +48,13 @@
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
|
|
||||||
<button style="display:inline;" class="button" name="like" type="submit">+🔼</button>
|
<button style="display:inline;" name="like" type="submit">+🔼</button>
|
||||||
<button style="display:inline;" class="button" name="dislike" type="submit">-🔽</button>
|
<button style="display:inline;" name="dislike" type="submit">-🔽</button>
|
||||||
<h3 style="display:inline;">
|
|
||||||
<%=new Date(message.time).toLocaleString() %>
|
|
||||||
</h3>
|
|
||||||
</form>
|
</form>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
@ -58,8 +68,12 @@
|
||||||
<input name="threadID" type="hidden" value="<%= thread.id %>"></input>
|
<input name="threadID" type="hidden" value="<%= thread.id %>"></input>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
<% if (user){ %>
|
||||||
|
<button type="submit">Send!</button>
|
||||||
|
<%} else {%>
|
||||||
|
<button disabled>Login for send</button>
|
||||||
|
<% }%>
|
||||||
|
|
||||||
<button class="button" type="submit">Send!</button>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<% if (user.admin) {%>
|
<% if (user?.admin) {%>
|
||||||
<form action="/admin/" method="POST">
|
<form action="/admin/" method="POST">
|
||||||
<input name="userid" type="hidden" value="<%= member.id %>"></input>
|
<input name="userid" type="hidden" value="<%= member.id %>"></input>
|
||||||
<button class="buyuk" type="submit">Make admin!</button>
|
<button class="buyuk" type="submit">Make admin!</button>
|
||||||
|
|
Loading…
Reference in a new issue