addServer static method
Future<void>
addServer(
- String email,
- WardenType wardenType,
- SchemaMetaData smd,
- SchemaMetaData smdSys,
- DbTransaction transaction,
Implementation
static Future<void> addServer(
String email,
WardenType wardenType,
SchemaMetaData smd,
SchemaMetaData smdSys,
DbTransaction transaction) async {
UserDao userDao = UserDao(smd, transaction);
await userDao.init();
int count = 0;
try {
List<UserDto> list =
await userDao.getUserDtoList(null, null, null, wardenType, null);
count = list.length;
} on SqlException catch (e) {
if (e.sqlExceptionEnum == SqlExceptionEnum.ENTRY_NOT_FOUND ||
e.sqlExceptionEnum == SqlExceptionEnum.FAILED_SELECT) {
} else
rethrow;
}
count++;
StringUtils stringUtils = StringUtils();
String passKey = stringUtils.randomAlphaNumericString(20);
UserDto userDto = UserDto.sep(null, passKey, count, wardenType, 0, 0);
int requestOffsetSecs = NumberUtils.randInt(0, TimeUtils.C_SECS_IN_DAY);
RemoteDto? remoteDto = await CrudHelper.insertUser(
null,
passKey,
count,
wardenType,
requestOffsetSecs,
TimeUtils.getNowCustomTs(),
transaction,
WardenType.WRITE_SERVER,
WardenType.WRITE_SERVER,
smd,
smdSys);
await CrudHelper.insertUserStore(
remoteDto!.trDto.id,
email,
0,
null,
null,
0,
0,
0,
transaction,
WardenType.WRITE_SERVER,
WardenType.WRITE_SERVER,
smd,
smdSys);
if (remoteDto != null) {
userDto = UserDto.field(remoteDto.trDto.getFieldDataNoTr);
print("insert into user values ('" +
userDto.id.toString() +
"','" +
userDto.pass_key.toString() +
"'," +
userDto.subset.toString() +
"," +
userDto.warden.toString() +
"," +
userDto.request_offset_secs.toString() +
"," +
userDto.registered_ts.toString() +
");");
}
await transaction.connection.close();
await transaction.endTransaction();
await transaction.closePool();
if (remoteDto != null) {
print("");
print("Now type on the client :");
print(C_CMD_ROCKVOLE+" setuser " +
remoteDto.trDto.id.toString() +
" $email $passKey " +
Warden.getSimpleWardenString(wardenType));
print(C_CMD_ROCKVOLE+" setserverid " + remoteDto.trDto.id.toString());
}
}