recoverAccess method

Future<void> recoverAccess()

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

Implementation

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

  _recoveryLogin = _recoveryNum = _recoveryPhone = _recoveryEmail = null;

  // Parse the [recovery] input.
  try {
    _recoveryNum = UserNum(recovery.text);
  } catch (_) {
    try {
      _recoveryPhone = UserPhone(recovery.text);
    } catch (_) {
      try {
        _recoveryLogin = UserLogin(recovery.text.toLowerCase());
      } catch (_) {
        try {
          _recoveryEmail = UserEmail(recovery.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(),
      );
    }

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