mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
[Server] Serve account registration from the database interface (#7841)
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:
parent
7719ff021c
commit
d05198101d
4 changed files with 21 additions and 11 deletions
|
|
@ -475,6 +475,11 @@ public:
|
||||||
{
|
{
|
||||||
return false;
|
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 */)
|
virtual void updateUsersClientID(const QString & /* userName */, const QString & /* userClientID */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -359,6 +359,13 @@ bool Servatrice_DatabaseInterface::registerUser(const QString &userName,
|
||||||
return true;
|
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)
|
bool Servatrice_DatabaseInterface::activateUser(const QString &userName, const QString &token)
|
||||||
{
|
{
|
||||||
if (!checkSql()) {
|
if (!checkSql()) {
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,7 @@ public:
|
||||||
const QString &country,
|
const QString &country,
|
||||||
bool active = false) override;
|
bool active = false) override;
|
||||||
bool activateUser(const QString &userName, const QString &token) 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 updateUsersClientID(const QString &userName, const QString &userClientID) override;
|
||||||
void updateUsersLastLoginData(const QString &userName, const QString &clientVersion) override;
|
void updateUsersLastLoginData(const QString &userName, const QString &clientVersion) override;
|
||||||
void logMessage(const int senderId,
|
void logMessage(const int senderId,
|
||||||
|
|
|
||||||
|
|
@ -3100,7 +3100,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
|
||||||
|
|
||||||
//! \todo Move this method outside of the db interface.
|
//! \todo Move this method outside of the db interface.
|
||||||
QString errorString;
|
QString errorString;
|
||||||
if (!sqlInterface->usernameIsValid(userName, errorString)) {
|
if (!databaseInterface->usernameIsValid(userName, errorString)) {
|
||||||
if (servatrice->getEnableRegistrationAudit()) {
|
if (servatrice->getEnableRegistrationAudit()) {
|
||||||
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
|
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
|
||||||
"REGISTER_ACCOUNT", "Username is invalid", false);
|
"REGISTER_ACCOUNT", "Username is invalid", false);
|
||||||
|
|
@ -3121,7 +3121,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
|
||||||
return Response::RespUsernameInvalid;
|
return Response::RespUsernameInvalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sqlInterface->userExists(userName)) {
|
if (databaseInterface->userExists(userName)) {
|
||||||
if (servatrice->getEnableRegistrationAudit()) {
|
if (servatrice->getEnableRegistrationAudit()) {
|
||||||
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
|
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
|
||||||
"REGISTER_ACCOUNT", "Username already exists", false);
|
"REGISTER_ACCOUNT", "Username already exists", false);
|
||||||
|
|
@ -3132,7 +3132,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
|
||||||
|
|
||||||
const auto parsedEmailAddress = EmailParser::getParsedEmailAddress(parsedEmailParts);
|
const auto parsedEmailAddress = EmailParser::getParsedEmailAddress(parsedEmailParts);
|
||||||
if (servatrice->getMaxAccountsPerEmail() > 0 &&
|
if (servatrice->getMaxAccountsPerEmail() > 0 &&
|
||||||
sqlInterface->checkNumberOfUserAccounts(parsedEmailAddress) >= servatrice->getMaxAccountsPerEmail()) {
|
databaseInterface->checkNumberOfUserAccounts(parsedEmailAddress) >= servatrice->getMaxAccountsPerEmail()) {
|
||||||
if (servatrice->getEnableRegistrationAudit()) {
|
if (servatrice->getEnableRegistrationAudit()) {
|
||||||
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
|
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
|
||||||
"REGISTER_ACCOUNT",
|
"REGISTER_ACCOUNT",
|
||||||
|
|
@ -3144,7 +3144,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdRegisterAccount(const C
|
||||||
|
|
||||||
QString banReason;
|
QString banReason;
|
||||||
int banSecondsRemaining;
|
int banSecondsRemaining;
|
||||||
if (sqlInterface->checkUserIsBanned(this->getAddress(), userName, clientId, banReason, banSecondsRemaining)) {
|
if (databaseInterface->checkUserIsBanned(this->getAddress(), userName, clientId, banReason, banSecondsRemaining)) {
|
||||||
if (servatrice->getEnableRegistrationAudit()) {
|
if (servatrice->getEnableRegistrationAudit()) {
|
||||||
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
|
databaseInterface->addAuditRecord(userName.simplified(), this->getAddress(), clientId.simplified(),
|
||||||
"REGISTER_ACCOUNT", "User is banned", false);
|
"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 requireEmailActivation = settingsCache->value("registration/requireemailactivation", true).toBool();
|
||||||
bool regSucceeded = sqlInterface->registerUser(userName, realName, password, passwordNeedsHash, parsedEmailAddress,
|
bool regSucceeded = databaseInterface->registerUser(userName, realName, password, passwordNeedsHash,
|
||||||
country, !requireEmailActivation);
|
parsedEmailAddress, country, !requireEmailActivation);
|
||||||
|
|
||||||
if (regSucceeded) {
|
if (regSucceeded) {
|
||||||
qCDebug(AbstractServerSocketInterfaceLog) << "Accepted register command for user:" << userName;
|
qCDebug(AbstractServerSocketInterfaceLog) << "Accepted register command for user:" << userName;
|
||||||
if (requireEmailActivation) {
|
if (requireEmailActivation) {
|
||||||
QSqlQuery *query =
|
if (!databaseInterface->addActivationEmail(userName)) {
|
||||||
sqlInterface->prepareQuery("insert into {prefix}_activation_emails (name) values(:name)");
|
|
||||||
query->bindValue(":name", userName);
|
|
||||||
if (!sqlInterface->execSqlQuery(query)) {
|
|
||||||
return Response::RespRegistrationFailed;
|
return Response::RespRegistrationFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3285,7 +3282,7 @@ Response::ResponseCode AbstractServerSocketInterface::cmdActivateAccount(const C
|
||||||
clientId = "UNKNOWN";
|
clientId = "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sqlInterface->activateUser(userName, token)) {
|
if (databaseInterface->activateUser(userName, token)) {
|
||||||
qCDebug(AbstractServerSocketInterfaceLog) << "Accepted activation for user" << userName;
|
qCDebug(AbstractServerSocketInterfaceLog) << "Accepted activation for user" << userName;
|
||||||
|
|
||||||
if (servatrice->getEnableRegistrationAudit()) {
|
if (servatrice->getEnableRegistrationAudit()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue