Added option to disable captcha

This commit is contained in:
Mawoka
2022-08-26 17:46:43 +02:00
parent bc43790cb4
commit 384fbd95fb
5 changed files with 42 additions and 50 deletions
+1
View File
@@ -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
+1
View File
@@ -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';
+2 -29
View File
@@ -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<void> => {
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 @@
>
<button
on:click={() => {
startGame(quiz.id);
start_game(quiz.id);
}}
class="px-4 py-2 leading-5 text-black dark:text-white transition-colors duration-200 transform bg-gray-50 dark:bg-gray-700 rounded text-center hover:bg-gray-300 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 dark:hover:bg-gray-600"
>
+36
View File
@@ -0,0 +1,36 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { alertModal } from '$lib/stores';
import { captcha_enabled } from '$lib/config';
export const start_game = async (id: string) => {
let res;
if (captcha_enabled && 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`);
};
@@ -9,6 +9,7 @@
import { createTippy } from 'svelte-tippy';
import ImportedOrNot from '$lib/view_quiz/imported_or_not.svelte';
import { QuizQuestionType } from '$lib/quiz_types.js';
import { start_game } from '$lib/dashboard/start_game';
const tippy = createTippy({
arrow: true,
@@ -43,26 +44,6 @@
imported_from_kahoot?: boolean;
questions: Question[];
}
const startGame = async (id: string): Promise<void> => {
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) {
throw new Error('Failed to start game');
}
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`);
};
</script>
<svelte:head>
@@ -83,7 +64,7 @@
<button
class="px-4 py-2 leading-5 text-white transition-colors duration-200 transform bg-gray-700 rounded text-center hover:bg-gray-600 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50"
on:click={() => {
startGame(quiz.id);
start_game(quiz.id);
}}
>
{$t('words.start')}