From 53950c21ea98890331081806ea185503bbc74f03 Mon Sep 17 00:00:00 2001 From: squelliy Date: Mon, 31 Aug 2026 20:15:55 +0900 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20(=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=20#30)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/js/register.js | 42 ++++++++++++++++++++++++++++++++ app/templates/auth/register.html | 4 ++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 app/static/js/register.js diff --git a/app/static/js/register.js b/app/static/js/register.js new file mode 100644 index 0000000..43468be --- /dev/null +++ b/app/static/js/register.js @@ -0,0 +1,42 @@ +document.addEventListener('DOMContentLoaded', function () { + const form = document.getElementById('register-form'); + const errorBlock = document.getElementById('register-error'); + + form.addEventListener('submit', async function (event) { + event.preventDefault(); + const email = document.getElementById('email').value.trim(); + const password = document.getElementById('password').value.trim(); + + if (!email || !password) { + showError('Пожалуйста, заполните все поля'); + return; + } + + try { + const response = await fetch('/api/auth/register', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ email, password }), + }); + + const data = await response.json(); + + if (response.ok) { + window.location.href = '/'; + } else { + const errorMsg = data.error || 'Ошибка регистрации. Попробуйте позже.'; + showError(errorMsg); + } + } catch (error) { + showError('Не удалось соединиться с сервером. Проверьте интернет.'); + console.error('Fetch error:', error); + } + }); + + function showError(message) { + errorBlock.textContent = message; + errorBlock.classList.remove('hidden'); + } +}); diff --git a/app/templates/auth/register.html b/app/templates/auth/register.html index e97ec4b..3ce9670 100644 --- a/app/templates/auth/register.html +++ b/app/templates/auth/register.html @@ -57,4 +57,6 @@

-{% endblock %} +{% block scripts %} + +{% endblock %} {% endblock %}