mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Added token generation, user activation command and response.
This commit is contained in:
parent
42796b0d0e
commit
ff1aed717e
19 changed files with 223 additions and 19 deletions
|
|
@ -114,6 +114,7 @@ SET(PROTO_FILES
|
|||
isl_message.proto
|
||||
moderator_commands.proto
|
||||
move_card_to_zone.proto
|
||||
response_activate.proto
|
||||
response_deck_download.proto
|
||||
response_deck_list.proto
|
||||
response_deck_upload.proto
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ message Response {
|
|||
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
|
||||
RespActivationAccepted = 31; // Server accepted a reg user activation token
|
||||
RespActivationFailed = 32; // Server didn't accept a reg user activation token
|
||||
RespRegistrationAcceptedNeedsActivation = 33; // Server accepted cient registration, but it will need token activation
|
||||
}
|
||||
enum ResponseType {
|
||||
JOIN_ROOM = 1000;
|
||||
|
|
@ -44,6 +47,7 @@ message Response {
|
|||
DECK_DOWNLOAD = 1007;
|
||||
DECK_UPLOAD = 1008;
|
||||
REGISTER = 1009;
|
||||
ACTIVATE = 1010;
|
||||
REPLAY_LIST = 1100;
|
||||
REPLAY_DOWNLOAD = 1101;
|
||||
}
|
||||
|
|
|
|||
7
common/pb/response_activate.proto
Normal file
7
common/pb/response_activate.proto
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import "response.proto";
|
||||
|
||||
message Response_Activate {
|
||||
extend Response {
|
||||
optional Response_Activate ext = 1010;
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ message SessionCommand {
|
|||
LIST_ROOMS = 1014;
|
||||
JOIN_ROOM = 1015;
|
||||
REGISTER = 1016;
|
||||
ACTIVATE = 1017;
|
||||
REPLAY_LIST = 1100;
|
||||
REPLAY_DOWNLOAD = 1101;
|
||||
REPLAY_MODIFY_MATCH = 1102;
|
||||
|
|
@ -115,3 +116,14 @@ message Command_Register {
|
|||
optional string country = 5;
|
||||
optional string real_name = 6;
|
||||
}
|
||||
|
||||
// User wants to activate an account
|
||||
message Command_Activate {
|
||||
extend SessionCommand {
|
||||
optional Command_Activate ext = 1017;
|
||||
}
|
||||
// User name client wants to activate
|
||||
required string user_name = 1;
|
||||
// Activation token
|
||||
required string token = 2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,9 +208,22 @@ RegistrationResult Server::registerUserAccount(const QString &ipAddress, const C
|
|||
if(password.length() < 6)
|
||||
return PasswordTooShort;
|
||||
|
||||
bool regSucceeded = databaseInterface->registerUser(userName, realName, gender, password, emailAddress, country, false);
|
||||
bool regSucceeded = databaseInterface->registerUser(userName, realName, gender, password, emailAddress, country, !requireEmailForRegistration);
|
||||
|
||||
return regSucceeded ? Accepted : Failed;
|
||||
if(regSucceeded)
|
||||
return requireEmailForRegistration ? AcceptedNeedsActivation : Accepted;
|
||||
else
|
||||
return Failed;
|
||||
}
|
||||
|
||||
bool Server::activateUserAccount(const Command_Activate &cmd)
|
||||
{
|
||||
QString userName = QString::fromStdString(cmd.user_name());
|
||||
QString token = QString::fromStdString(cmd.token());
|
||||
|
||||
Server_DatabaseInterface *databaseInterface = getDatabaseInterface();
|
||||
|
||||
return databaseInterface->activateUser(userName, token);
|
||||
}
|
||||
|
||||
bool Server::tooManyRegistrationAttempts(const QString &ipAddress)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class CommandContainer;
|
|||
class Command_JoinGame;
|
||||
|
||||
enum AuthenticationResult { NotLoggedIn, PasswordRight, UnknownUser, WouldOverwriteOldSession, UserIsBanned, UsernameInvalid, RegistrationRequired, UserIsInactive };
|
||||
enum RegistrationResult { Accepted, UserAlreadyExists, EmailRequired, TooManyRequests, InvalidUsername, ClientIsBanned, RegistrationDisabled, Failed, PasswordTooShort };
|
||||
enum RegistrationResult { Accepted, UserAlreadyExists, EmailRequired, TooManyRequests, InvalidUsername, ClientIsBanned, RegistrationDisabled, Failed, PasswordTooShort, AcceptedNeedsActivation };
|
||||
|
||||
class Server : public QObject
|
||||
{
|
||||
|
|
@ -57,6 +57,7 @@ public:
|
|||
* @return RegistrationResult member indicating whether it succeeded or failed.
|
||||
*/
|
||||
RegistrationResult registerUserAccount(const QString &ipAddress, const Command_Register &cmd, QString &banReason, int &banSecondsRemaining);
|
||||
bool activateUserAccount(const Command_Activate &cmd);
|
||||
|
||||
bool tooManyRegistrationAttempts(const QString &ipAddress);
|
||||
const QMap<int, Server_Room *> &getRooms() { return rooms; }
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ public:
|
|||
|
||||
virtual bool getRequireRegistration() { 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; }
|
||||
virtual bool activateUser(const QString & /* userName */, const QString & /* token */) { 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 */) { };
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@ Response::ResponseCode Server_ProtocolHandler::processSessionCommandContainer(co
|
|||
case SessionCommand::PING: resp = cmdPing(sc.GetExtension(Command_Ping::ext), rc); break;
|
||||
case SessionCommand::LOGIN: resp = cmdLogin(sc.GetExtension(Command_Login::ext), rc); break;
|
||||
case SessionCommand::REGISTER: resp = cmdRegisterAccount(sc.GetExtension(Command_Register::ext), rc); break;
|
||||
case SessionCommand::ACTIVATE: resp = cmdActivateAccount(sc.GetExtension(Command_Activate::ext), rc); break;
|
||||
case SessionCommand::MESSAGE: resp = cmdMessage(sc.GetExtension(Command_Message::ext), rc); break;
|
||||
case SessionCommand::GET_GAMES_OF_USER: resp = cmdGetGamesOfUser(sc.GetExtension(Command_GetGamesOfUser::ext), rc); break;
|
||||
case SessionCommand::GET_USER_INFO: resp = cmdGetUserInfo(sc.GetExtension(Command_GetUserInfo::ext), rc); break;
|
||||
|
|
@ -437,8 +438,11 @@ Response::ResponseCode Server_ProtocolHandler::cmdRegisterAccount(const Command_
|
|||
switch (result) {
|
||||
case RegistrationDisabled:
|
||||
return Response::RespRegistrationDisabled;
|
||||
case Accepted:
|
||||
case Accepted:
|
||||
return Response::RespRegistrationAccepted;
|
||||
case AcceptedNeedsActivation:
|
||||
// TODO SEND EMAIL WITH TOKEN TO THE USER
|
||||
return Response::RespRegistrationAcceptedNeedsActivation;
|
||||
case UserAlreadyExists:
|
||||
return Response::RespUserAlreadyExists;
|
||||
case EmailRequired:
|
||||
|
|
@ -463,6 +467,18 @@ Response::ResponseCode Server_ProtocolHandler::cmdRegisterAccount(const Command_
|
|||
return Response::RespInvalidCommand;
|
||||
}
|
||||
|
||||
Response::ResponseCode Server_ProtocolHandler::cmdActivateAccount(const Command_Activate &cmd, ResponseContainer &rc)
|
||||
{
|
||||
if(server->activateUserAccount(cmd))
|
||||
{
|
||||
qDebug() << "Accepted activation for user" << QString::fromStdString(cmd.user_name());
|
||||
return Response::RespActivationAccepted;
|
||||
} else {
|
||||
qDebug() << "Failed activation for user" << QString::fromStdString(cmd.user_name());
|
||||
return Response::RespActivationFailed;
|
||||
}
|
||||
}
|
||||
|
||||
Response::ResponseCode Server_ProtocolHandler::cmdMessage(const Command_Message &cmd, ResponseContainer &rc)
|
||||
{
|
||||
if (authState == NotLoggedIn)
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ private:
|
|||
Response::ResponseCode cmdPing(const Command_Ping &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdLogin(const Command_Login &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdRegisterAccount(const Command_Register &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdActivateAccount(const Command_Activate &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdMessage(const Command_Message &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdGetGamesOfUser(const Command_GetGamesOfUser &cmd, ResponseContainer &rc);
|
||||
Response::ResponseCode cmdGetUserInfo(const Command_GetUserInfo &cmd, ResponseContainer &rc);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue