Geniální software
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.env
|
||||||
|
.DS_Store
|
||||||
|
node_modules
|
||||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Shitty registration UI
|
||||||
|
|
||||||
|
Purpose-built. I suppose you could use this to let your friends register on your DMS instance. The UI is in Czech.
|
||||||
69
index.js
Normal file
69
index.js
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import dotenv from "dotenv";
|
||||||
|
import e from "express";
|
||||||
|
import z from "zod";
|
||||||
|
|
||||||
|
import { execa } from "execa";
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const PORT = process.env.PORT || 3000;
|
||||||
|
const CONTAINER = process.env.CONTAINER || "mailserver";
|
||||||
|
const INVITE_CODE = process.env.INVITE_CODE;
|
||||||
|
const DOMAIN = process.env.DOMAIN;
|
||||||
|
|
||||||
|
const RegisterSchema = z.object({
|
||||||
|
invite: z.literal(INVITE_CODE, "ŠPATNÝ KÓD, GÓJI."),
|
||||||
|
username: z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.regex(
|
||||||
|
/^[a-zA-Z0-9]([a-zA-Z0-9._-]{0,62}[a-zA-Z0-9])?$/,
|
||||||
|
"Neplatný formát jména."
|
||||||
|
)
|
||||||
|
.transform((s) => s.toLowerCase()),
|
||||||
|
password: z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.min(8, "Heslo by mělo mít aspoň 8 znaků.")
|
||||||
|
.regex(/^[^\s]+$/, "Heslo prosím bez mezer."),
|
||||||
|
});
|
||||||
|
|
||||||
|
const app = e();
|
||||||
|
|
||||||
|
app.use(e.urlencoded({ extended: true }));
|
||||||
|
app.use(e.static("public"));
|
||||||
|
|
||||||
|
app.post("/register", async (req, res) => {
|
||||||
|
const result = RegisterSchema.safeParse(req.body);
|
||||||
|
|
||||||
|
if (!result.success) {
|
||||||
|
return res
|
||||||
|
.status(400)
|
||||||
|
.send(`Tvůj požadavek je neplatný: ${result.error.issues[0].message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const email = `${result.data.username}@${DOMAIN}`;
|
||||||
|
const password = result.data.password;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await execa(
|
||||||
|
"docker",
|
||||||
|
["exec", "-i", CONTAINER, "setup", "email", "add", email, password],
|
||||||
|
{ timeout: 10000 }
|
||||||
|
);
|
||||||
|
|
||||||
|
res.send(
|
||||||
|
`VÍTEJ V TAJNÉM ELITNÍM KLUBU. Tvůj nový profesionální e-mail je ${email}.`
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("CHYBA:", err.stderr || err.message);
|
||||||
|
|
||||||
|
res
|
||||||
|
.status(500)
|
||||||
|
.send(
|
||||||
|
"Buď se něco rozbilo nebo tento e-mail už existuje. Kdyžtak si postěžuj sneedNEGROVI."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(PORT);
|
||||||
1134
package-lock.json
generated
Normal file
1134
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
package.json
Normal file
22
package.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "shitty-registration-ui",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A shitty ad hoc UI to create an account on my amazing mail server.",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.czchan.org/sneedmaster/shitty-registration-ui"
|
||||||
|
},
|
||||||
|
"license": "AGPL-3.0-only",
|
||||||
|
"author": "sneedmaster <sneedmaster@czchan.org>",
|
||||||
|
"type": "module",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Meds.\""
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"dotenv": "^17.2.3",
|
||||||
|
"execa": "^9.6.0",
|
||||||
|
"express": "^5.1.0",
|
||||||
|
"zod": "^4.1.12"
|
||||||
|
}
|
||||||
|
}
|
||||||
52
public/index.html
Normal file
52
public/index.html
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="stylesheet" href="./style.css" />
|
||||||
|
<title>Registrace</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>REGISTRACE DO TAJNÉHO ELITNÍHO KLUBU</h1>
|
||||||
|
<form method="post" action="/register">
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="invite">Kód pozvánky</label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input id="invite" name="invite" type="text" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="username">Uživatelské jméno</label>
|
||||||
|
<br>
|
||||||
|
<small>(Část emailu před zavináčem)</small>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input id="username" name="username" type="text" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="password">Heslo</label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input id="password" name="password" type="password" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2">
|
||||||
|
<input type="submit" value="Registrovat" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
3
public/style.css
Normal file
3
public/style.css
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
:root {
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user