mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
fix: improve password validation flow (#15132)
Refers to #14984 Currently, password validation is done backend side and is not explicit enough so it can be painful to create first users. We'd like to make this validation easier - but also duplicate it frontend side to make it smoother. Flows involved : - First user set password - New user set password - Change password --------- Co-authored-by: BrunoQuaresma <bruno_nonato_quaresma@hotmail.com>
This commit is contained in:
@ -178,6 +178,15 @@ type UpdateUserProfileRequest struct {
|
||||
Name string `json:"name" validate:"user_real_name"`
|
||||
}
|
||||
|
||||
type ValidateUserPasswordRequest struct {
|
||||
Password string `json:"password" validate:"required"`
|
||||
}
|
||||
|
||||
type ValidateUserPasswordResponse struct {
|
||||
Valid bool `json:"valid"`
|
||||
Details string `json:"details"`
|
||||
}
|
||||
|
||||
type UpdateUserAppearanceSettingsRequest struct {
|
||||
ThemePreference string `json:"theme_preference" validate:"required"`
|
||||
}
|
||||
@ -407,6 +416,20 @@ func (c *Client) UpdateUserProfile(ctx context.Context, user string, req UpdateU
|
||||
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
||||
}
|
||||
|
||||
// ValidateUserPassword validates the complexity of a user password and that it is secured enough.
|
||||
func (c *Client) ValidateUserPassword(ctx context.Context, req ValidateUserPasswordRequest) (ValidateUserPasswordResponse, error) {
|
||||
res, err := c.Request(ctx, http.MethodPost, "/api/v2/users/validate-password", req)
|
||||
if err != nil {
|
||||
return ValidateUserPasswordResponse{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return ValidateUserPasswordResponse{}, ReadBodyAsError(res)
|
||||
}
|
||||
var resp ValidateUserPasswordResponse
|
||||
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
||||
}
|
||||
|
||||
// UpdateUserStatus sets the user status to the given status
|
||||
func (c *Client) UpdateUserStatus(ctx context.Context, user string, status UserStatus) (User, error) {
|
||||
path := fmt.Sprintf("/api/v2/users/%s/status/", user)
|
||||
|
Reference in New Issue
Block a user