Improve input UI

This commit is contained in:
soruly 2022-06-18 17:50:30 +00:00
parent 658e936dce
commit 7e9ee2f3c9
No known key found for this signature in database
GPG Key ID: EF971E90F3D2521F
2 changed files with 19 additions and 2 deletions

View File

@ -135,6 +135,9 @@ app.post("/", (req, res) => {
) {
return res.status(403);
}
if (!req.body.name || !req.body.otp) return res.sendStatus(400);
if (!req.body.name.match(/[a-zA-Z][a-zA-Z0-9]+/)) return res.sendStatus(400);
if (!req.body.otp.match(/[a-zA-Z0-9]{16,}/)) return res.sendStatus(400);
fs.copyFileSync("data/latest.json", `data/${Date.now()}.json`);
fs.writeFileSync(
"data/latest.json",

View File

@ -40,11 +40,25 @@
<form method="post" action="/" enctype="application/x-www-form-urlencoded">
<label>
Name
<input name="name" type="text" required />
<input
name="name"
type="text"
required
minlength="2"
pattern="[a-zA-Z][a-zA-Z0-9]+"
placeholder="(alphanumeric characters only)"
/>
</label>
<label>
Secret
<input name="otp" type="text" required minlength="16" />
<input
name="otp"
type="text"
required
minlength="16"
pattern="[a-zA-Z0-9]{16,}"
placeholder="(remove spaces if any)"
/>
</label>
<input type="submit" />
</form>