diff --git a/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h b/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h index ad9106a6e..41daf31d0 100644 --- a/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h +++ b/libcockatrice_network/libcockatrice/network/server/remote/server_database_interface.h @@ -475,6 +475,11 @@ public: { return false; } + /** @brief Queues the activation email lookup row for a freshly registered user. */ + virtual bool addActivationEmail(const QString & /* userName */) + { + return false; + } virtual void updateUsersClientID(const QString & /* userName */, const QString & /* userClientID */) { } diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index a777a23a9..4c9501eb1 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -359,6 +359,13 @@ bool Servatrice_DatabaseInterface::registerUser(const QString &userName, return true; } +bool Servatrice_DatabaseInterface::addActivationEmail(const QString &userName) +{ + QSqlQuery *query = prepareQuery("insert into {prefix}_activation_emails (name) values(:name)"); + query->bindValue(":name", userName); + return execSqlQuery(query); +} + bool Servatrice_DatabaseInterface::activateUser(const QString &userName, const QString &token) { if (!checkSql()) { diff --git a/servatrice/src/servatrice_database_interface.h b/servatrice/src/servatrice_database_interface.h index 4e18882c7..9bb90645a 100644 --- a/servatrice/src/servatrice_database_interface.h +++ b/servatrice/src/servatrice_database_interface.h @@ -199,6 +199,7 @@ public: const QString &country, bool active = false) override; bool activateUser(const QString &userName, const QString &token) override; + bool addActivationEmail(const QString &userName) override; void updateUsersClientID(const QString &userName, const QString &userClientID) override; void updateUsersLastLoginData(const QString &userName, const QString &clientVersion) override; void logMessage(const int senderId, diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index d1b043f10..ca5bb8597 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -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()) {