changePassword method

  1. @override
Future<RequestResponse<bool?>> changePassword({
  1. required String oldPassword,
  2. required String newPassword,
})
override

Changes the password of the currently logged in user.

Validates the old (current) password before changing it.

Validates for compliance with the Password Policy (zxcvbn).

Implementation

@override
Future<RequestResponse<bool?>> changePassword({
  required String oldPassword,
  required String newPassword,
}) async {
  await getFrappe().checkAppInstalled(features: ['changePassword']);

  assert(oldPassword.isNotEmpty && newPassword.isNotEmpty,
      'Passwords cannot be empty');
  assert(isLoggedIn, 'Need to be signed in to change password');

  final response = await Request.initiateRequest(
    url: config.hostUrl,
    method: HttpMethod.POST,
    contentType: ContentTypeLiterals.APPLICATION_JSON,
    data: <String, dynamic>{
      'cmd': 'renovation_core.utils.auth.change_password',
      'old_password': oldPassword,
      'new_password': newPassword
    },
  );

  if (response.isSuccess) {
    return RequestResponse.success(
      response.isSuccess,
      rawResponse: response.rawResponse,
    );
  } else {
    return RequestResponse.fail(handleError('change_pwd', response.error))
      ..data = false;
  }
}