From b923f8261bed913645219a1da11dc72522efc02e Mon Sep 17 00:00:00 2001 From: ajnart Date: Tue, 21 Mar 2023 11:36:34 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Address=20P?= =?UTF-8?q?R=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../header/SettingsMenu/EditModeToggle.tsx | 38 ++++++++++--------- src/pages/api/configs/tryToggleEdit.tsx | 33 ---------------- 2 files changed, 20 insertions(+), 51 deletions(-) delete mode 100644 src/pages/api/configs/tryToggleEdit.tsx diff --git a/src/components/layout/header/SettingsMenu/EditModeToggle.tsx b/src/components/layout/header/SettingsMenu/EditModeToggle.tsx index 5d4fda871..e27c48139 100644 --- a/src/components/layout/header/SettingsMenu/EditModeToggle.tsx +++ b/src/components/layout/header/SettingsMenu/EditModeToggle.tsx @@ -15,24 +15,26 @@ function ModalContent() { return (
{ - axios.post('/api/configs/tryToggleEdit', { tried: values.triedPassword }).then((res) => { - if (res.data.success) { - showNotification({ - title: 'Success', - message: 'Successfully toggled edit mode, reloading the page...', - color: 'green', - }); - setTimeout(() => { - window.location.reload(); - }, 500); - } else { - showNotification({ - title: 'Wrong password', - message: 'The password you entered is wrong.', - color: 'red', - }); - } - }); + axios + .post('/api/configs/tryPassword', { tried: values.triedPassword, type: 'edit' }) + .then((res) => { + if (res.data.success) { + showNotification({ + title: 'Success', + message: 'Successfully toggled edit mode, reloading the page...', + color: 'green', + }); + setTimeout(() => { + window.location.reload(); + }, 500); + } else { + showNotification({ + title: 'Wrong password', + message: 'The password you entered is wrong.', + color: 'red', + }); + } + }); })} > diff --git a/src/pages/api/configs/tryToggleEdit.tsx b/src/pages/api/configs/tryToggleEdit.tsx deleted file mode 100644 index 45f22e8f2..000000000 --- a/src/pages/api/configs/tryToggleEdit.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import Consola from 'consola'; -import { NextApiRequest, NextApiResponse } from 'next'; - -function Post(req: NextApiRequest, res: NextApiResponse) { - const { tried } = req.body; - // Try to match the password with the EDIT_PASSWORD env variable - if (tried === process.env.EDIT_MODE_PASSWORD) { - process.env.DISABLE_EDIT_MODE = process.env.DISABLE_EDIT_MODE === 'true' ? 'false' : 'true'; - return res.status(200).json({ - success: true, - }); - } - // Warn that there was a wrong password attempt (date : wrong password, person's IP) - Consola.warn( - `${new Date().toLocaleString()} : Wrong edit password attempt, from ${ - req.headers['x-forwarded-for'] - }` - ); - return res.status(200).json({ - success: false, - }); -} - -export default async (req: NextApiRequest, res: NextApiResponse) => { - // Filter out if the request is a POST or a GET - if (req.method === 'POST') { - return Post(req, res); - } - return res.status(405).json({ - statusCode: 405, - message: 'Method not allowed', - }); -};