diff --git a/public/js/index.js b/public/js/index.js index e69de29..7d40619 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -0,0 +1,21 @@ +window.onload = async () => { + let id = (await (await fetch("/api/captcha/new", {method: "POST"})).json()).id + console.log(id); + fetch(`/api/captcha/${id}`).then(response => response.blob()) + .then(blob => { + const url = URL.createObjectURL(blob); + document.getElementById("captcha_image").src = url; + } + ); + const form = document.getElementById("captchaForm"); + const inputField = document.getElementById("captcha"); + form.addEventListener('submit', async (e) => { + e.preventDefault(); + + const response = await fetch(`/api/captcha/${id}`, {method: "PATCH",headers: {'Content-Type': 'application/json'}, body: JSON.stringify({"solution": inputField.value})}); + if (response.status == 200) { + inputField.value = ""; + window.location.reload(); + }; + }) +}; \ No newline at end of file diff --git a/public/views/index.pug b/public/views/index.pug deleted file mode 100644 index dde9418..0000000 --- a/public/views/index.pug +++ /dev/null @@ -1,26 +0,0 @@ -html - head - title Captcha Aggregator - meta(charset="utf-8") - meta(name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no") - meta(name="description" content="") - link(href="css/index.css" rel="stylesheet") - body - div(id="tsparticles") - main(class="box") - h2 Вход - - form(id="loginForm" target="hiddenFrame") - div(class="inputBox") - label(for="username") Ник - input(type="text" name="username" id="username" placeholder="ваш ник на сервере" required=true) - - div(class="inputBox") - label(for="password") Пароль - input(type="password" name="password" id="password" placeholder="ваш пароль" required=true) - - div - button(type="submit" name="" style="float: left;") Войти - a(class="button" href="register" style="float: left;") Регистрация - script(type="text/javascript" src="js/index.js") - \ No newline at end of file diff --git a/views/index.pug b/views/index.pug new file mode 100644 index 0000000..22e7961 --- /dev/null +++ b/views/index.pug @@ -0,0 +1,22 @@ +html + head + title Captcha Aggregator + meta(charset="utf-8") + meta(name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no") + meta(name="description" content="") + link(href="css/index.css" rel="stylesheet") + body + div(id="tsparticles") + main(class="box") + h2 Captcha Aggregator + + form(id="captchaForm") + div(class="image") + img(id="captcha_image" placeholder="captcha is loading") + div(class="inputBox") + label(for="captcha") Captcha + input(type="text" name="captcha" id="captcha" placeholder="solve a captcha" required=true) + div + button(type="submit" name="" style="float: center;") Send + script(type="text/javascript" src="js/index.js") + \ No newline at end of file