requestAuthenticationFromServer method

Future<RemoteDto> requestAuthenticationFromServer(
  1. int version, {
  2. String? serverDatabase,
  3. String? testPassword,
})

Implementation

Future<RemoteDto> requestAuthenticationFromServer(int version,
    {String? serverDatabase, String? testPassword}) async {
  if (initialized == false) throw ArgumentError(AbstractDao.C_MUST_INIT);
  RemoteDto remoteDto =
      await sendAuthenticationRequest(version, serverDatabase, testPassword);
  if (remoteDto.water_table_id == RemoteStatusDto.C_TABLE_ID) {
    RemoteStatusDto remoteState = remoteDto as RemoteStatusDto;
    print("State=$remoteState");
    switch (remoteState.getStatus()) {
      case RemoteStatus.FRESH_PASSKEY:
        UserDto? userDto =
            await userTools.getCurrentUserDto(smd, transaction);
        print("get fresh $userDto");
        userDto!.pass_key =
            ""; // Email address is only sent when passKey is empty
        await userTools.setCurrentUserDto(smd, transaction, userDto);
        remoteDto = await sendAuthenticationRequest(
            version, serverDatabase, testPassword);
        break;
      default:
        throw TransmitStatusException(null,
            remoteStatus: remoteState.getStatus(),
            cause: "Send Authentication");
    }
  }
  if (remoteDto.water_table_id == UserMixin.C_TABLE_ID) {
    UserChangeEnum? userChangeEnum =
        await writeNewUser(UserDto.field(remoteDto.trDto));
    remoteDto = await sendAuthenticationRequest(
        version, serverDatabase, testPassword);
    if (userChangeListener != null)
      userChangeListener!.update(userChangeEnum);
    if (remoteDto.water_table_id == RemoteStatusDto.C_TABLE_ID) {
      RemoteStatusDto remoteState = remoteDto as RemoteStatusDto;
      throw TransmitStatusException(null,
          remoteStatus: remoteState.getStatus(),
          cause: "Send Authentication");
    }
  }
  return remoteDto;
}