feat(api): require bearer authentication and unify response contracts

This commit is contained in:
eezd committed 2026-10-25 20:42:20 +08:00
1 parent 30e361cd10
commit 1b2b2b12ff
19 files changed
+1799 -314

No files matched your search

+2 -7
View File
@@ -87,16 +87,11 @@ func (s *Server) changePassword(w http.ResponseWriter, r *http.Request) {
if !readJSON(w, r, &body) {
return
}
c, err := r.Cookie(cookieName)
if err != nil {
writeError(w, 401, "未登录")
return
}
switch err := s.auth.ChangePassword(clientIP(r), c.Value, body.Current, body.Next); {
switch err := s.auth.ChangePassword(clientIP(r), identity(r).Token, body.Current, body.Next); {
case errors.Is(err, auth.ErrRateLimited):
writeError(w, 429, err.Error())
case errors.Is(err, auth.ErrBadCredentials):
writeError(w, 401, "当前密码错误")
writeFailure(w, 400, CodeCurrentPassword, "当前密码错误", nil)
case errors.Is(err, auth.ErrWeakPassword):
writeError(w, 400, err.Error())
case err != nil: