setPassword method

Future<void> setPassword()

Validates and sets the password of the currently authenticated MyUser.

Implementation

Future<void> setPassword() async {
  if (password.error.value != null ||
      repeat.error.value != null ||
      !password.editable.value ||
      !repeat.editable.value) {
    return;
  }

  if (password.text.isEmpty) {
    password.error.value = 'err_password_empty'.l10n;
    return;
  }

  if (repeat.text.isEmpty) {
    repeat.error.value = 'err_repeat_password_empty'.l10n;
    return;
  }

  password.editable.value = false;
  repeat.editable.value = false;
  password.status.value = RxStatus.loading();
  repeat.status.value = RxStatus.loading();
  try {
    await _myUserService.updateUserPassword(
      newPassword: UserPassword(repeat.text),
    );
    password.status.value = RxStatus.success();
    repeat.status.value = RxStatus.success();
    await Future.delayed(1.seconds);
    stage.value = ConfirmLogoutViewStage.success;
  } on UpdateUserPasswordException catch (e) {
    repeat.error.value = e.toMessage();
  } catch (e) {
    repeat.resubmitOnError.value = true;
    repeat.error.value = 'err_data_transfer'.l10n;
    rethrow;
  } finally {
    password.status.value = RxStatus.empty();
    repeat.status.value = RxStatus.empty();
    password.editable.value = true;
    repeat.editable.value = true;
  }
}