1
0

Added the ability to update a users password

This commit is contained in:
konrad
2018-10-03 19:28:17 +02:00
parent 17368dea9a
commit 85c9fba808
4 changed files with 43 additions and 58 deletions

View File

@ -109,10 +109,10 @@ func UpdateUser(user User) (updatedUser User, err error) {
}
// UpdateUserPassword updates the password of a user
func UpdateUserPassword(userID int64, newPassword string, doer *User) (err error) {
func UpdateUserPassword(user *User, newPassword string) (err error) {
// Get all user details
user, err := GetUserByID(userID)
theUser, err := GetUserByID(user.ID)
if err != nil {
return err
}
@ -122,10 +122,10 @@ func UpdateUserPassword(userID int64, newPassword string, doer *User) (err error
if err != nil {
return err
}
user.Password = hashed
theUser.Password = hashed
// Update it
_, err = x.Id(user.ID).Update(user)
_, err = x.Id(user.ID).Update(theUser)
if err != nil {
return err
}

View File

@ -99,7 +99,7 @@ func TestCreateUser(t *testing.T) {
// Update a users password
newpassword := "55555"
err = UpdateUserPassword(theuser.ID, newpassword, &doer)
err = UpdateUserPassword(&theuser, newpassword)
assert.NoError(t, err)
// Check if it was changed
@ -116,7 +116,7 @@ func TestCreateUser(t *testing.T) {
assert.True(t, len(all) > 0)
// Try updating the password of a nonexistent user (should fail)
err = UpdateUserPassword(9999, newpassword, &doer)
err = UpdateUserPassword(&User{ID: 9999}, newpassword)
assert.Error(t, err)
assert.True(t, IsErrUserDoesNotExist(err))