fix: missed update user's password

pull/4945/head v3.25.1
Andy Hsu 2023-08-07 18:51:54 +08:00
parent 353dd7f796
commit a797494aa3
3 changed files with 9 additions and 3 deletions

View File

@ -22,7 +22,7 @@ type User struct {
Username string `json:"username" gorm:"unique" binding:"required"` // username
PwdHash string `json:"-"` // password hash
Salt string // unique salt
Password string `json:"-"` // Deprecated password
Password string `json:"password"` // password
BasePath string `json:"base_path"` // base path
Role int `json:"role"` // user's role
Disabled bool `json:"disabled"`

View File

@ -115,7 +115,7 @@ func UpdateCurrent(c *gin.Context) {
user := c.MustGet("user").(*model.User)
user.Username = req.Username
if req.Password != "" {
user.Password = req.Password
user.SetPassword(req.Password)
}
user.SsoID = req.SsoID
if err := op.UpdateUser(user); err != nil {

View File

@ -39,6 +39,8 @@ func CreateUser(c *gin.Context) {
common.ErrorStrResp(c, "admin or guest user can not be created", 400, true)
return
}
req.SetPassword(req.Password)
req.Password = ""
if err := op.CreateUser(&req); err != nil {
common.ErrorResp(c, err, 500, true)
} else {
@ -62,7 +64,11 @@ func UpdateUser(c *gin.Context) {
return
}
if req.Password == "" {
req.Password = user.Password
req.PwdHash = user.PwdHash
req.Salt = user.Salt
} else {
req.SetPassword(req.Password)
req.Password = ""
}
if req.OtpSecret == "" {
req.OtpSecret = user.OtpSecret