From f2b51cd33e02b9005951e0d7d6ac2f72bd2996ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=B7=E9=BE=99?= Date: Fri, 29 Aug 2025 03:49:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E7=A0=81=E6=A0=BC=E5=BC=8F=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/signup/page.tsx | 76 +++++++++++++++++++++++++++++---- components/pages/home-page2.tsx | 2 +- components/pages/login.tsx | 60 ++++++++++++++++++++++++-- 3 files changed, 124 insertions(+), 14 deletions(-) diff --git a/app/signup/page.tsx b/app/signup/page.tsx index b7a41a4..08b9db7 100644 --- a/app/signup/page.tsx +++ b/app/signup/page.tsx @@ -13,10 +13,47 @@ export default function SignupPage() { const [inviteCode, setInviteCode] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); const [formError, setFormError] = useState(""); + const [passwordError, setPasswordError] = useState(""); + const [showPassword, setShowPassword] = useState(false); const router = useRouter(); + /** Password validation function with English prompts */ + const validatePassword = (password: string): string => { + if (password.length < 8) { + return "Password must be at least 8 characters"; + } + if (password.length > 18) { + return "Password cannot exceed 18 characters"; + } + if (!/^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d]{8,18}$/.test(password)) { + return "Password must contain both letters and numbers"; + } + return ""; + }; + + /** 处理密码输入变化 */ + const handlePasswordChange = (e: React.ChangeEvent) => { + const newPassword = e.target.value; + setPassword(newPassword); + + if (newPassword) { + const error = validatePassword(newPassword); + setPasswordError(error); + } else { + setPasswordError(""); + } + }; + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); + + // 验证密码 + const passwordValidationError = validatePassword(password); + if (passwordValidationError) { + setPasswordError(passwordValidationError); + return; + } + setIsSubmitting(true); setFormError(""); @@ -125,14 +162,35 @@ export default function SignupPage() { - setPassword(e.target.value)} - required - className="w-full px-4 py-3 rounded-lg bg-black/30 border border-white/20 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent" - /> +
+ + +
+ {passwordError && ( +

{passwordError}

+ )} + {password && !passwordError && ( +

✓ Password format is correct

+ )} +

+ Password requirements: 8-18 characters, must contain letters and numbers +

@@ -163,7 +221,7 @@ export default function SignupPage() {
+ {passwordError && ( +

{passwordError}

+ )} + {password && !passwordError && ( +

✓ Password format is correct

+ )} +

+ Password requirements: 8-18 characters, must contain letters and numbers +

{/*
{isSubmitting ? "Logging in..." : "Login"}