Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add reset user password action #1320

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 18 commits into from
May 6, 2022
Merged
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
Return hash error as server error
  • Loading branch information
BrunoQuaresma committed May 5, 2022
commit 355f1631928a87675275d58ed2b4656e70fdff57
13 changes: 7 additions & 6 deletions coderd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@ func (api *api) putUserSuspend(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(rw, http.StatusOK, convertUser(suspendedUser, organizations))
}

func (api *api) putUserPassword(rw http.ResponseWriter, r *http.Request) error {
func (api *api) putUserPassword(rw http.ResponseWriter, r *http.Request) {
user := httpmw.UserParam(r)

var params codersdk.UpdateUserPasswordRequest
if !httpapi.Read(rw, r, &params) {
return nil
return
}

// Check if the new password and the confirmation match
Expand All @@ -380,13 +380,15 @@ func (api *api) putUserPassword(rw http.ResponseWriter, r *http.Request) error {
Message: fmt.Sprintf("The new password and the new password confirmation don't match"),
Errors: requestErrors,
})
return nil
return
}

// Hash password and update it in the database
hashedPassword, hashError := userpassword.Hash(params.NewPassword)
if hashError != nil {
return xerrors.Errorf("hash password: %w", hashError)
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("hash password: %s", hashError.Error()),
})
}
databaseError := api.Database.UpdateUserHashedPassword(r.Context(), database.UpdateUserHashedPasswordParams{
ID: user.ID,
Expand All @@ -396,11 +398,10 @@ func (api *api) putUserPassword(rw http.ResponseWriter, r *http.Request) error {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("put user password: %s", databaseError.Error()),
})
return nil
return
}

httpapi.Write(rw, http.StatusNoContent, nil)
return nil
}

func (api *api) userRoles(rw http.ResponseWriter, r *http.Request) {
Expand Down