feat(1.0): 调整密码编辑

This commit is contained in:
summer 2025-11-06 11:26:16 +08:00
parent 4001993e96
commit 110ecb2818

View File

@ -18,7 +18,7 @@ type modifyAdminRequest struct {
UserName string `json:"username" binding:"required"` // 用户名
NickName string `json:"nickname" binding:"required"` // 昵称
Mobile string `json:"mobile"` // 手机号
Password string `json:"password" binding:"required"` // 密码
Password string `json:"password"` // 密码
Avatar string `json:"avatar"` // 头像
}
@ -60,11 +60,11 @@ func (h *handler) ModifyAdmin() core.HandlerFunc {
return
}
if req.UserName == "" && req.NickName == "" && req.Password == "" {
if req.UserName == "" && req.NickName == "" {
ctx.AbortWithError(core.Error(
http.StatusBadRequest,
code.ParamBindError,
"用户名、昵称、密码为必填"),
"用户名、昵称为必填"),
)
return
}
@ -122,20 +122,22 @@ func (h *handler) ModifyAdmin() core.HandlerFunc {
return
}
hashedPassword, err := utils.GenerateAdminHashedPassword(req.Password)
if err != nil {
ctx.AbortWithError(core.Error(
http.StatusBadRequest,
code.ModifyAdminError,
fmt.Sprintf("%s: %s", code.Text(code.ModifyAdminError), err.Error())),
)
return
if req.Password != "" {
hashedPassword, err := utils.GenerateAdminHashedPassword(req.Password)
if err != nil {
ctx.AbortWithError(core.Error(
http.StatusBadRequest,
code.ModifyAdminError,
fmt.Sprintf("%s: %s", code.Text(code.ModifyAdminError), err.Error())),
)
return
}
checkIdInfo.Password = hashedPassword
}
checkIdInfo.Username = req.UserName
checkIdInfo.Nickname = req.NickName
checkIdInfo.Mobile = req.Mobile
checkIdInfo.Password = hashedPassword
checkIdInfo.Avatar = req.Avatar
checkIdInfo.UpdatedUser = ctx.SessionUserInfo().UserName
checkIdInfo.UpdatedAt = time.Now()