From c7511180a8e65472f07cb2032aa582cb419f445c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E4=B9=90=E6=B6=9B?= <1215891603@qq.com> Date: Mon, 3 Jun 2024 00:02:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20app/templates?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/templates/login.html | 11 ++++---- app/templates/reset.html | 13 +++++---- app/templates/signup.html | 20 +++++++------ app/templates/test_bug536_QianLetao.py | 39 ++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 app/templates/test_bug536_QianLetao.py diff --git a/app/templates/login.html b/app/templates/login.html index b0806b6..b001cb0 100644 --- a/app/templates/login.html +++ b/app/templates/login.html @@ -11,12 +11,14 @@ function login(){ let username = $("#username").val(); let password = $("#password").val(); + let regex = /^[a-zA-Z0-9_]*$/; + if (username === "" || password === ""){ alert('输入不能为空!'); return false; } - if (password.includes(' ')) { - alert('输入不能包含空格!'); + if (!regex.test(username) || !regex.test(password)) { + alert('用户名和密码只能包含英文字母和数字!'); return false; } $.post( @@ -29,7 +31,7 @@ window.location.href = "/"+username+"/userpage"; } } - ) + ); return false; } @@ -46,5 +48,4 @@ {% endif %} -{% endblock %} - +{% endblock %} \ No newline at end of file diff --git a/app/templates/reset.html b/app/templates/reset.html index 408e001..741a7f9 100644 --- a/app/templates/reset.html +++ b/app/templates/reset.html @@ -8,14 +8,12 @@ let old_password = $("#old-password").val(); let new_password = $("#new-password").val(); let re_new_password = $("#re-new-password").val(); + let regex = /^[a-zA-Z0-9_]*$/; + if (old_password === "" || new_password === "" || re_new_password === ""){ alert('输入不能为空!'); return false; } - if (old_password.includes(' ') || new_password.includes(' ')) { - alert('输入不能包含空格!'); - return false; - } if (new_password !== re_new_password) { alert('新密码不匹配,请重新输入'); return false; @@ -24,6 +22,11 @@ alert('密码过于简单。(密码长度至少4位)'); return false; } + if (!regex.test(new_password)) { + alert('新密码只能包含英文字母和数字!'); + return false; + } + $.post("/reset", {'old-password': old_password, 'new-password': new_password}, function (response) { if (response.status === '1') { @@ -34,7 +37,7 @@ window.location.href = "/reset"; } } - ) + ); return false; } diff --git a/app/templates/signup.html b/app/templates/signup.html index 6b5db6e..660e924 100644 --- a/app/templates/signup.html +++ b/app/templates/signup.html @@ -12,14 +12,12 @@ You're logged in already! Logout. let username = $("#username").val(); let password = $("#password").val(); let password2 = $("#password2").val(); + let regex = /^[a-zA-Z0-9_]*$/; + if (username === "" || password === "" || password2 === ""){ alert('输入不能为空!'); return false; } - if (password.includes(' ') || password2.includes(' ')) { - alert('输入不能包含空格!'); - return false; - } if (password !== password2) { alert('确认密码与输入密码不一致!'); return false; @@ -28,6 +26,11 @@ You're logged in already! Logout. alert('密码过于简单。(密码长度至少4位)'); return false; } + if (!regex.test(username) || !regex.test(password)) { + alert('用户名和密码只能包含英文字母和数字!'); + return false; + } + $.post("/signup", {'username': username, 'password': password}, function (response) { if (response.status === '0') { @@ -47,7 +50,7 @@ You're logged in already! Logout. alert(response.warn); } } - ) + ); return false; } @@ -60,13 +63,12 @@ You're logged in already! Logout.