fix: 开启自助注册须先有 8-64 字符安全码

This commit is contained in:
Nixevol
2026-09-30 16:21:51 +08:00
parent 659373e142
commit 8c20b76df5
9 changed files with 230 additions and 8 deletions
+13 -3
View File
@@ -77,9 +77,7 @@ func (h *Handler) handleRegistrationPut(w http.ResponseWriter, r *http.Request)
); e != nil {
return e
}
return nil
}
if req.Code != nil {
} else if req.Code != nil {
code := *req.Code
n := utf8.RuneCountInString(code)
if n < minRegistrationCodeLen || n > maxRegistrationCodeLen {
@@ -93,6 +91,18 @@ func (h *Handler) handleRegistrationPut(w http.ResponseWriter, r *http.Request)
return e
}
}
var enabledVal, codeVal sql.NullString
if e := tx.QueryRow(`SELECT value FROM settings WHERE key = ?`, settingRegistrationEnabled).Scan(&enabledVal); e != nil && !errors.Is(e, sql.ErrNoRows) {
return e
}
if e := tx.QueryRow(`SELECT value FROM settings WHERE key = ?`, settingRegistrationCode).Scan(&codeVal); e != nil && !errors.Is(e, sql.ErrNoRows) {
return e
}
n := utf8.RuneCountInString(codeVal.String)
if registrationTruthy(enabledVal.String) && (n < minRegistrationCodeLen || n > maxRegistrationCodeLen) {
return errBadRequest("开启自助注册前须先设置 8–64 字符的安全码")
}
return nil
})
if err != nil {