Formatted with eslint.

Signed-off-by: Armored Dragon <publicmail@armoreddragon.com>
pull/6/head^2
Armored Dragon 2024-07-08 13:21:36 -05:00
parent f4bf5c37d9
commit 57460c2328
Signed by: ArmoredDragon
GPG Key ID: C7207ACC3382AD8B
7 changed files with 753 additions and 753 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,68 +3,68 @@ const bcrypt = require("bcrypt");
const validate = require("../form_validation");
async function postRegister(req, res) {
const { username, password } = req.body; // Get the username and password from the request body
const { username, password } = req.body; // Get the username and password from the request body
const form_validation = await validate.newUser({ username: username, password: password }); // Check form for errors
const form_validation = await validate.newUser({ username: username, password: password }); // Check form for errors
// User registration disabled?
// We also check if the server was setup. If it was not set up, the server will proceed anyways.
if (!core.settings["ACCOUNT_REGISTRATION"] && core.settings["SETUP_COMPLETE"]) return res.json({ success: false, message: "Account registrations are disabled" });
// User registration disabled?
// We also check if the server was setup. If it was not set up, the server will proceed anyways.
if (!core.settings["ACCOUNT_REGISTRATION"] && core.settings["SETUP_COMPLETE"]) return res.json({ success: false, message: "Account registrations are disabled" });
// User data valid?
if (!form_validation.success) return res.json({ success: false, message: form_validation.message });
// User data valid?
if (!form_validation.success) return res.json({ success: false, message: form_validation.message });
// If setup incomplete, set the user role to Admin. This is the initial user so it will be the master user.
const role = core.settings["SETUP_COMPLETE"] ? undefined : "ADMIN";
// If setup incomplete, set the user role to Admin. This is the initial user so it will be the master user.
const role = core.settings["SETUP_COMPLETE"] ? undefined : "ADMIN";
const hashed_password = await bcrypt.hash(password, 10); // Hash the password for security :^)
res.json(await core.newUser({ username: username, password: hashed_password, role: role }));
const hashed_password = await bcrypt.hash(password, 10); // Hash the password for security :^)
res.json(await core.newUser({ username: username, password: hashed_password, role: role }));
}
async function postLogin(req, res) {
const { username, password } = req.body; // Get the username and password from the request body
const { username, password } = req.body; // Get the username and password from the request body
// Get the user by username
const existing_user = await core.getUser({ username: username, include_password: true });
if (!existing_user.success) return res.json({ success: false, message: existing_user.message });
// Get the user by username
const existing_user = await core.getUser({ username: username, include_password: true });
if (!existing_user.success) return res.json({ success: false, message: existing_user.message });
// Check the password
const password_match = await bcrypt.compare(password, existing_user.data.password);
if (!password_match) return res.json({ success: false, message: "Incorrect password" });
// Check the password
const password_match = await bcrypt.compare(password, existing_user.data.password);
if (!password_match) return res.json({ success: false, message: "Incorrect password" });
// Send the cookies to the user & return successful
req.session.user = { username: username, id: existing_user.data.id };
res.json({ success: true });
// Send the cookies to the user & return successful
req.session.user = { username: username, id: existing_user.data.id };
res.json({ success: true });
}
async function postSetting(request, response) {
const user = await core.getUser({ user_id: request.session.user.id });
const user = await core.getUser({ user_id: request.session.user.id });
if (!user.success) return response.json({ success: false, message: user.message });
if (user.data.role !== "ADMIN") return response.json({ success: false, message: "User is not permitted" });
if (!user.success) return response.json({ success: false, message: user.message });
if (user.data.role !== "ADMIN") return response.json({ success: false, message: "User is not permitted" });
response.json(await core.postSetting(request.body.setting_name, request.body.value));
response.json(await core.postSetting(request.body.setting_name, request.body.value));
}
async function postImage(request, response) {
// TODO: Permissions for uploading images
// TODO: Verification for image uploading
return response.json(await core.uploadMedia({ parent_id: request.body.post_id, parent_type: request.body.parent_type, file_buffer: request.body.buffer, content_type: request.body.content_type }));
// TODO: Permissions for uploading images
// TODO: Verification for image uploading
return response.json(await core.uploadMedia({ parent_id: request.body.post_id, parent_type: request.body.parent_type, file_buffer: request.body.buffer, content_type: request.body.content_type }));
}
async function deleteImage(req, res) {
// TODO: Permissions for deleting image
return res.json(await core.deleteImage(req.body, req.session.user.id));
// TODO: Permissions for deleting image
return res.json(await core.deleteImage(req.body, req.session.user.id));
}
async function deleteBlog(req, res) {
// TODO: Permissions for deleting blog
return res.json(await core.deletePost({ post_id: req.body.id, requester_id: req.session.user.id }));
// TODO: Permissions for deleting blog
return res.json(await core.deletePost({ post_id: req.body.id, requester_id: req.session.user.id }));
}
async function patchBlog(req, res) {
return res.json(await core.editPost({ requester_id: req.session.user.id, post_id: req.body.id, post_content: req.body }));
return res.json(await core.editPost({ requester_id: req.session.user.id, post_id: req.body.id, post_content: req.body }));
}
async function patchBiography(request, response) {
// TODO: Validate
return response.json(await core.updateBiography({ requester_id: request.session.user.id, author_id: request.body.id, biography_content: request.body }));
// TODO: Validate
return response.json(await core.updateBiography({ requester_id: request.session.user.id, author_id: request.body.id, biography_content: request.body }));
}
async function patchUser(request, response) {
return response.json(await core.editUser({ requester_id: request.session.user.id, user_id: request.body.id, user_content: request.body }));
return response.json(await core.editUser({ requester_id: request.session.user.id, user_id: request.body.id, user_content: request.body }));
}
module.exports = { postRegister, patchBiography, postLogin, postSetting, postImage, deleteImage, deleteBlog, patchBlog, patchUser };

View File

@ -2,126 +2,126 @@ const external = require("./core/external_api");
const core = require("./core/core");
function _getThemePage(page_name) {
let manifest = require(`../frontend/views/themes/${core.settings.theme}/manifest.json`);
return `themes/${core.settings.theme}/${manifest.pages[page_name]}`;
let manifest = require(`../frontend/views/themes/${core.settings.theme}/manifest.json`);
return `themes/${core.settings.theme}/${manifest.pages[page_name]}`;
}
async function getDefaults(req) {
// TODO: Fix reference to website_name
let user;
if (req.session.user) user = await core.getUser({ user_id: req.session.user.id });
if (user?.success) user = user.data;
return { logged_in_user: user, website_name: core.settings.WEBSITE_NAME || "Yet-Another-Blog", settings: core.settings };
// TODO: Fix reference to website_name
let user;
if (req.session.user) user = await core.getUser({ user_id: req.session.user.id });
if (user?.success) user = user.data;
return { logged_in_user: user, website_name: core.settings.WEBSITE_NAME || "Yet-Another-Blog", settings: core.settings };
}
async function index(request, response) {
// Check if the master admin has been created
// const is_setup_complete = core.settings["SETUP_COMPLETE"];
// if (!is_setup_complete) return response.redirect("/register");
// Check if the master admin has been created
// const is_setup_complete = core.settings["SETUP_COMPLETE"];
// if (!is_setup_complete) return response.redirect("/register");
const blog_list = await core.getPost({ requester_id: request.session.user?.id }, {}, { page: request.query.page || 0 });
const tags = await core.getTags();
const blog_list = await core.getPost({ requester_id: request.session.user?.id }, {}, { page: request.query.page || 0 });
const tags = await core.getTags();
blog_list.data.forEach((post) => {
let published_date_parts = new Date(post.publish_date).toLocaleDateString().split("/");
const formatted_date = `${published_date_parts[2]}-${published_date_parts[0].padStart(2, "0")}-${published_date_parts[1].padStart(2, "0")}`;
post.publish_date = formatted_date;
});
blog_list.data.forEach((post) => {
let published_date_parts = new Date(post.publish_date).toLocaleDateString().split("/");
const formatted_date = `${published_date_parts[2]}-${published_date_parts[0].padStart(2, "0")}-${published_date_parts[1].padStart(2, "0")}`;
post.publish_date = formatted_date;
});
response.render(_getThemePage("index"), {
...(await getDefaults(request)),
blog_list: blog_list.data,
pagination: blog_list.pagination,
current_page: request.query.page || 0,
loaded_page: request.path,
tags: tags,
});
response.render(_getThemePage("index"), {
...(await getDefaults(request)),
blog_list: blog_list.data,
pagination: blog_list.pagination,
current_page: request.query.page || 0,
loaded_page: request.path,
tags: tags,
});
}
async function register(request, response) {
response.render(_getThemePage("register"), await getDefaults(request));
response.render(_getThemePage("register"), await getDefaults(request));
}
async function login(request, response) {
response.render(_getThemePage("login"), await getDefaults(request));
response.render(_getThemePage("login"), await getDefaults(request));
}
async function author(req, res) {
const user = await core.getUser({ user_id: req.params.author_id });
// FIXME: Bandage fix for author get error
if (!user.success) return res.redirect("/");
const profile = await core.getBiography({ author_id: user.data.id });
// TODO: Check for success
const posts = await core.getPost({ requester_id: user.data.id });
const user = await core.getUser({ user_id: req.params.author_id });
// FIXME: Bandage fix for author get error
if (!user.success) return res.redirect("/");
const profile = await core.getBiography({ author_id: user.data.id });
// TODO: Check for success
const posts = await core.getPost({ requester_id: user.data.id });
res.render(_getThemePage("author"), { ...(await getDefaults(req)), post: { ...profile.data, post_count: posts.data.length } });
res.render(_getThemePage("author"), { ...(await getDefaults(req)), post: { ...profile.data, post_count: posts.data.length } });
}
async function authorEdit(request, response) {
let author = await core.getBiography({ author_id: request.params.author_id });
if (!author.success) return response.redirect("/");
response.render(_getThemePage("authorEdit"), { ...(await getDefaults(request)), profile: author.data });
let author = await core.getBiography({ author_id: request.params.author_id });
if (!author.success) return response.redirect("/");
response.render(_getThemePage("authorEdit"), { ...(await getDefaults(request)), profile: author.data });
}
async function blogList(req, res) {
const blog_list = await core.getPost({ requester_id: req.session.user?.id }, { search: req.query.search, search_title: true, search_tags: true, search_content: true });
const blog_list = await core.getPost({ requester_id: req.session.user?.id }, { search: req.query.search, search_title: true, search_tags: true, search_content: true });
blog_list.data.forEach((post) => {
let published_date_parts = new Date(post.publish_date).toLocaleDateString().split("/");
const formatted_date = `${published_date_parts[2]}-${published_date_parts[0].padStart(2, "0")}-${published_date_parts[1].padStart(2, "0")}`;
post.publish_date = formatted_date;
});
blog_list.data.forEach((post) => {
let published_date_parts = new Date(post.publish_date).toLocaleDateString().split("/");
const formatted_date = `${published_date_parts[2]}-${published_date_parts[0].padStart(2, "0")}-${published_date_parts[1].padStart(2, "0")}`;
post.publish_date = formatted_date;
});
res.render(_getThemePage("postSearch"), {
...(await getDefaults(req)),
blog_list: blog_list.data,
pagination: blog_list.pagination,
current_page: req.query.page || 0,
loaded_page: req.path,
});
res.render(_getThemePage("postSearch"), {
...(await getDefaults(req)),
blog_list: blog_list.data,
pagination: blog_list.pagination,
current_page: req.query.page || 0,
loaded_page: req.path,
});
}
async function blogSingle(req, res) {
const blog = await core.getPost({ requester_id: req.session.user?.id, post_id: req.params.blog_id });
if (blog.success === false) return res.redirect("/");
res.render(_getThemePage("post"), { ...(await getDefaults(req)), blog_post: blog.data });
const blog = await core.getPost({ requester_id: req.session.user?.id, post_id: req.params.blog_id });
if (blog.success === false) return res.redirect("/");
res.render(_getThemePage("post"), { ...(await getDefaults(req)), blog_post: blog.data });
}
async function blogNew(request, response) {
const new_post = await core.newPost({ requester_id: request.session.user.id });
return response.redirect(`/post/${new_post}/edit`);
const new_post = await core.newPost({ requester_id: request.session.user.id });
return response.redirect(`/post/${new_post}/edit`);
}
async function blogEdit(req, res) {
let existing_blog = await core.getPost({ post_id: req.params.blog_id });
if (!existing_blog.success) return res.redirect("/");
existing_blog = existing_blog.data;
let existing_blog = await core.getPost({ post_id: req.params.blog_id });
if (!existing_blog.success) return res.redirect("/");
existing_blog = existing_blog.data;
let published_time_parts = new Date(existing_blog.publish_date).toLocaleTimeString([], { timeStyle: "short" }).slice(0, 4).split(":");
const formatted_time = `${published_time_parts[0].padStart(2, "0")}:${published_time_parts[1].padStart(2, "0")}`;
existing_blog.publish_time = formatted_time;
let published_time_parts = new Date(existing_blog.publish_date).toLocaleTimeString([], { timeStyle: "short" }).slice(0, 4).split(":");
const formatted_time = `${published_time_parts[0].padStart(2, "0")}:${published_time_parts[1].padStart(2, "0")}`;
existing_blog.publish_time = formatted_time;
let published_date_parts = new Date(existing_blog.publish_date).toLocaleDateString().split("/");
const formatted_date = `${published_date_parts[2]}-${published_date_parts[0].padStart(2, "0")}-${published_date_parts[1].padStart(2, "0")}`;
existing_blog.publish_date = formatted_date;
let published_date_parts = new Date(existing_blog.publish_date).toLocaleDateString().split("/");
const formatted_date = `${published_date_parts[2]}-${published_date_parts[0].padStart(2, "0")}-${published_date_parts[1].padStart(2, "0")}`;
existing_blog.publish_date = formatted_date;
res.render(_getThemePage("postNew"), { ...(await getDefaults(req)), existing_blog: existing_blog });
res.render(_getThemePage("postNew"), { ...(await getDefaults(req)), existing_blog: existing_blog });
}
async function admin(request, response) {
response.render(_getThemePage("admin-settings"), { ...(await getDefaults(request)) });
response.render(_getThemePage("admin-settings"), { ...(await getDefaults(request)) });
}
async function atom(req, res) {
res.type("application/xml");
res.send(await external.getFeed({ type: "atom" }));
res.type("application/xml");
res.send(await external.getFeed({ type: "atom" }));
}
async function jsonFeed(req, res) {
res.type("application/json");
res.send(await external.getFeed({ type: "json" }));
res.type("application/json");
res.send(await external.getFeed({ type: "json" }));
}
// Internal API ------------------------------
module.exports = {
index,
register,
login,
author,
blogList,
blogNew,
blogEdit,
blogSingle,
admin,
atom,
jsonFeed,
authorEdit,
index,
register,
login,
author,
blogList,
blogNew,
blogEdit,
blogSingle,
admin,
atom,
jsonFeed,
authorEdit,
};

View File

@ -1,127 +1,127 @@
.page .page-center {
background-color: white;
width: 700px;
min-height: 50px;
margin-top: 4rem;
padding: 1rem;
box-sizing: border-box;
box-shadow: #0000001c 0 0px 5px;
background-color: white;
width: 700px;
min-height: 50px;
margin-top: 4rem;
padding: 1rem;
box-sizing: border-box;
box-shadow: #0000001c 0 0px 5px;
.header {
text-align: center;
font-size: 1.5rem;
}
.header {
text-align: center;
font-size: 1.5rem;
}
.setting-list {
display: flex;
flex-direction: column;
.setting-list {
display: flex;
flex-direction: column;
.setting {
width: 100%;
height: 32px;
background-color: rgb(240, 240, 240);
padding: 0.1rem;
box-sizing: border-box;
display: flex;
flex-direction: row;
.setting {
width: 100%;
height: 32px;
background-color: rgb(240, 240, 240);
padding: 0.1rem;
box-sizing: border-box;
display: flex;
flex-direction: row;
.title {
margin: auto auto auto 0;
}
.title {
margin: auto auto auto 0;
}
.value {
margin: 0 0 0 auto;
display: flex;
.value {
margin: 0 0 0 auto;
display: flex;
input[type="text"] {
margin: auto;
font-size: 1rem;
text-align: center;
}
input[type="number"] {
margin: auto;
width: 4rem;
text-align: right;
font-size: 1rem;
}
}
}
input[type="text"] {
margin: auto;
font-size: 1rem;
text-align: center;
}
input[type="number"] {
margin: auto;
width: 4rem;
text-align: right;
font-size: 1rem;
}
}
}
.largeset {
flex-direction: column;
height: fit-content;
.value {
width: 100%;
padding: 0.25rem;
box-sizing: border-box;
textarea {
width: 100%;
margin: auto;
font-size: initial;
resize: vertical;
min-height: 3rem;
}
}
}
.largeset {
flex-direction: column;
height: fit-content;
.value {
width: 100%;
padding: 0.25rem;
box-sizing: border-box;
textarea {
width: 100%;
margin: auto;
font-size: initial;
resize: vertical;
min-height: 3rem;
}
}
}
.setting.fit-column {
flex-direction: column;
width: 100%;
}
.setting.fit-column {
flex-direction: column;
width: 100%;
}
.setting:nth-child(even) {
background-color: rgb(250, 250, 250);
}
}
.setting:nth-child(even) {
background-color: rgb(250, 250, 250);
}
}
}
.switch {
position: relative;
display: inline-block;
width: 50px;
height: 28px;
position: relative;
display: inline-block;
width: 50px;
height: 28px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #b8b8b8;
-webkit-transition: 0.4s;
transition: 0.4s;
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #b8b8b8;
-webkit-transition: 0.4s;
transition: 0.4s;
}
.slider:before {
position: absolute;
content: "";
height: 20px;
width: 20px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: 0.4s;
transition: 0.4s;
position: absolute;
content: "";
height: 20px;
width: 20px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: 0.4s;
transition: 0.4s;
}
input:checked + .slider {
background-color: #2196f3;
background-color: #2196f3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196f3;
box-shadow: 0 0 1px #2196f3;
}
input:checked + .slider:before {
-webkit-transform: translateX(20px);
-ms-transform: translateX(20px);
transform: translateX(20px);
-webkit-transform: translateX(20px);
-ms-transform: translateX(20px);
transform: translateX(20px);
}
.slider.round {
border-radius: 34px;
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
border-radius: 50%;
}

View File

@ -1,77 +1,77 @@
<!DOCTYPE html>
<html lang="">
<head>
<%- include("partials/document-head.ejs") %>
<link rel="stylesheet" type="text/css" href="../css/settings.css" />
<link rel="stylesheet" type="text/css" href="../css/generic.css" />
<script src="/js/generic.js"></script>
</head>
<body>
<%- include("partials/header.ejs") %>
<div class="page">
<div class="page-center">
<div class="header"><%= website_name %> Admin Settings</div>
<div class="setting-list">
<div class="setting">
<div class="title">User registration</div>
<div class="value">
<label class="switch">
<input <% if(settings.ACCOUNT_REGISTRATION) {%> checked <% } %> id="ACCOUNT_REGISTRATION" onchange="toggleState(this.id, this)" type="checkbox" />
<span class="slider round"></span>
</label>
</div>
</div>
<div class="setting">
<div class="title">Hide "Login" in navigation bar</div>
<div class="value">
<label class="switch">
<input <% if(settings.HIDE_LOGIN) {%> checked <% } %> id="HIDE_LOGIN" onchange="toggleState(this.id, this)" type="checkbox" />
<span class="slider round"></span>
</label>
</div>
</div>
<div class="setting">
<div class="title">Serve ATOM feed</div>
<div class="value">
<label class="switch">
<input <% if(settings.CD_RSS) {%> checked <% } %> id="CD_RSS" onchange="toggleState(this.id, this)" type="checkbox" />
<span class="slider round"></span>
</label>
</div>
</div>
<div class="setting">
<div class="title">Serve JSON feed</div>
<div class="value">
<label class="switch">
<input <% if(settings.CD_JSON) {%> checked <% } %> id="CD_JSON" onchange="toggleState(this.id, this)" type="checkbox" />
<span class="slider round"></span>
</label>
</div>
</div>
<div class="setting">
<div class="title">Password minimum length</div>
<div class="value">
<input id="USER_MINIMUM_PASSWORD_LENGTH" value="<%- settings.USER_MINIMUM_PASSWORD_LENGTH -%>" onchange="changeValue(this.id, this)" type="number" />
</div>
</div>
<div class="setting">
<div class="title">Website Name</div>
<div class="value">
<input id="WEBSITE_NAME" value="<%- settings.WEBSITE_NAME -%>" onchange="changeValue(this.id, this)" type="text" />
</div>
</div>
<div class="setting largeset">
<div class="title">Custom head</div>
<div class="value">
<textarea id="CUSTOM_HEADER" onchange="changeValue(this.id, this)" ><%= settings.CUSTOM_HEADER -%></textarea>
</div>
</div>
</div>
</div>
</div>
<head>
<%- include("partials/document-head.ejs") %>
<link rel="stylesheet" type="text/css" href="../css/settings.css" />
<link rel="stylesheet" type="text/css" href="../css/generic.css" />
<script src="/js/generic.js"></script>
</head>
<body>
<%- include("partials/header.ejs") %>
<div class="page">
<div class="page-center">
<div class="header"><%= website_name %> Admin Settings</div>
<div class="setting-list">
<div class="setting">
<div class="title">User registration</div>
<div class="value">
<label class="switch">
<input <% if(settings.ACCOUNT_REGISTRATION) {% /> checked <% } %> id="ACCOUNT_REGISTRATION" onchange="toggleState(this.id, this)" type="checkbox" />
<span class="slider round"></span>
</label>
</div>
</div>
<div class="setting">
<div class="title">Hide "Login" in navigation bar</div>
<div class="value">
<label class="switch">
<input <% if(settings.HIDE_LOGIN) {% /> checked <% } %> id="HIDE_LOGIN" onchange="toggleState(this.id, this)" type="checkbox" />
<span class="slider round"></span>
</label>
</div>
</div>
<div class="setting">
<div class="title">Serve ATOM feed</div>
<div class="value">
<label class="switch">
<input <% if(settings.CD_RSS) {% /> checked <% } %> id="CD_RSS" onchange="toggleState(this.id, this)" type="checkbox" />
<span class="slider round"></span>
</label>
</div>
</div>
<div class="setting">
<div class="title">Serve JSON feed</div>
<div class="value">
<label class="switch">
<input <% if(settings.CD_JSON) {% /> checked <% } %> id="CD_JSON" onchange="toggleState(this.id, this)" type="checkbox" />
<span class="slider round"></span>
</label>
</div>
</div>
<div class="setting">
<div class="title">Password minimum length</div>
<div class="value">
<input id="USER_MINIMUM_PASSWORD_LENGTH" value="<%- settings.USER_MINIMUM_PASSWORD_LENGTH -%>" onchange="changeValue(this.id, this)" type="number" />
</div>
</div>
<div class="setting">
<div class="title">Website Name</div>
<div class="value">
<input id="WEBSITE_NAME" value="<%- settings.WEBSITE_NAME -%>" onchange="changeValue(this.id, this)" type="text" />
</div>
</div>
<div class="setting largeset">
<div class="title">Custom head</div>
<div class="value">
<textarea id="CUSTOM_HEADER" onchange="changeValue(this.id, this)"><%= settings.CUSTOM_HEADER -%></textarea>
</div>
</div>
</div>
</div>
</div>
<%- include("partials/footer.ejs") %>
</body>
<%- include("partials/footer.ejs") %>
</body>
</html>
<script defer src="/js/admin.js"></script>

View File

@ -1,24 +1,24 @@
async function toggleState(setting_name, element) {
console.log(element.checked);
const form = {
setting_name: setting_name,
value: element.checked,
};
const response = await request("/setting", "POST", form);
console.log(element.checked);
const form = {
setting_name: setting_name,
value: element.checked,
};
const response = await request("/setting", "POST", form);
// TODO: On failure, notify the user
if (response.body.success) {
}
// TODO: On failure, notify the user
if (response.body.success) {
}
}
async function changeValue(setting_name, element) {
const form = {
setting_name: setting_name,
value: element.value,
};
const response = await request("/setting", "POST", form);
const form = {
setting_name: setting_name,
value: element.value,
};
const response = await request("/setting", "POST", form);
// TODO: On failure, notify the user
if (response.body.success) {
}
// TODO: On failure, notify the user
if (response.body.success) {
}
}

18
yab.js
View File

@ -20,11 +20,11 @@ const refreshTheme = (theme_name) => app.use(express.static(path.join(__dirname,
refreshTheme("default");
app.use(
session({
secret: require("crypto").randomBytes(128).toString("base64"),
resave: false,
saveUninitialized: false,
})
session({
secret: require("crypto").randomBytes(128).toString("base64"),
resave: false,
saveUninitialized: false,
})
);
// API
@ -55,13 +55,13 @@ app.get("/atom", page_scripts.atom);
app.get("/json", page_scripts.jsonFeed);
function checkAuthenticated(req, res, next) {
if (req.session.user) return next();
res.redirect("/login");
if (req.session.user) return next();
res.redirect("/login");
}
function checkNotAuthenticated(req, res, next) {
if (req.session.user) return res.redirect("/");
next();
if (req.session.user) return res.redirect("/");
next();
}
app.listen(5004);