validateCode method

Future<void> validateCode()

Validates the provided password recovery ConfirmationCode for the MyUser identified by the provided in recoverAccess identity.

Implementation

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

  if (recoveryCode.text.isEmpty) {
    recoveryCode.editable.value = true;
    recoveryCode.status.value = RxStatus.empty();
    recoveryCode.error.value = 'err_input_empty'.l10n;
    return;
  }

  try {
    await _authService.validateConfirmationCode(
      login: _recoveryLogin,
      num: _recoveryNum,
      email: _recoveryEmail,
      phone: _recoveryPhone,
      code: ConfirmationCode(recoveryCode.text.toLowerCase()),
    );

    recoveryCode.editable.value = false;
    recoveryCode.status.value = RxStatus.success();
    stage.value = LoginViewStage.recoveryPassword;
  } on FormatException {
    recoveryCode.error.value = 'err_wrong_code'.l10n;
  } on ArgumentError {
    recoveryCode.error.value = 'err_wrong_code'.l10n;
  } on ValidateConfirmationCodeException catch (e) {
    recoveryCode.error.value = e.toMessage();
  } catch (e) {
    recoveryCode.unsubmit();
    recoveryCode.resubmitOnError.value = true;
    recoveryCode.error.value = 'err_data_transfer'.l10n;
    rethrow;
  } finally {
    recoveryCode.editable.value = true;
    recoveryCode.status.value = RxStatus.empty();
  }
}