Added e-mail change dialog (#4536)

This commit is contained in:
Kuba 2021-06-02 04:21:38 +02:00 committed by GitHub
parent 5fed067b9c
commit 8f15575eef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 2 deletions

View File

@ -17,11 +17,17 @@
<box proportion="1" width="100%" layout="vertical-row">
<div x="1%" y="2%" width="98%" height="96%" layout="vertical-row" >
<div width="fit" height="fit" layout="horizontal-row" >
<div width="19%" height="fit" layout="horizontal-row" >
<label proportion="1" height="fit" text_align="left" I18N="In the online account settings screen" text="Password:"/>
<spacer width="20" height="1"/>
<button id="change_password_button" height="100%" width="fit" text="Change" />
</div>
<spacer height="5%" width="20"/>
<div width="19%" height="fit" layout="horizontal-row" >
<label proportion="1" height="fit" text_align="left" I18N="In the online account settings screen" text="E-mail:"/>
<spacer width="20" height="1"/>
<button id="change_email_button" height="100%" width="fit" text="Change" />
</div>
</div>
</box>
</div>

View File

@ -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 <IGUIButton.h>
@ -47,6 +52,7 @@ void OnlineProfileSettings::loadedFromFile()
{
OnlineProfileBase::loadedFromFile();
m_change_password_button = this->getWidget<ButtonWidget>("change_password_button");
m_change_email_button = getWidget<ButtonWidget>("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<ChangeEmailRequest>();
PlayerManager::setUserDetails(request, "change-email");
request->addParameter("new-email", new_email);
request->queue();
} // changeEmail

View File

@ -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<OnlineProfileSettings>;