feat(auth): Separate Login, Register, and Profile views with robust validations and SQL-safe backend

This commit is contained in:
Antigravity committed 2026-09-17 10:22:02 +00:00
1 parent 5f3abba27c
commit 4e450d758b
5 files changed
+392 -126

No files matched your search

+20
View File
@@ -186,6 +186,7 @@ def test_auth_system():
"getCurrentUser",
"isGuest",
"login",
"register",
"loginAsGuest",
"logout",
"getUserData",
@@ -193,6 +194,8 @@ def test_auth_system():
"flushSave",
"scheduleSave",
"apiPost",
"validateUsername",
"validatePassword"
]
for m in auth_methods:
if m in auth_code:
@@ -205,6 +208,19 @@ def test_auth_system():
record("auth.js has debounced save (scheduleSave)", "PASS" if "scheduleSave" in auth_code else "FAIL")
record("auth.js has flushSave for game-over sync", "PASS" if "flushSave" in auth_code else "FAIL")
# Check HTML auth views
index_html_path = os.path.join(GAME_DIR, "index.html")
with open(index_html_path, "r", encoding="utf-8") as f:
html_code = f.read()
record("Auth Login view present", "PASS" if 'id="auth-login-view"' in html_code else "FAIL")
record("Auth Register view present", "PASS" if 'id="auth-register-view"' in html_code else "FAIL")
record("Auth Logged-in view present", "PASS" if 'id="auth-logged-in-view"' in html_code else "FAIL")
record("Auth switch to register button present", "PASS" if 'id="btn-auth-to-register"' in html_code else "FAIL")
record("Auth do register button present", "PASS" if 'id="btn-auth-do-register"' in html_code else "FAIL")
record("Auth guest button present", "PASS" if 'id="btn-auth-guest"' in html_code else "FAIL")
record("Auth logout button present", "PASS" if 'id="btn-auth-logout"' in html_code else "FAIL")
# Server-side SQLite DB tests
print("\n--- 4b. SQLite DB & Auth API CRUD Tests ---")
sys.path.insert(0, os.path.join(BASE_DIR, "scripts"))
@@ -233,6 +249,10 @@ def test_auth_system():
record("SQLite DB: reject wrong password", "PASS" if bad_auth and not bad_auth.get("success") else "FAIL",
"Bad password was accepted!" if bad_auth and bad_auth.get("success") else "")
# Test duplicate registration rejection
dup_reg = pvz_db.register_user("kopri", "c63bc483")
record("SQLite DB: reject duplicate user registration", "PASS" if not dup_reg.get("success") else "FAIL")
# Test save profile (update newbie coins)
save_res = pvz_db.save_user_profile("newbie_test", {"coins": 999, "level": 3, "highScore": 2500})
record("SQLite DB: save_user_profile() succeeds", "PASS" if save_res.get("success") else "FAIL")