Files
speaking-practice/docs/superpowers/plans/2026-06-05-speaking-lab-activation-auth.md
T
TTlaji 2d3ff21222
Deploy Speaking Practice / deploy (push) Successful in 24s
feat: add activation-code auth
2026-06-05 16:56:30 +08:00

4.3 KiB

Speaking Lab Activation Auth Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: Add activation-code registration, server-backed login, admin-only account/code management, and gated access to the learning pages.

Architecture: Reuse FastAPI and SQLite. Add focused auth helpers in backend/auth.py, extend backend/db.py for users and activation codes, expose auth/admin APIs in backend/main.py, then replace local fake login in frontend with a shared auth.js module and a new login.html/login.js.

Tech Stack: FastAPI, SQLite, plain HTML/CSS/JavaScript, Node syntax checks, Python compile checks.


Task 1: Backend Auth Storage And Helpers

Files:

  • Create: backend/auth.py

  • Modify: backend/db.py

  • Test: tests/auth_helpers_test.py

  • Add SQLite columns users.is_active and users.last_login_at in initialize_database.

  • Add activation_codes table and indexes in initialize_database.

  • Add user CRUD helpers, activation code helpers, and password hashing helpers.

  • Add signed token helpers in backend/auth.py.

  • Add focused Python tests for password hashing, token roundtrip, user creation, activation code use, and disabled user behavior.

Task 2: Backend Auth And Admin APIs

Files:

  • Modify: backend/main.py

  • Test: tests/auth_routes_test.py

  • Add Pydantic request models for login, register, code generation, and user status changes.

  • Add POST /api/auth/login, POST /api/auth/register, and GET /api/auth/session.

  • Extend admin dependency to accept either current HTTP Basic admin credentials or Authorization: Bearer <token> with admin role.

  • Add GET /api/admin/users, PATCH /api/admin/users/{user_id}, GET /api/admin/activation-codes, POST /api/admin/activation-codes, and DELETE /api/admin/activation-codes/{code_id}.

  • Add route tests for normal login, admin login, registration with activation code, reused code rejection, normal-user admin rejection, and admin code generation.

Task 3: Shared Frontend Auth And Login Page

Files:

  • Create: auth.js

  • Create: login.html

  • Create: login.js

  • Modify: styles.css

  • Test: tests/auth-ui-helpers.test.mjs

  • Add browser auth helpers for token storage, session check, logout, and authenticated fetch.

  • Build the centered login/register page inspired by the reference HTML.

  • Add login/register UI logic and frontend password confirmation checks.

  • Add CSS for the auth page card, form fields, mode switching, and messages.

  • Add Node tests for pure auth helper functions where practical.

Task 4: Gate Home And Study Pages

Files:

  • Modify: index.html

  • Modify: home.js

  • Modify: study.html

  • Modify: app.js

  • Modify: styles.css

  • Remove inline email login/register forms.

  • Load auth.js before page scripts.

  • Require a valid session before rendering home/study content.

  • Show username and logout in the top bar.

  • Show backend/admin entry only for admin users.

  • Remove duplicate study-entry control from the study-side/right-side area.

  • Keep existing browser-local learning progress data intact.

Task 5: Admin Account And Activation Code UI

Files:

  • Modify: admin.html

  • Modify: admin.js

  • Modify: styles.css

  • Test: existing admin Node tests plus syntax checks

  • Switch admin session to the shared bearer-token auth flow while keeping existing Basic helper functions exportable for tests if needed.

  • Add account management panel with user status rows and enable/disable buttons.

  • Add activation code panel with quantity input, generated code list, copy buttons, used status, and unused delete buttons.

  • Ensure material upload/edit/delete continues to use authenticated admin requests.

Task 6: Verification, Commit, Push

Files:

  • All changed files

  • Run Python compile checks.

  • Run backend route/helper tests.

  • Run Node syntax checks.

  • Run existing Node helper tests.

  • Start local server and smoke-test login, admin code generation, registration, normal-user blocking, and admin material page access.

  • Commit implementation.

  • Push to origin feature/deepseek-subtitle-ai.