mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-22 08:38:03 +01:00
fixed no need to provide old password when initialization.
This commit is contained in:
parent
fc2fda0efe
commit
ea063c13df
12
dao/user.go
12
dao/user.go
@ -135,9 +135,17 @@ func ToggleUserAdminRole(u models.User) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func ChangeUserPassword(u models.User, oldPassword string) error {
|
||||
func ChangeUserPassword(u models.User, oldPassword ...string) error {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Raw(`update user set password=?, salt=? where user_id=? and password = ?`, utils.Encrypt(u.Password, u.Salt), u.Salt, u.UserId, utils.Encrypt(oldPassword, u.Salt)).Exec()
|
||||
//In some cases, it may no need to check old password, just as Linux change password polies.
|
||||
var err error
|
||||
if len(oldPassword) == 0 {
|
||||
_, err = o.Raw(`update user set password=?, salt=? where user_id=?`, utils.Encrypt(u.Password, u.Salt), u.Salt, u.UserId).Exec()
|
||||
} else if len(oldPassword) == 1 {
|
||||
_, err = o.Raw(`update user set password=?, salt=? where user_id=? and password = ?`, utils.Encrypt(u.Password, u.Salt), u.Salt, u.UserId, utils.Encrypt(oldPassword[0], u.Salt)).Exec()
|
||||
} else {
|
||||
err = errors.New("Wrong numbers of params.")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
4
main.go
4
main.go
@ -38,7 +38,7 @@ func updateInitPassword(userId int, password string) error {
|
||||
queryUser := models.User{UserId: userId}
|
||||
user, err := dao.GetUser(queryUser)
|
||||
if err != nil {
|
||||
log.Println("Failed to get user in initial password, userId:", userId)
|
||||
log.Println("Failed to get user's initial password, userId:", userId)
|
||||
return err
|
||||
}
|
||||
if user == nil {
|
||||
@ -52,7 +52,7 @@ func updateInitPassword(userId int, password string) error {
|
||||
}
|
||||
user.Salt = salt
|
||||
user.Password = password
|
||||
err = dao.ChangeUserPassword(*user, password)
|
||||
err = dao.ChangeUserPassword(*user)
|
||||
if err != nil {
|
||||
log.Printf("Failed to update user encrypted password, userId: %d, err: %v", userId, err)
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user