diff --git a/app/main.py b/app/main.py index 0e39c3e..c18f045 100644 --- a/app/main.py +++ b/app/main.py @@ -440,8 +440,13 @@ async def request_access(request: Request, db: Session = Depends(get_db)): manager = str(data.get("manager", "")).strip() products = data.get("products", []) + import re as _re if not name or not company or not email or not phone: raise HTTPException(status_code=422, detail="Заполните все обязательные поля") + if not _re.match(r'^[^\s@]+@[^\s@]+\.[^\s@]+$', email): + raise HTTPException(status_code=422, detail="Некорректный email") + if not _re.match(r'^[\+\d][\d\s\-\(\)]{6,18}$', phone): + raise HTTPException(status_code=422, detail="Некорректный номер телефона") products_text = "" if products: diff --git a/app/templates/login.html b/app/templates/login.html index e2ef52f..b8a61c7 100644 --- a/app/templates/login.html +++ b/app/templates/login.html @@ -175,11 +175,23 @@ const checked = [...document.querySelectorAll('#am-products input[type=checkbox]:checked')]; const products = checked.map(c => c.value); + const emailRe = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + const phoneRe = /^[\+\d][\d\s\-\(\)]{6,18}$/; if (!name || !company || !email || !phone) { errEl.textContent = 'Пожалуйста, заполните все обязательные поля'; errEl.style.display = 'block'; return; } + if (!emailRe.test(email)) { + errEl.textContent = 'Введите корректный email'; + errEl.style.display = 'block'; + return; + } + if (!phoneRe.test(phone)) { + errEl.textContent = 'Введите корректный номер телефона'; + errEl.style.display = 'block'; + return; + } btnSubmit.disabled = true; btnSubmit.textContent = 'Отправка...';