changePassword method

  1. @override
Future<void> changePassword({
  1. required String newPassword,
  2. String? currentPassword,
  3. bool isExpired = false,
})
override

If isExpired is true, it changes an expired password (using the expired/first-time login session). Otherwise, it performs a normal password change (from settings) and requires currentPassword.

Implementation

@override
Future<void> changePassword({
  required String newPassword,
  String? currentPassword,
  bool isExpired = false,
}) async {
  final response = await _portalDio.post(
    !isExpired ? 'passwordMdy.do' : 'passwordFirstMdy.do',
    // TODO: Move credentials to form data
    queryParameters: !isExpired
        ? {
            "oldPassword": currentPassword,
            "userPassword": newPassword,
            "pwdForceMdy": "profile",
          }
        : null,
    data: isExpired
        ? {
            'pwdForceMdy': 'expired',
            'userPassword': newPassword,
            'confirmPassword': newPassword,
          }
        : null,
  );

  final body = jsonDecode(response.data);

  // API returns "success": "false" on failure (note the string "false")
  if (body['success'] != true) {
    throw Exception(
      body['returnMsg'] ?? 'Password change failed. Please try again.',
    );
  }
}