diff options
Diffstat (limited to 'src/account-server/accounthandler.cpp')
-rw-r--r-- | src/account-server/accounthandler.cpp | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 4a4c73cf..e8161fcd 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -591,23 +591,28 @@ void AccountHandler::handleRegisterMessage(AccountClient &client, { reply.writeInt8(REGISTER_EXISTS_USERNAME); } - else if (storage->doesEmailAddressExist(sha256(email))) - { - reply.writeInt8(REGISTER_EXISTS_EMAIL); - } - else if (!checkCaptcha(client, captcha)) - { - reply.writeInt8(REGISTER_CAPTCHA_WRONG); - } else { // We hash email server-side for additional privacy. We ask for it again // when we need it and verify it through comparing it with the hash. - client.setAccount(createAccount(username, sha256(password), sha256(email))); - client.status = CLIENT_CONNECTED; + const std::string emailHash = email.empty() ? std::string() : sha256(email); - reply.writeInt8(ERRMSG_OK); - addServerInfo(reply); + if (storage->doesEmailAddressExist(emailHash)) + { + reply.writeInt8(REGISTER_EXISTS_EMAIL); + } + else if (!checkCaptcha(client, captcha)) + { + reply.writeInt8(REGISTER_CAPTCHA_WRONG); + } + else + { + client.setAccount(createAccount(username, sha256(password), emailHash)); + client.status = CLIENT_CONNECTED; + + reply.writeInt8(ERRMSG_OK); + addServerInfo(reply); + } } client.send(reply); @@ -692,27 +697,29 @@ void AccountHandler::handleEmailChangeMessage(AccountClient &client, } const std::string email = msg.readString(); - const std::string emailHash = sha256(email); - if (!stringFilter->isEmailValid(email)) - { - reply.writeInt8(ERRMSG_INVALID_ARGUMENT); - } - else if (stringFilter->findDoubleQuotes(email)) + if (!stringFilter->isEmailValid(email) + || stringFilter->findDoubleQuotes(email)) { reply.writeInt8(ERRMSG_INVALID_ARGUMENT); } - else if (storage->doesEmailAddressExist(emailHash)) - { - reply.writeInt8(ERRMSG_EMAIL_ALREADY_EXISTS); - } else { - acc->setEmail(emailHash); - // Keep the database up to date otherwise we will go out of sync - storage->flush(*acc); - reply.writeInt8(ERRMSG_OK); + const std::string emailHash = email.empty() ? std::string() : sha256(email); + + if (storage->doesEmailAddressExist(emailHash)) + { + reply.writeInt8(ERRMSG_EMAIL_ALREADY_EXISTS); + } + else + { + acc->setEmail(emailHash); + // Keep the database up to date otherwise we will go out of sync + storage->flush(*acc); + reply.writeInt8(ERRMSG_OK); + } } + client.send(reply); } @@ -996,7 +1003,7 @@ void AccountHandler::handleCharacterDeleteMessage(AccountClient &client, } const std::string &characterName = chars[slot]->getName(); - LOG_INFO("Character deleted:" << characterName); + LOG_INFO("Character deleted: " << characterName); // Log transaction Transaction trans; @@ -1110,7 +1117,7 @@ void AccountHandler::handleStellarLogin(const std::string &token, const std::str } else { - // On-demand account creation for public keys + // On-demand account creation, using the public key as username. acc = createAccount(pubKey, std::string(), std::string()); LOG_INFO("Stellar login: Created account for public key " << pubKey << ", ID " << acc->getID()); |