mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-13 17:05:47 +01:00
🧑💻 Address PR comments
This commit is contained in:
@@ -15,24 +15,26 @@ function ModalContent() {
|
|||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
onSubmit={form.onSubmit((values) => {
|
onSubmit={form.onSubmit((values) => {
|
||||||
axios.post('/api/configs/tryToggleEdit', { tried: values.triedPassword }).then((res) => {
|
axios
|
||||||
if (res.data.success) {
|
.post('/api/configs/tryPassword', { tried: values.triedPassword, type: 'edit' })
|
||||||
showNotification({
|
.then((res) => {
|
||||||
title: 'Success',
|
if (res.data.success) {
|
||||||
message: 'Successfully toggled edit mode, reloading the page...',
|
showNotification({
|
||||||
color: 'green',
|
title: 'Success',
|
||||||
});
|
message: 'Successfully toggled edit mode, reloading the page...',
|
||||||
setTimeout(() => {
|
color: 'green',
|
||||||
window.location.reload();
|
});
|
||||||
}, 500);
|
setTimeout(() => {
|
||||||
} else {
|
window.location.reload();
|
||||||
showNotification({
|
}, 500);
|
||||||
title: 'Wrong password',
|
} else {
|
||||||
message: 'The password you entered is wrong.',
|
showNotification({
|
||||||
color: 'red',
|
title: 'Wrong password',
|
||||||
});
|
message: 'The password you entered is wrong.',
|
||||||
}
|
color: 'red',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Stack>
|
<Stack>
|
||||||
|
|||||||
@@ -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',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user