Updated server to support "."

Now uses regex.
Added "."
Updated login message
This commit is contained in:
Matt Lowe 2015-04-16 23:50:05 +02:00
parent 302cb3ba4e
commit d5a1264bcb
2 changed files with 4 additions and 18 deletions

View file

@ -78,7 +78,7 @@ void MainWindow::processConnectionClosedEvent(const Event_ConnectionClosed &even
break; break;
} }
case Event_ConnectionClosed::SERVER_SHUTDOWN: reasonStr = tr("Scheduled server shutdown."); break; case Event_ConnectionClosed::SERVER_SHUTDOWN: reasonStr = tr("Scheduled server shutdown."); break;
case Event_ConnectionClosed::USERNAMEINVALID: reasonStr = tr("Invalid username.\nYou may only use A-Z, a-z, 0-9, _, and - in your username."); break; case Event_ConnectionClosed::USERNAMEINVALID: reasonStr = tr("Invalid username.\nYou may only use A-Z, a-z, 0-9, _, ., and - in your username."); break;
default: reasonStr = QString::fromStdString(event.reason_str()); default: reasonStr = QString::fromStdString(event.reason_str());
} }
QMessageBox::critical(this, tr("Connection closed"), tr("The server has terminated your connection.\nReason: %1").arg(reasonStr)); QMessageBox::critical(this, tr("Connection closed"), tr("The server has terminated your connection.\nReason: %1").arg(reasonStr));
@ -261,7 +261,7 @@ void MainWindow::loginError(Response::ResponseCode r, QString reasonStr, quint32
break; break;
} }
case Response::RespUsernameInvalid: case Response::RespUsernameInvalid:
QMessageBox::critical(this, tr("Error"), tr("Invalid username.\nYou may only use A-Z, a-z, 0-9, _, and - in your username.")); QMessageBox::critical(this, tr("Error"), tr("Invalid username.\nYou may only use A-Z, a-z, 0-9, _, ., and - in your username."));
break; break;
case Response::RespRegistrationRequired: case Response::RespRegistrationRequired:
QMessageBox::critical(this, tr("Error"), tr("This server requires user registration.")); QMessageBox::critical(this, tr("Error"), tr("This server requires user registration."));

View file

@ -98,22 +98,8 @@ bool Servatrice_DatabaseInterface::execSqlQuery(QSqlQuery *query)
bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user) bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user)
{ {
QString result; static QRegExp re = QRegExp("^[a-zA-Z0-9_\-\.]+$");
result.reserve(user.size()); return re.exactMatch(user);
foreach (const QChar& c, user) {
switch (c.category()) {
case QChar::Letter_Uppercase: //[A-Z]
case QChar::Letter_Lowercase: //[a-z]
case QChar::Number_DecimalDigit: //[0-9]
case QChar::Punctuation_Connector: //[_]
case QChar::Punctuation_Dash: //[-]
result += c;
default:
break;
}
}
result = result.trimmed();
return (result.size() == user.size());
} }
bool Servatrice_DatabaseInterface::getRequireRegistration() bool Servatrice_DatabaseInterface::getRequireRegistration()