Beispiel #1
0
// Passwd changes a user's password.
func Passwd(username string, password string, newPassword string) error {
	client, err := New()

	if err != nil {
		return err
	}

	req := api.AuthPasswdRequest{Password: password, NewPassword: newPassword}

	if username != "" {
		req.Username = username
	}

	body, err := json.Marshal(req)

	if err != nil {
		return err
	}

	resBody, status, err := client.BasicRequest("POST", "/v1/auth/passwd/", body)

	if err != nil {
		return err
	}

	if status != 200 {
		return fmt.Errorf("Password change failed: %s", resBody)
	}

	fmt.Println("Password change succeeded.")
	return nil
}
Beispiel #2
0
// Passwd changes a user's password.
func Passwd(c *client.Client, username, password, newPassword string) error {
	req := api.AuthPasswdRequest{Password: password, NewPassword: newPassword}

	if username != "" {
		req.Username = username
	}

	body, err := json.Marshal(req)

	if err != nil {
		return err
	}

	_, err = c.BasicRequest("POST", "/v1/auth/passwd/", body)
	return err
}