Update index.html
Browse files- index.html +64 -56
index.html
CHANGED
|
@@ -883,65 +883,73 @@ gtag('config', 'G-Z920J6JQHG', {
|
|
| 883 |
};
|
| 884 |
|
| 885 |
// 执行 登录/注册
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
|
|
|
| 901 |
|
| 902 |
-
|
|
|
|
|
|
|
| 903 |
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 943 |
}
|
| 944 |
-
}
|
|
|
|
| 945 |
|
| 946 |
// 忘记密码重置逻辑
|
| 947 |
document.getElementById('forgot-pwd').onclick = () => {
|
|
|
|
| 883 |
};
|
| 884 |
|
| 885 |
// 执行 登录/注册
|
| 886 |
+
document.getElementById('btn-main-action').onclick = async () => {
|
| 887 |
+
const email = document.getElementById('email').value;
|
| 888 |
+
const pass = document.getElementById('password').value;
|
| 889 |
+
|
| 890 |
+
if (isLoginMode) {
|
| 891 |
+
if (!email || !pass) { alert("Please enter both email and password."); return; }
|
| 892 |
+
// 登录逻辑也加上 await 和 try...catch 更稳妥
|
| 893 |
+
try {
|
| 894 |
+
await signInWithEmailAndPassword(auth, email, pass);
|
| 895 |
+
} catch (err) {
|
| 896 |
+
alert("Login failed: " + err.message);
|
| 897 |
+
}
|
| 898 |
+
} else {
|
| 899 |
+
const name = document.getElementById('username').value;
|
| 900 |
+
const confirmPass = document.getElementById('confirm-password').value;
|
| 901 |
+
const isAgreed = document.getElementById('terms-checkbox').checked;
|
| 902 |
|
| 903 |
+
if (!name || !email || !pass) { alert("Please fill in all required fields."); return; }
|
| 904 |
+
if (pass !== confirmPass) { alert("Passwords do not match!"); return; }
|
| 905 |
+
if (!isAgreed) { alert("Please read and agree to the User Agreement."); return; }
|
| 906 |
|
| 907 |
+
isRegisteringFlow = true;
|
| 908 |
+
|
| 909 |
+
try {
|
| 910 |
+
// 1. 创建账号
|
| 911 |
+
const userCredential = await createUserWithEmailAndPassword(auth, email, pass);
|
| 912 |
+
const user = userCredential.user;
|
| 913 |
+
|
| 914 |
+
// 2. 更新用户名
|
| 915 |
+
await updateProfile(user, { displayName: name });
|
| 916 |
+
|
| 917 |
+
// 3. 写入数据库
|
| 918 |
+
const leadData = {
|
| 919 |
+
name: name,
|
| 920 |
+
email: email,
|
| 921 |
+
registerTime: new Date().toISOString()
|
| 922 |
+
};
|
| 923 |
+
await setDoc(doc(db, "leads", user.uid), leadData);
|
| 924 |
+
|
| 925 |
+
// 4. 发送验证邮件
|
| 926 |
+
await sendEmailVerification(user);
|
| 927 |
+
|
| 928 |
+
// 5. 提示用户
|
| 929 |
+
alert("Registration successful! A verification email has been sent to " + email + ".\n\n⚠️ Note: If you don't see it in your inbox, please check your Spam or Junk folder.");
|
| 930 |
+
|
| 931 |
+
// 6. 登出并重置 UI
|
| 932 |
+
await signOut(auth);
|
| 933 |
+
|
| 934 |
+
isRegisteringFlow = false;
|
| 935 |
+
isLoginMode = true;
|
| 936 |
+
document.getElementById('auth-title').innerText = "Resource Center";
|
| 937 |
+
document.getElementById('btn-main-action').innerText = "Login";
|
| 938 |
+
document.getElementById('toggle-link').innerText = "Register Now";
|
| 939 |
+
document.getElementById('reg-name-field').style.display = 'none';
|
| 940 |
+
document.getElementById('reg-confirm-field').style.display = 'none';
|
| 941 |
+
document.getElementById('terms-container').style.display = 'none';
|
| 942 |
+
document.getElementById('login-extra').style.display = 'block';
|
| 943 |
+
document.getElementById('password').value = "";
|
| 944 |
+
|
| 945 |
+
} catch (err) {
|
| 946 |
+
// 只要上面的任何一步(包括写数据库、发邮件)出错,都会立刻走到这里并弹出详细错误原因!
|
| 947 |
+
isRegisteringFlow = false;
|
| 948 |
+
console.error("Registration Error Details:", err); // 在 F12 控制台打印详细日志
|
| 949 |
+
alert("Registration Error:\n" + err.code + "\n" + err.message);
|
| 950 |
}
|
| 951 |
+
}
|
| 952 |
+
};
|
| 953 |
|
| 954 |
// 忘记密码重置逻辑
|
| 955 |
document.getElementById('forgot-pwd').onclick = () => {
|