recoverAccess method

Future<void> recoverAccess()

Initiates password recovery for the MyUser identified by the provided recoveryIdentifier input and stores the parsed value.

Implementation

Future<void> recoverAccess() async {
  recoveryIdentifier.editable.value = false;
  recoveryIdentifier.status.value = RxStatus.loading();
  recoveryIdentifier.error.value = null;

  _recoveryLogin = _recoveryNum = _recoveryPhone = _recoveryEmail = null;

  // Parse the [recovery] input.
  try {
    _recoveryNum = UserNum(recoveryIdentifier.text);
  } catch (_) {
    try {
      _recoveryPhone = UserPhone(recoveryIdentifier.text);
    } catch (_) {
      try {
        _recoveryLogin = UserLogin(recoveryIdentifier.text.toLowerCase());
      } catch (_) {
        try {
          _recoveryEmail = UserEmail(recoveryIdentifier.text.toLowerCase());
        } catch (_) {
          // No-op.
        }
      }
    }
  }

  try {
    if (_recoveryLogin != null ||
        _recoveryNum != null ||
        _recoveryEmail != null ||
        _recoveryPhone != null) {
      await _authService.createConfirmationCode(
        login: _recoveryLogin,
        num: _recoveryNum,
        email: _recoveryEmail,
        phone: _recoveryPhone,
        locale: L10n.chosen.value?.toString(),
      );
    }

    page.value = IntroductionStage.recoveryCode;
    recoveryIdentifier.status.value = RxStatus.success();
    recoveryIdentifier.editable.value = false;
  } catch (e) {
    recoveryIdentifier.unsubmit();
    recoveryIdentifier.resubmitOnError.value = true;
    recoveryIdentifier.error.value = 'err_data_transfer'.l10n;
    rethrow;
  } finally {
    recoveryIdentifier.status.value = RxStatus.empty();
    recoveryIdentifier.editable.value = true;
  }
}