支持动态更新管理员密码和下载次数逻辑完善,优化相关错误处理和配置更新流程
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
type ConfigHandler struct{}
|
||||
@@ -52,6 +53,16 @@ func (h *ConfigHandler) UpdateConfig(c *gin.Context) {
|
||||
newConfig.Database.Path = config.GlobalConfig.Database.Path
|
||||
}
|
||||
|
||||
// 如果传入了明文密码,则重新生成 hash
|
||||
if newConfig.Security.AdminPassword != "" {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(newConfig.Security.AdminPassword), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, model.ErrorResponse(model.CodeInternalError, "Failed to hash password: "+err.Error()))
|
||||
return
|
||||
}
|
||||
newConfig.Security.AdminPasswordHash = string(hash)
|
||||
}
|
||||
|
||||
// 检查取件码长度是否变化
|
||||
pickupCodeLengthChanged := newConfig.Security.PickupCodeLength != config.GlobalConfig.Security.PickupCodeLength && newConfig.Security.PickupCodeLength > 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user