From 384fbd95fb3ff3f1e6744644a193c20d3efc4cd7 Mon Sep 17 00:00:00 2001 From: Mawoka Date: Fri, 26 Aug 2022 17:46:43 +0200 Subject: [PATCH] :sparkles: Added option to disable captcha --- frontend/Dockerfile | 1 + frontend/src/lib/config.ts | 1 + frontend/src/lib/dashboard/main_slider.svelte | 31 ++-------------- frontend/src/lib/dashboard/start_game.ts | 36 +++++++++++++++++++ .../src/routes/view/[quiz_id]/+page.svelte | 23 ++---------- 5 files changed, 42 insertions(+), 50 deletions(-) create mode 100644 frontend/src/lib/dashboard/start_game.ts diff --git a/frontend/Dockerfile b/frontend/Dockerfile index c9de360..c4b3c29 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -11,6 +11,7 @@ ENV VITE_HCAPTCHA=ee81b2a1-acf3-4d20-b2a4-a7ea94c7eba5 # ENV VITE_SENTRY=https://75cb4ef1be624d8f81bbaf864b722f8a@glitch.mawoka.eu/2 ENV VITE_GOOGLE_AUTH_ENABLED=true ENV VITE_GITHUB_AUTH_ENABLED=true +ENV CAPTCHA_ENABLED=true # change working directory WORKDIR /usr/src/app diff --git a/frontend/src/lib/config.ts b/frontend/src/lib/config.ts index 92f3390..23ac02b 100644 --- a/frontend/src/lib/config.ts +++ b/frontend/src/lib/config.ts @@ -6,3 +6,4 @@ export const google_auth_enabled = import.meta.env.VITE_GOOGLE_AUTH_ENABLED === 'true'; export const github_auth_enabled = import.meta.env.VITE_GITHUB_AUTH_ENABLED === 'true'; +export const captcha_enabled = import.meta.env.CAPTCHA_ENABLED === 'true'; diff --git a/frontend/src/lib/dashboard/main_slider.svelte b/frontend/src/lib/dashboard/main_slider.svelte index 229cd8e..e4f7b7c 100644 --- a/frontend/src/lib/dashboard/main_slider.svelte +++ b/frontend/src/lib/dashboard/main_slider.svelte @@ -11,38 +11,11 @@ import { Pagination, EffectCoverflow, Keyboard, Mousewheel, Navigation } from 'swiper'; import { QuizQuestionType } from '$lib/quiz_types.js'; import { getLocalization } from '../i18n'; - import { alertModal } from '../stores'; + import { start_game } from './start_game'; const { t } = getLocalization(); export let quizzes; - const startGame = async (id: string): Promise => { - let res; - if (window.confirm('Do you want to enable the captcha for players?')) { - res = await fetch(`/api/v1/quiz/start/${id}?captcha_enabled=True`, { - method: 'POST' - }); - } else { - res = await fetch(`/api/v1/quiz/start/${id}?captcha_enabled=False`, { - method: 'POST' - }); - } - - if (res.status !== 200) { - alertModal.set({ - open: true, - title: 'Start failed', - body: `Failed to start game, ${await res.text()}` - }); - alertModal.subscribe((_) => { - window.location.assign('/account/login?returnTo=/dashboard'); - }); - } - const data = await res.json(); - // eslint-disable-next-line no-undef - plausible('Started Game', { props: { quiz_id: id } }); - window.location.assign(`/admin?token=${data.game_id}&pin=${data.game_pin}&connect=1`); - }; /* const deleteQuiz = async (to_delete: string) => { if (!confirm('Do you really want to delete this quiz?')) { @@ -158,7 +131,7 @@ >