feat(Scripts/Commands): account set email (#19481)
* added worldserver command to set email address * reverted sql, added Tail args * removed pointer * Added helper text via updatescript * fix build * fix build * fixed db update * Update data/sql/updates/db_world/2024_07_26_01.sql Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> * Update data/sql/updates/db_world/2024_07_26_01.sql Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com> * fixed hander * refactor with named params * refactor with named params --------- Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
-- DB update 22024_07_26_00 -> 2024_07_26_01
|
||||||
|
DELETE FROM `command` WHERE `name`='account set email';
|
||||||
|
|
||||||
|
INSERT INTO `command` (`name`, `security`, `help`) VALUES
|
||||||
|
('account set email', 4, 'Syntax: .account set email $account $email $email_confirmation\nAdd or change an email to the account.');
|
||||||
|
|
||||||
|
DELETE FROM `acore_string` WHERE `entry` IN (875);
|
||||||
|
INSERT INTO `acore_string` (`entry`, `content_default`,`locale_zhCN`) VALUES
|
||||||
|
(875, 'Your email can\'t be longer than 255 characters, email not changed!', '您的电子邮件无法超过255个字符,电子邮件没有改变!');
|
||||||
@@ -83,6 +83,7 @@ void LoginDatabaseConnection::DoPrepareStatements()
|
|||||||
PrepareStatement(LOGIN_UPD_EXPANSION, "UPDATE account SET expansion = ? WHERE id = ?", CONNECTION_ASYNC);
|
PrepareStatement(LOGIN_UPD_EXPANSION, "UPDATE account SET expansion = ? WHERE id = ?", CONNECTION_ASYNC);
|
||||||
PrepareStatement(LOGIN_UPD_ACCOUNT_LOCK, "UPDATE account SET locked = ? WHERE id = ?", CONNECTION_ASYNC);
|
PrepareStatement(LOGIN_UPD_ACCOUNT_LOCK, "UPDATE account SET locked = ? WHERE id = ?", CONNECTION_ASYNC);
|
||||||
PrepareStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY, "UPDATE account SET lock_country = ? WHERE id = ?", CONNECTION_ASYNC);
|
PrepareStatement(LOGIN_UPD_ACCOUNT_LOCK_COUNTRY, "UPDATE account SET lock_country = ? WHERE id = ?", CONNECTION_ASYNC);
|
||||||
|
PrepareStatement(LOGIN_UPD_EMAIL, "UPDATE account SET email = ? WHERE id = ?", CONNECTION_ASYNC);
|
||||||
PrepareStatement(LOGIN_UPD_USERNAME, "UPDATE account SET username = ? WHERE id = ?", CONNECTION_ASYNC);
|
PrepareStatement(LOGIN_UPD_USERNAME, "UPDATE account SET username = ? WHERE id = ?", CONNECTION_ASYNC);
|
||||||
PrepareStatement(LOGIN_UPD_MUTE_TIME, "UPDATE account SET mutetime = ? , mutereason = ? , muteby = ? WHERE id = ?", CONNECTION_ASYNC);
|
PrepareStatement(LOGIN_UPD_MUTE_TIME, "UPDATE account SET mutetime = ? , mutereason = ? , muteby = ? WHERE id = ?", CONNECTION_ASYNC);
|
||||||
PrepareStatement(LOGIN_UPD_MUTE_TIME_LOGIN, "UPDATE account SET mutetime = ? WHERE id = ?", CONNECTION_ASYNC);
|
PrepareStatement(LOGIN_UPD_MUTE_TIME_LOGIN, "UPDATE account SET mutetime = ? WHERE id = ?", CONNECTION_ASYNC);
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ enum LoginDatabaseStatements : uint32
|
|||||||
LOGIN_UPD_EXPANSION,
|
LOGIN_UPD_EXPANSION,
|
||||||
LOGIN_UPD_ACCOUNT_LOCK,
|
LOGIN_UPD_ACCOUNT_LOCK,
|
||||||
LOGIN_UPD_ACCOUNT_LOCK_COUNTRY,
|
LOGIN_UPD_ACCOUNT_LOCK_COUNTRY,
|
||||||
|
LOGIN_UPD_EMAIL,
|
||||||
LOGIN_UPD_USERNAME,
|
LOGIN_UPD_USERNAME,
|
||||||
LOGIN_UPD_MUTE_TIME,
|
LOGIN_UPD_MUTE_TIME,
|
||||||
LOGIN_UPD_MUTE_TIME_LOGIN,
|
LOGIN_UPD_MUTE_TIME_LOGIN,
|
||||||
|
|||||||
@@ -58,6 +58,33 @@ namespace AccountMgr
|
|||||||
return AOR_OK; // everything's fine
|
return AOR_OK; // everything's fine
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AccountOpResult ChangeEmail(uint32 accountId, std::string newEmail)
|
||||||
|
{
|
||||||
|
std::string username;
|
||||||
|
|
||||||
|
if (!GetName(accountId, username))
|
||||||
|
{
|
||||||
|
sScriptMgr->OnFailedEmailChange(accountId);
|
||||||
|
return AOR_NAME_NOT_EXIST; // account doesn't exist
|
||||||
|
}
|
||||||
|
|
||||||
|
if (utf8length(newEmail) > MAX_EMAIL_STR)
|
||||||
|
{
|
||||||
|
sScriptMgr->OnFailedEmailChange(accountId);
|
||||||
|
return AOR_EMAIL_TOO_LONG; // email's too long
|
||||||
|
}
|
||||||
|
|
||||||
|
Utf8ToUpperOnlyLatin(newEmail);
|
||||||
|
|
||||||
|
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_EMAIL);
|
||||||
|
stmt->SetData(0, newEmail);
|
||||||
|
stmt->SetData(1, accountId);
|
||||||
|
LoginDatabase.Execute(stmt);
|
||||||
|
|
||||||
|
sScriptMgr->OnEmailChange(accountId);
|
||||||
|
return AOR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
AccountOpResult DeleteAccount(uint32 accountId)
|
AccountOpResult DeleteAccount(uint32 accountId)
|
||||||
{
|
{
|
||||||
// Check if accounts exists
|
// Check if accounts exists
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ enum AccountOpResult
|
|||||||
AOR_OK,
|
AOR_OK,
|
||||||
AOR_NAME_TOO_LONG,
|
AOR_NAME_TOO_LONG,
|
||||||
AOR_PASS_TOO_LONG,
|
AOR_PASS_TOO_LONG,
|
||||||
|
AOR_EMAIL_TOO_LONG,
|
||||||
AOR_NAME_ALREADY_EXIST,
|
AOR_NAME_ALREADY_EXIST,
|
||||||
AOR_NAME_NOT_EXIST,
|
AOR_NAME_NOT_EXIST,
|
||||||
AOR_DB_INTERNAL_ERROR
|
AOR_DB_INTERNAL_ERROR
|
||||||
@@ -33,6 +34,7 @@ enum AccountOpResult
|
|||||||
|
|
||||||
#define MAX_ACCOUNT_STR 20
|
#define MAX_ACCOUNT_STR 20
|
||||||
#define MAX_PASS_STR 16
|
#define MAX_PASS_STR 16
|
||||||
|
#define MAX_EMAIL_STR 255
|
||||||
|
|
||||||
namespace AccountMgr
|
namespace AccountMgr
|
||||||
{
|
{
|
||||||
@@ -40,6 +42,7 @@ namespace AccountMgr
|
|||||||
AccountOpResult DeleteAccount(uint32 accountId);
|
AccountOpResult DeleteAccount(uint32 accountId);
|
||||||
AccountOpResult ChangeUsername(uint32 accountId, std::string newUsername, std::string newPassword);
|
AccountOpResult ChangeUsername(uint32 accountId, std::string newUsername, std::string newPassword);
|
||||||
AccountOpResult ChangePassword(uint32 accountId, std::string newPassword);
|
AccountOpResult ChangePassword(uint32 accountId, std::string newPassword);
|
||||||
|
AccountOpResult ChangeEmail(uint32 accountId, std::string email);
|
||||||
bool CheckPassword(uint32 accountId, std::string password);
|
bool CheckPassword(uint32 accountId, std::string password);
|
||||||
|
|
||||||
uint32 GetId(std::string const& username);
|
uint32 GetId(std::string const& username);
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ public:
|
|||||||
{ "addon", HandleAccountSetAddonCommand, SEC_GAMEMASTER, Console::Yes },
|
{ "addon", HandleAccountSetAddonCommand, SEC_GAMEMASTER, Console::Yes },
|
||||||
{ "gmlevel", HandleAccountSetGmLevelCommand, SEC_ADMINISTRATOR, Console::Yes },
|
{ "gmlevel", HandleAccountSetGmLevelCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "password", HandleAccountSetPasswordCommand, SEC_ADMINISTRATOR, Console::Yes },
|
{ "password", HandleAccountSetPasswordCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "2fa", HandleAccountSet2FACommand, SEC_PLAYER, Console::Yes }
|
{ "2fa", HandleAccountSet2FACommand, SEC_PLAYER, Console::Yes },
|
||||||
|
{ "email", HandleAccountSetEmailCommand, SEC_ADMINISTRATOR, Console::Yes }
|
||||||
};
|
};
|
||||||
|
|
||||||
static ChatCommandTable accountLockCommandTable
|
static ChatCommandTable accountLockCommandTable
|
||||||
@@ -900,6 +901,53 @@ public:
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set email for account
|
||||||
|
static bool HandleAccountSetEmailCommand(ChatHandler* handler, AccountIdentifier account, std::string email, std::string emailConfirmation)
|
||||||
|
|
||||||
|
{
|
||||||
|
if (!account || !email.data() || !emailConfirmation.data())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::string accountName = account.GetName();
|
||||||
|
if (!Utf8ToUpperOnlyLatin(accountName))
|
||||||
|
{
|
||||||
|
handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 targetAccountId = account.GetID();
|
||||||
|
if (!targetAccountId)
|
||||||
|
{
|
||||||
|
handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (email != emailConfirmation)
|
||||||
|
{
|
||||||
|
handler->SendErrorMessage(LANG_NEW_EMAILS_NOT_MATCH);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountOpResult result = AccountMgr::ChangeEmail(targetAccountId, email.data());
|
||||||
|
|
||||||
|
switch (result)
|
||||||
|
{
|
||||||
|
case AOR_OK:
|
||||||
|
handler->SendSysMessage(LANG_COMMAND_EMAIL);
|
||||||
|
break;
|
||||||
|
case AOR_NAME_NOT_EXIST:
|
||||||
|
handler->SendErrorMessage(LANG_ACCOUNT_NOT_EXIST, accountName);
|
||||||
|
return false;
|
||||||
|
case AOR_EMAIL_TOO_LONG:
|
||||||
|
handler->SendErrorMessage(LANG_EMAIL_TOO_LONG);
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
handler->SendErrorMessage(LANG_COMMAND_NOTCHANGEEMAIL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void AddSC_account_commandscript()
|
void AddSC_account_commandscript()
|
||||||
|
|||||||
Reference in New Issue
Block a user