mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
Almost completed registration
* added missing bits of serverside code; * added fronted in client; * removed demo python scripts;
This commit is contained in:
parent
735fcbf311
commit
5ace0dd892
20 changed files with 585 additions and 112 deletions
|
|
@ -27,8 +27,8 @@ message Response {
|
|||
RespRegistrationAccepted = 23; // Server agrees to process client's registration request
|
||||
RespUserAlreadyExists = 24; // Client attempted to register a name which is already registered
|
||||
RespEmailRequiredToRegister = 25; // Server requires email to register accounts but client did not provide one
|
||||
RespServerDoesNotUseAuth = 26; // Client attempted to register but server does not use authentication
|
||||
RespTooManyRequests = 27; // Server refused to complete command because client has sent too many too quickly
|
||||
RespTooManyRequests = 26; // Server refused to complete command because client has sent too many too quickly
|
||||
RespPasswordTooShort = 27; // Server requires a decent password
|
||||
RespAccountNotActivated = 28; // Client attempted to log into a registered username but the account hasn't been activated
|
||||
RespRegistrationDisabled = 29; // Server does not allow clients to register
|
||||
RespRegistrationFailed = 30; // Server accepted a reg request but failed to perform the registration
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
|||
QWriteLocker locker(&clientsLock);
|
||||
|
||||
AuthenticationResult authState = databaseInterface->checkUserPassword(session, name, password, reasonStr, secondsLeft);
|
||||
if ((authState == NotLoggedIn) || (authState == UserIsBanned || authState == UsernameInvalid))
|
||||
if (authState == NotLoggedIn || authState == UserIsBanned || authState == UsernameInvalid || authState == UserIsInactive)
|
||||
return authState;
|
||||
|
||||
ServerInfo_User data = databaseInterface->getUserData(name, true);
|
||||
|
|
@ -140,7 +140,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
|||
|
||||
QString tempName = name;
|
||||
int i = 0;
|
||||
while (users.contains(tempName) || databaseInterface->userExists(tempName) || databaseInterface->userSessionExists(tempName))
|
||||
while (users.contains(tempName) || databaseInterface->activeUserExists(tempName) || databaseInterface->userSessionExists(tempName))
|
||||
tempName = name + "_" + QString::number(++i);
|
||||
name = tempName;
|
||||
data.set_name(name.toStdString());
|
||||
|
|
@ -177,8 +177,6 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
|||
|
||||
RegistrationResult Server::registerUserAccount(const QString &ipAddress, const Command_Register &cmd, QString &banReason, int &banSecondsRemaining)
|
||||
{
|
||||
// TODO
|
||||
|
||||
if (!registrationEnabled)
|
||||
return RegistrationDisabled;
|
||||
|
||||
|
|
@ -193,6 +191,9 @@ RegistrationResult Server::registerUserAccount(const QString &ipAddress, const C
|
|||
if (!databaseInterface->usernameIsValid(userName))
|
||||
return InvalidUsername;
|
||||
|
||||
if(databaseInterface->userExists(userName))
|
||||
return UserAlreadyExists;
|
||||
|
||||
if (databaseInterface->checkUserIsBanned(ipAddress, userName, banReason, banSecondsRemaining))
|
||||
return ClientIsBanned;
|
||||
|
||||
|
|
@ -202,8 +203,12 @@ RegistrationResult Server::registerUserAccount(const QString &ipAddress, const C
|
|||
QString realName = QString::fromStdString(cmd.real_name());
|
||||
ServerInfo_User_Gender gender = cmd.gender();
|
||||
QString country = QString::fromStdString(cmd.country());
|
||||
QString passwordSha512 = QString::fromStdString(cmd.password());
|
||||
bool regSucceeded = databaseInterface->registerUser(userName, realName, gender, passwordSha512, emailAddress, country, false);
|
||||
QString password = QString::fromStdString(cmd.password());
|
||||
|
||||
if(password.length() < 6)
|
||||
return PasswordTooShort;
|
||||
|
||||
bool regSucceeded = databaseInterface->registerUser(userName, realName, gender, password, emailAddress, country, false);
|
||||
|
||||
return regSucceeded ? Accepted : Failed;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ class GameEventContainer;
|
|||
class CommandContainer;
|
||||
class Command_JoinGame;
|
||||
|
||||
enum AuthenticationResult { NotLoggedIn = 0, PasswordRight = 1, UnknownUser = 2, WouldOverwriteOldSession = 3, UserIsBanned = 4, UsernameInvalid = 5, RegistrationRequired = 6 };
|
||||
enum RegistrationResult { Accepted = 0, UserAlreadyExists = 1, EmailRequired = 2, UnauthenticatedServer = 3, TooManyRequests = 4, InvalidUsername = 5, ClientIsBanned = 6, RegistrationDisabled = 7, Failed = 8};
|
||||
enum AuthenticationResult { NotLoggedIn, PasswordRight, UnknownUser, WouldOverwriteOldSession, UserIsBanned, UsernameInvalid, RegistrationRequired, UserIsInactive };
|
||||
enum RegistrationResult { Accepted, UserAlreadyExists, EmailRequired, TooManyRequests, InvalidUsername, ClientIsBanned, RegistrationDisabled, Failed, PasswordTooShort };
|
||||
|
||||
class Server : public QObject
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ public:
|
|||
|
||||
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft) = 0;
|
||||
virtual bool checkUserIsBanned(const QString &ipAddress, const QString &userName, QString &banReason, int &banSecondsRemaining) { return false; }
|
||||
virtual bool activeUserExists(const QString & /* user */) { return false; }
|
||||
virtual bool userExists(const QString & /* user */) { return false; }
|
||||
virtual QMap<QString, ServerInfo_User> getBuddyList(const QString & /* name */) { return QMap<QString, ServerInfo_User>(); }
|
||||
virtual QMap<QString, ServerInfo_User> getIgnoreList(const QString & /* name */) { return QMap<QString, ServerInfo_User>(); }
|
||||
|
|
@ -37,7 +38,7 @@ public:
|
|||
virtual bool userSessionExists(const QString & /* userName */) { return false; }
|
||||
|
||||
virtual bool getRequireRegistration() { return false; }
|
||||
virtual bool registerUser(const QString &userName, const QString &realName, ServerInfo_User_Gender const &gender, const QString &passwordSha512, const QString &emailAddress, const QString &country, bool active = false) { return false; }
|
||||
virtual bool registerUser(const QString & /* userName */, const QString & /* realName */, ServerInfo_User_Gender const & /* gender */, const QString & /* password */, const QString & /* emailAddress */, const QString & /* country */, bool /* active = false */) { return false; }
|
||||
|
||||
enum LogMessage_TargetType { MessageTargetRoom, MessageTargetGame, MessageTargetChat, MessageTargetIslRoom };
|
||||
virtual void logMessage(const int /* senderId */, const QString & /* senderName */, const QString & /* senderIp */, const QString & /* logMessage */, LogMessage_TargetType /* targetType */, const int /* targetId */, const QString & /* targetName */) { };
|
||||
|
|
|
|||
|
|
@ -392,6 +392,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd
|
|||
case WouldOverwriteOldSession: return Response::RespWouldOverwriteOldSession;
|
||||
case UsernameInvalid: return Response::RespUsernameInvalid;
|
||||
case RegistrationRequired: return Response::RespRegistrationRequired;
|
||||
case UserIsInactive: return Response::RespAccountNotActivated;
|
||||
default: authState = res;
|
||||
}
|
||||
|
||||
|
|
@ -442,10 +443,10 @@ Response::ResponseCode Server_ProtocolHandler::cmdRegisterAccount(const Command_
|
|||
return Response::RespUserAlreadyExists;
|
||||
case EmailRequired:
|
||||
return Response::RespEmailRequiredToRegister;
|
||||
case UnauthenticatedServer:
|
||||
return Response::RespServerDoesNotUseAuth;
|
||||
case TooManyRequests:
|
||||
return Response::RespTooManyRequests;
|
||||
case PasswordTooShort:
|
||||
return Response::RespPasswordTooShort;
|
||||
case InvalidUsername:
|
||||
return Response::RespUsernameInvalid;
|
||||
case Failed:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue