3 Commits

Author SHA1 Message Date
Bingxi Zhao (Frank)
42cf57bf96 fix(auth): scope password changes and expose temporary-password state 2026-10-31 17:15:58 +08:00
yuleihaotong
35512dccff feat(auth): prompt users who still hold an admin-assigned password
Creating an account through the admin UI means the administrator picks the
password, so the owner starts life with a secret someone else knows. Nothing
in the UI said so: the password form existed, but nobody was sent to it.

- identity: accounts carry must_change_password, set on admin creation and
  cleared once the owner changes the password themselves
- POST /login returns the flag so the client can act on it right away
- GET /profile exposes it for the profile page
- web: after login, a flagged account goes straight to /profile, which shows
  why; the banner disappears once the change succeeds

Backend tests cover both directions: a successful change clears the flag, a
failed one (wrong current password) leaves it alone.
2026-10-30 17:44:24 +08:00
yuleihaotong
1606c9e702 feat(auth): add password change endpoints and accept CJK usernames
Two gaps surfaced while running DeepTutor for a staff roster:

1. No endpoint changed a password. The service layer already had
   identity.set_password(), but nothing exposed it, so an account whose
   password was lost could only be fixed by editing users.json by hand.

   - PUT /api/auth/profile/password  (self-service, verifies the current
     password so a stolen session alone cannot take the account over)
   - PUT /api/auth/users/{username}/password  (admin reset, require_admin)

2. The username validator only accepted [A-Za-z0-9_-.]{3,64}, so real
   names such as 于冬阳 were rejected — with an error message that said
   'enter a valid email address', which pointed at the wrong problem.
   CJK-only names now allow two characters (张伟) where Latin usernames
   still require three (abc); the message names both accepted forms.
2026-10-30 10:14:56 +08:00