fix: 开启自助注册须先有 8-64 字符安全码
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user