Add captcha to the pubnix registration frontend.

This commit is contained in:
Midou 2023-07-10 22:23:00 +01:00
parent f98d8d03c9
commit c9520c82fd
Signed by: midou
GPG Key ID: 1D134A95FE521A7A
4 changed files with 30 additions and 6 deletions

View File

@ -36,6 +36,7 @@
"@auth/core": "^0.2.5", "@auth/core": "^0.2.5",
"@auth/sveltekit": "^0.1.12", "@auth/sveltekit": "^0.1.12",
"joi": "^17.7.0", "joi": "^17.7.0",
"snarkdown": "^2.0.0" "snarkdown": "^2.0.0",
"svelte-hcaptcha": "^0.1.1"
} }
} }

9
pnpm-lock.yaml generated
View File

@ -1,4 +1,4 @@
lockfileVersion: '6.1' lockfileVersion: '6.0'
settings: settings:
autoInstallPeers: true autoInstallPeers: true
@ -17,6 +17,9 @@ dependencies:
snarkdown: snarkdown:
specifier: ^2.0.0 specifier: ^2.0.0
version: 2.0.0 version: 2.0.0
svelte-hcaptcha:
specifier: ^0.1.1
version: 0.1.1
devDependencies: devDependencies:
'@iconify-json/ic': '@iconify-json/ic':
@ -1667,6 +1670,10 @@ packages:
resolution: {integrity: sha512-/QmIqWGwzcfE82FAMuHBlKFwudW7Vcos60Ii8j/mJZ0H6kGAXwL5EGlcc8voBJMJv/i0QZmhp5b1ZX/XKg9NJQ==} resolution: {integrity: sha512-/QmIqWGwzcfE82FAMuHBlKFwudW7Vcos60Ii8j/mJZ0H6kGAXwL5EGlcc8voBJMJv/i0QZmhp5b1ZX/XKg9NJQ==}
dev: true dev: true
/svelte-hcaptcha@0.1.1:
resolution: {integrity: sha512-iFF3HwfrCRciJnDs4Y9/rpP/BM2U/5zt+vh+9d4tALPAHVkcANiJIKqYuS835pIaTm6gt+xOzjfFI3cgiRI29A==}
dev: false
/svelte-hmr@0.15.1(svelte@3.55.1): /svelte-hmr@0.15.1(svelte@3.55.1):
resolution: {integrity: sha512-BiKB4RZ8YSwRKCNVdNxK/GfY+r4Kjgp9jCLEy0DuqAKfmQtpL38cQK3afdpjw4sqSs4PLi3jIPJIFp259NkZtA==} resolution: {integrity: sha512-BiKB4RZ8YSwRKCNVdNxK/GfY+r4Kjgp9jCLEy0DuqAKfmQtpL38cQK3afdpjw4sqSs4PLi3jIPJIFp259NkZtA==}
engines: {node: ^12.20 || ^14.13.1 || >= 16} engines: {node: ^12.20 || ^14.13.1 || >= 16}

View File

@ -15,9 +15,7 @@ export const actions: Actions = {
const BodyTypeSchema = Joi.object({ const BodyTypeSchema = Joi.object({
username: Joi.string() username: Joi.string()
.required() .required()
.pattern( .pattern(/^[a-z_][a-z0-9_]{0,20}$/)
/^[a-z_][a-z0-9_]{0,20}$/
)
.message("Invalid username ([A-Za-z0-9_])"), .message("Invalid username ([A-Za-z0-9_])"),
email: Joi.string().email().required(), email: Joi.string().email().required(),
ssh: Joi.string() ssh: Joi.string()
@ -26,7 +24,10 @@ export const actions: Actions = {
/^(ssh-rsa|ssh-ed25519|ecdsa-sha2-nistp256|ecdsa-sha2-nistp384|ecdsa-sha2-nistp521) [A-Za-z0-9+/]+[=]{0,3}( [^@]+@[^@]+)?$/ /^(ssh-rsa|ssh-ed25519|ecdsa-sha2-nistp256|ecdsa-sha2-nistp384|ecdsa-sha2-nistp521) [A-Za-z0-9+/]+[=]{0,3}( [^@]+@[^@]+)?$/
) )
.message("Invalid SSH key"), .message("Invalid SSH key"),
ip: Joi.string().required().ip() ip: Joi.string().required().ip(),
"h-captcha-response": Joi.string().required().messages({
"any.only": "Captcha is required."
})
}); });
formData.append("ip", getClientAddress()); formData.append("ip", getClientAddress());

View File

@ -1,7 +1,11 @@
<script lang="ts"> <script lang="ts">
import type { ActionData, PageData } from "./$types"; import type { ActionData, PageData } from "./$types";
import HCaptcha from "svelte-hcaptcha";
export let form: ActionData; export let form: ActionData;
export let data: PageData; export let data: PageData;
let siteKey = "cb477b1b-6f87-43ee-aa79-71e3302fbb34";
//export const hcaptchaSiteKey = env.HCAPTCHA_SITE_KEY;
</script> </script>
<h1>{data.title}</h1> <h1>{data.title}</h1>
@ -43,6 +47,13 @@
rows="5" rows="5"
required required
/> />
<div>
<label for="h-captcha-response"
><HCaptcha sitekey={siteKey} />
</label>
</div>
</div> </div>
{#if form?.success} {#if form?.success}
@ -53,6 +64,10 @@
{form.message} {form.message}
{/if} {/if}
<div style="display:block;" >
<input type="checkbox" style="display:inline-block;width: 1em;margin-right: 10px;" required><p style="display:inline-block;word-break: break-all;">I agree to the <a href="/legal/tos">Terms of Service</p>.
</div>
<button <button
type="submit" type="submit"
class="transition-filter duration-200 hover:brightness-75" class="transition-filter duration-200 hover:brightness-75"