Skip to content

feat: Add update user password endpoint #1310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve readbility
  • Loading branch information
BrunoQuaresma committed May 5, 2022
commit 30b8f15172b50e6b80b422c68c1acf1501eeb0bc
2 changes: 1 addition & 1 deletion coderd/database/queries/users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ WHERE
-- name: GetUsers :many
SELECT
*
FROM
FROM
users
WHERE
CASE
Expand Down
13 changes: 7 additions & 6 deletions coderd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,20 @@ func (api *api) putUserPassword(rw http.ResponseWriter, r *http.Request) {
}

// Hash password and update it in the database
hashedPassword, hashError := userpassword.Hash(params.NewPassword)
if hashError != nil {
hashedPassword, err := userpassword.Hash(params.NewPassword)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("hash password: %s", hashError.Error()),
Message: fmt.Sprintf("hash password: %s", err.Error()),
})
return
}
databaseError := api.Database.UpdateUserHashedPassword(r.Context(), database.UpdateUserHashedPasswordParams{
err = api.Database.UpdateUserHashedPassword(r.Context(), database.UpdateUserHashedPasswordParams{
ID: user.ID,
HashedPassword: []byte(hashedPassword),
})
if databaseError != nil {
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("put user password: %s", databaseError.Error()),
Message: fmt.Sprintf("put user password: %s", err.Error()),
})
return
}
Expand Down
3 changes: 2 additions & 1 deletion codersdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ func (c *Client) SuspendUser(ctx context.Context, userID uuid.UUID) (User, error
return user, json.NewDecoder(res.Body).Decode(&user)
}

// Update user password
// UpdateUserPassword updates a user password.
// It calls PUT /users/{user}/password
func (c *Client) UpdateUserPassword(ctx context.Context, userID uuid.UUID, req UpdateUserPasswordRequest) error {
res, err := c.request(ctx, http.MethodPut, fmt.Sprintf("/api/v2/users/%s/password", uuidOrMe(userID)), req)
if err != nil {
Expand Down