From 8f15575eef91cd063b19903d5e3f7e5c33b5835e Mon Sep 17 00:00:00 2001 From: Kuba Date: Wed, 2 Jun 2021 04:21:38 +0200 Subject: [PATCH] Added e-mail change dialog (#4536) --- .../screens/online/profile_settings.stkgui | 8 ++- .../online/online_profile_settings.cpp | 57 +++++++++++++++++++ .../online/online_profile_settings.hpp | 3 +- 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/data/gui/screens/online/profile_settings.stkgui b/data/gui/screens/online/profile_settings.stkgui index 77a850646..79bc8d811 100644 --- a/data/gui/screens/online/profile_settings.stkgui +++ b/data/gui/screens/online/profile_settings.stkgui @@ -17,11 +17,17 @@
-
+
+ +
+
diff --git a/src/states_screens/online/online_profile_settings.cpp b/src/states_screens/online/online_profile_settings.cpp index ca929cdae..7fb302fa5 100644 --- a/src/states_screens/online/online_profile_settings.cpp +++ b/src/states_screens/online/online_profile_settings.cpp @@ -23,7 +23,12 @@ #include "guiengine/widget.hpp" #include "states_screens/state_manager.hpp" #include "states_screens/dialogs/change_password_dialog.hpp" +#include "states_screens/dialogs/general_text_field_dialog.hpp" +#include "states_screens/dialogs/message_dialog.hpp" #include "utils/translation.hpp" +#include "online/xml_request.hpp" +#include "config/player_manager.hpp" +#include "audio/sfx_manager.hpp" #include @@ -47,6 +52,7 @@ void OnlineProfileSettings::loadedFromFile() { OnlineProfileBase::loadedFromFile(); m_change_password_button = this->getWidget("change_password_button"); + m_change_email_button = getWidget("change_email_button"); assert(m_change_password_button != NULL); } // loadedFromFile @@ -68,5 +74,56 @@ void OnlineProfileSettings::eventCallback(Widget* widget, const std::string& nam { new ChangePasswordDialog(); } + if (name == m_change_email_button->m_properties[GUIEngine::PROP_ID]) + { + new GeneralTextFieldDialog(_("Enter new E-mail below"),[](const irr::core::stringw& str){},[&](GUIEngine::LabelWidget* lw, GUIEngine::TextBoxWidget* tb)->bool + { + const irr::core::stringw new_email = tb->getText().trim(); + if (new_email.size() < 5 || new_email.size() > 254) + { + lw->setText(_("New Email has to be between 5 and 254 characters long!"), false); + lw->setErrorColor(); + SFXManager::get()->quickSound("anvil"); + return false; + } + else if ( new_email.find(L"@")== -1 || new_email.find(L".")== -1 || + (new_email.findLast(L'.') - new_email.findLast(L'@') <= 2 ) || + new_email.findLast(L'@')==0 ) + { + lw->setText(_("New Email is invalid!"), false); + lw->setErrorColor(); + SFXManager::get()->quickSound("anvil"); + return false; + } + else + { + lw->setDefaultColor(); + changeEmail(new_email); + return true; + } + + }); + } } // eventCallback +// ----------------------------------------------------------------------------- + +void OnlineProfileSettings::changeEmail(const irr::core::stringw &new_email) +{ + class ChangeEmailRequest : public XMLRequest + { + virtual void callback() + { + if(isSuccess()) + new MessageDialog(_("E-mail changed!")); + else + new MessageDialog(_("Failed to change E-mail: %s", getInfo())); + } // callback + public: + ChangeEmailRequest() : XMLRequest() {} + }; // ChangeEmailRequest + auto request = std::make_shared(); + PlayerManager::setUserDetails(request, "change-email"); + request->addParameter("new-email", new_email); + request->queue(); +} // changeEmail diff --git a/src/states_screens/online/online_profile_settings.hpp b/src/states_screens/online/online_profile_settings.hpp index b4e1fa235..e03f867d0 100644 --- a/src/states_screens/online/online_profile_settings.hpp +++ b/src/states_screens/online/online_profile_settings.hpp @@ -38,7 +38,8 @@ class OnlineProfileSettings : public OnlineProfileBase, public GUIEngine::Screen protected: OnlineProfileSettings(); GUIEngine::ButtonWidget * m_change_password_button; - + GUIEngine::ButtonWidget* m_change_email_button; + void changeEmail(const irr::core::stringw &new_email); public: friend class GUIEngine::ScreenSingleton;