updatePassword method

Future<void> updatePassword(
  1. String username,
  2. String password,
  3. String code
)

Updates the given username's password validating the change with the given code

Implementation

Future<void> updatePassword(
  String username,
  String password,
  String code,
) async {
  emit(state.startLoading(updatePasswordLoading));

  try {
    await provider.updatePassword(username, password, code);
    emit(state.copyWith(
      resetAwaitingVerification: true,
    ));
  } on InvalidCodeException catch (error, stackTrace) {
    emit(state.addMessage(
      Message.error(_localizations.invalidVerificationCode),
      error,
      stackTrace,
    ));
  } on ExpiredCodeException catch (error, stackTrace) {
    emit(state.addMessage(
      Message.error(_localizations.expiredVerificationCode),
      error,
      stackTrace,
    ));
  } on ResetPasswordLimitException catch (error, stackTrace) {
    emit(state.addMessage(
      Message.error(_localizations.resetPasswordLimit),
      error,
      stackTrace,
    ));
  } on UpdatePasswordException catch (error, stackTrace) {
    emit(state.addMessage(
      Message.error(
        _localizations.updatePasswordError(error.message),
      ),
      error,
      stackTrace,
    ));
  } finally {
    emit(state.endLoading(updatePasswordLoading));
  }
}