confirm with button
This commit is contained in:
parent
bfb53d5c64
commit
c106b1f21d
1 changed files with 58 additions and 18 deletions
|
@ -53,11 +53,22 @@ export class WebVerifier {
|
|||
|
||||
private serve(request: Request): Response {
|
||||
const url = new URL(request.url);
|
||||
if (!url.pathname.startsWith("/verify/")) return response_failure("Invalid path.");
|
||||
if (url.pathname.startsWith("/verify/")) return this.serve_verification_page(url);
|
||||
if (url.pathname.startsWith("/confirm/")) return this.serve_confirmation(url);
|
||||
return response_failure("Chemin invalide.");
|
||||
}
|
||||
|
||||
private serve_verification_page(url: URL) {
|
||||
const [uid] = url.pathname.slice("/verify/".length).split("/");
|
||||
const exists = this.awaiting.has(uid);
|
||||
if (!exists) return response_failure("Lien de vérification invalide.");
|
||||
return response_verification_page(this.create_confirm_link(uid));
|
||||
}
|
||||
|
||||
private serve_confirmation(url: URL) {
|
||||
const [uid] = url.pathname.slice("/confirm/".length).split("/");
|
||||
const resolver = this.awaiting.get(uid);
|
||||
if (resolver === undefined) return response_failure("Invalid verification link.");
|
||||
if (resolver === undefined) return response_failure("Lien de vérification invalide.");
|
||||
|
||||
resolver(true);
|
||||
this.awaiting.delete(uid);
|
||||
|
@ -65,12 +76,20 @@ export class WebVerifier {
|
|||
return response_success();
|
||||
}
|
||||
|
||||
private async serve_result_page() {
|
||||
//
|
||||
}
|
||||
|
||||
private create_verif_link() {
|
||||
const uid = uuid.generate() as string;
|
||||
const link = `http://${this.conf.url_prefix}/verify/${uid}`;
|
||||
return { uid, link };
|
||||
}
|
||||
|
||||
private create_confirm_link(uid: string) {
|
||||
return `http://${this.conf.url_prefix}/confirm/${uid}`;
|
||||
}
|
||||
|
||||
private async start_peremption(uid: string) {
|
||||
await wait(5 * 60 * 1000); // 5 mins
|
||||
const resolver = this.awaiting.get(uid);
|
||||
|
@ -82,34 +101,55 @@ export class WebVerifier {
|
|||
}
|
||||
|
||||
function response_failure(message: string) {
|
||||
const body = `<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Epitls • Verification</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre>
|
||||
❌ Failure :
|
||||
const body = html_pre(`
|
||||
EPITLS BOT
|
||||
==========
|
||||
|
||||
❌ Échec
|
||||
---------
|
||||
${message}
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
`);
|
||||
return new Response(body, { headers: { "Content-Type": "text/html" } });
|
||||
}
|
||||
|
||||
function response_verification_page(confirm_link: string) {
|
||||
const body = html_pre(`
|
||||
EPITLS BOT
|
||||
==========
|
||||
|
||||
🟡 Vérification
|
||||
----------------
|
||||
|
||||
Vous êtes sur le point de confirmer l'association.
|
||||
<form action="${confirm_link}">
|
||||
<input type="submit" value="Confirmer">
|
||||
</form>
|
||||
`);
|
||||
return new Response(body, { headers: { "Content-Type": "text/html" } });
|
||||
}
|
||||
|
||||
function response_success() {
|
||||
const body = `<!DOCTYPE html>
|
||||
const body = html_pre(`
|
||||
EPITLS BOT
|
||||
==========
|
||||
|
||||
✅ Vérifié avec succès
|
||||
-----------------------
|
||||
`);
|
||||
return new Response(body, { headers: { "Content-Type": "text/html" } });
|
||||
}
|
||||
|
||||
function html_pre(content: string) {
|
||||
return `<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Epitls • Verification</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre>
|
||||
✅ Verified successfully.
|
||||
${content}
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
return new Response(body, { headers: { "Content-Type": "text/html" } });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue