changePassword static method

Future<void> changePassword(
  1. String oldPassword,
  2. String newPassword, {
  3. MBManager? manager,
})

Change the password of the current logged in user.

  • Parameters:
    • oldPassword: The old password of the user.
    • newPassword: The new password of the user.
    • manager: An optional MBManager used to make calls instead of MBManager.shared.
  • Returns a Future that completes when the api is called with success.

Implementation

static Future<void> changePassword(
  String oldPassword,
  String newPassword, {
  MBManager? manager,
}) async {
  MBManager mbManager = manager ?? MBManager.shared;

  String apiName = 'api/change-password';

  var uri = Uri.https(mbManager.endpoint, apiName);

  Map<String, String> apiParameters = {};
  apiParameters['old_password'] = oldPassword;
  apiParameters['new_password'] = newPassword;
  apiParameters.addAll(await mbManager.defaultParameters());

  var requestBody = json.encode(apiParameters);

  Map<String, String> headers =
      await mbManager.headers(contentTypeJson: true);

  http.Response response = await http.post(
    uri,
    headers: headers,
    body: requestBody,
  );

  MBManager.checkResponse(response.body, checkBody: false);
}