[Server] Serve account registration from the database interface

cmdRegisterAccount and cmdActivateAccount still called
Servatrice_DatabaseInterface for username validation, user existence, the
per-email account limit, ban checks, registration and activation, and
cmdRegisterAccount issued the activation-email insert inline. Add
addActivationEmail to Server_DatabaseInterface with a false default, implement
it with the same statement and bind value, and let both commands ask the
injected interface. Validation order and every response code are unchanged.
This commit is contained in:
Lukas Brübach 2026-11-10 00:59:09 +01:00
parent 80d92d1611
commit 56c8593a19
4 changed files with 21 additions and 11 deletions

View file

@ -3100,7 +3100,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
//! \todo Move this method outside of the db interface.
QString errorString;
if (!sqlInterface->usernameIsValid(userName, errorString)) {
if (!databaseInterface->usernameIsValid(userName, errorString)) {
if (servatrice->getEnableRegistrationAudit()) {
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Username is invalid", false);
@ -3121,7 +3121,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
return Response::RespUsernameInvalid;
}
if (sqlInterface->userExists(userName)) {
if (databaseInterface->userExists(userName)) {
if (servatrice->getEnableRegistrationAudit()) {
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "Username already exists", false);
@ -3132,7 +3132,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
const auto parsedEmailAddress = EmailParser::getParsedEmailAddress(parsedEmailParts);
if (servatrice->getMaxAccountsPerEmail() > 0 &&
sqlInterface->checkNumberOfUserAccounts(parsedEmailAddress) >= servatrice->getMaxAccountsPerEmail()) {
databaseInterface->checkNumberOfUserAccounts(parsedEmailAddress) >= servatrice->getMaxAccountsPerEmail()) {
if (servatrice->getEnableRegistrationAudit()) {
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT",
@ -3144,7 +3144,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
QString banReason;
int banSecondsRemaining;
if (sqlInterface->checkUserIsBanned(this->getAddress(), userName, clientId, banReason, banSecondsRemaining)) {
if (databaseInterface->checkUserIsBanned(this->getAddress(), userName, clientId, banReason, banSecondsRemaining)) {
if (servatrice->getEnableRegistrationAudit()) {
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
"REGISTER_ACCOUNT", "User is banned", false);
@ -3207,16 +3207,13 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
}
bool requireEmailActivation = settingsCache->value("registration/requireemailactivation", true).toBool();
bool regSucceeded = sqlInterface->registerUser(userName, realName, password, passwordNeedsHash, parsedEmailAddress,
country, !requireEmailActivation);
bool regSucceeded = databaseInterface->registerUser(userName, realName, password, passwordNeedsHash,
parsedEmailAddress, country, !requireEmailActivation);
if (regSucceeded) {
qCDebug(AbstractServerSocketInterfaceLog) << "Accepted register command for user:" << userName;
if (requireEmailActivation) {
QSqlQuery *query =
sqlInterface->prepareQuery("insert into {prefix}_activation_emails (name) values(:name)");
query->bindValue(":name", userName);
if (!sqlInterface->execSqlQuery(query)) {
if (!databaseInterface->addActivationEmail(userName)) {
return Response::RespRegistrationFailed;
}
@ -3285,7 +3282,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdActivateAccount(const C
clientId = "UNKNOWN";
}
if (sqlInterface->activateUser(userName, token)) {
if (databaseInterface->activateUser(userName, token)) {
qCDebug(AbstractServerSocketInterfaceLog) << "Accepted activation for user" << userName;
if (servatrice->getEnableRegistrationAudit()) {