|
@@ -24,15 +24,15 @@
|
|
|
|
|
|
<script lang="typescript">
|
|
<script lang="typescript">
|
|
import { Converter } from "showdown";
|
|
import { Converter } from "showdown";
|
|
- import { onMount } from "svelte";
|
|
|
|
|
|
+ import { onMount, tick } from "svelte";
|
|
import Icon from "svelte-awesome/components/Icon.svelte";
|
|
import Icon from "svelte-awesome/components/Icon.svelte";
|
|
import { faSpinner } from "@fortawesome/free-solid-svg-icons";
|
|
import { faSpinner } from "@fortawesome/free-solid-svg-icons";
|
|
import { fade } from "svelte/transition";
|
|
import { fade } from "svelte/transition";
|
|
|
|
+ import type { VerifyRequest } from "./verify";
|
|
|
|
|
|
export let rulesText: string = "";
|
|
export let rulesText: string = "";
|
|
export let sitekey: string = "";
|
|
export let sitekey: string = "";
|
|
export let verified!: boolean;
|
|
export let verified!: boolean;
|
|
- console.log(verified);
|
|
|
|
let showVerify: boolean = false;
|
|
let showVerify: boolean = false;
|
|
const spinner = (faSpinner as unknown) as undefined;
|
|
const spinner = (faSpinner as unknown) as undefined;
|
|
let htmlContent = new Converter().makeHtml(rulesText);
|
|
let htmlContent = new Converter().makeHtml(rulesText);
|
|
@@ -46,10 +46,24 @@
|
|
|
|
|
|
let state: State = State.None;
|
|
let state: State = State.None;
|
|
let message: string = "";
|
|
let message: string = "";
|
|
- function onVerified(e: { key: string }) {
|
|
|
|
- // console.log(e.key);
|
|
|
|
|
|
+ async function onVerified(e: { key: string }) {
|
|
state = State.Verify;
|
|
state = State.Verify;
|
|
- // message = "wew";
|
|
|
|
|
|
+ const result = await fetch("/rules/verify", {
|
|
|
|
+ method: "post",
|
|
|
|
+ headers: {
|
|
|
|
+ Accept: "application/json",
|
|
|
|
+ "Content-Type": "application/json",
|
|
|
|
+ },
|
|
|
|
+ body: JSON.stringify({ captchaResponse: e.key } as VerifyRequest),
|
|
|
|
+ });
|
|
|
|
+ const opt = (await result.json()) as Option<unknown, { error: string }>;
|
|
|
|
+ if (!opt.ok) {
|
|
|
|
+ state = State.Error;
|
|
|
|
+ message = opt.error;
|
|
|
|
+ } else {
|
|
|
|
+ state = State.Message;
|
|
|
|
+ message = "Verification done! Welcome to the server!";
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
function onExpired() {
|
|
function onExpired() {
|
|
@@ -98,10 +112,8 @@
|
|
them</label>
|
|
them</label>
|
|
</form>
|
|
</form>
|
|
{#if showVerify}
|
|
{#if showVerify}
|
|
- <a
|
|
|
|
- href="asd"
|
|
|
|
- on:click|preventDefault={() => onVerified({ key: 'wew' })}>Verify test</a>
|
|
|
|
- <!-- <h-captcha site-key={sitekey} dark on:verified={onVerified} on:expired={onExpired} on:error={onError} /> -->
|
|
|
|
|
|
+ <!-- <a href="asd" on:click|preventDefault={() => onVerified({ key: 'wew' })}>Verify test</a> -->
|
|
|
|
+ <h-captcha site-key={sitekey} dark on:verified={onVerified} on:expired={onExpired} on:error={onError} />
|
|
{/if}
|
|
{/if}
|
|
<div class="py-2 pointer-events-none select-none">
|
|
<div class="py-2 pointer-events-none select-none">
|
|
{#if state == State.Verify}
|
|
{#if state == State.Verify}
|