2011-05-22 22:09:12 +02:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Part of Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
Copyright (C) 2013 Ciaran Gultnieks <ciaran@ciarang.com>
|
2011-05-22 22:09:12 +02:00
|
|
|
|
2011-05-31 10:59:51 +02:00
|
|
|
Permission to use, copy, modify, and distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
2011-05-22 22:09:12 +02:00
|
|
|
|
2011-05-31 10:59:51 +02:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2011-05-22 22:09:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "guiPasswordChange.h"
|
2018-11-28 20:01:49 +01:00
|
|
|
#include "client/client.h"
|
2019-10-12 18:44:23 +02:00
|
|
|
#include "guiButton.h"
|
2011-10-12 12:53:38 +02:00
|
|
|
#include <IGUICheckBox.h>
|
|
|
|
#include <IGUIEditBox.h>
|
|
|
|
#include <IGUIButton.h>
|
|
|
|
#include <IGUIStaticText.h>
|
|
|
|
#include <IGUIFont.h>
|
2018-08-07 21:58:26 +02:00
|
|
|
|
2021-09-26 18:04:09 +02:00
|
|
|
#ifdef HAVE_TOUCHSCREENGUI
|
|
|
|
#include "client/renderingengine.h"
|
|
|
|
#endif
|
|
|
|
|
2018-06-24 21:50:57 +02:00
|
|
|
#include "porting.h"
|
2011-07-20 16:51:19 +02:00
|
|
|
#include "gettext.h"
|
|
|
|
|
2011-05-22 22:09:12 +02:00
|
|
|
const int ID_oldPassword = 256;
|
|
|
|
const int ID_newPassword1 = 257;
|
|
|
|
const int ID_newPassword2 = 258;
|
|
|
|
const int ID_change = 259;
|
|
|
|
const int ID_message = 260;
|
2017-05-09 11:04:45 +02:00
|
|
|
const int ID_cancel = 261;
|
2011-05-22 22:09:12 +02:00
|
|
|
|
|
|
|
GUIPasswordChange::GUIPasswordChange(gui::IGUIEnvironment* env,
|
|
|
|
gui::IGUIElement* parent, s32 id,
|
|
|
|
IMenuManager *menumgr,
|
2020-04-11 22:39:30 +02:00
|
|
|
Client* client,
|
|
|
|
ISimpleTextureSource *tsrc
|
2011-05-22 22:09:12 +02:00
|
|
|
):
|
|
|
|
GUIModalMenu(env, parent, id, menumgr),
|
2020-04-11 22:39:30 +02:00
|
|
|
m_client(client),
|
|
|
|
m_tsrc(tsrc)
|
2011-05-22 22:09:12 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIPasswordChange::regenerateGui(v2u32 screensize)
|
|
|
|
{
|
2017-05-20 12:29:44 +02:00
|
|
|
/*
|
|
|
|
save current input
|
|
|
|
*/
|
|
|
|
acceptInput();
|
|
|
|
|
2011-05-22 22:09:12 +02:00
|
|
|
/*
|
|
|
|
Remove stuff
|
|
|
|
*/
|
2022-05-22 00:11:59 +02:00
|
|
|
removeAllChildren();
|
2015-04-17 06:10:30 +02:00
|
|
|
|
2011-05-22 22:09:12 +02:00
|
|
|
/*
|
|
|
|
Calculate new sizes and positions
|
|
|
|
*/
|
2021-09-26 18:04:09 +02:00
|
|
|
#ifdef HAVE_TOUCHSCREENGUI
|
|
|
|
const float s = m_gui_scale * RenderingEngine::getDisplayDensity() / 2;
|
2020-07-21 14:16:25 +02:00
|
|
|
#else
|
2018-11-26 22:55:24 +01:00
|
|
|
const float s = m_gui_scale;
|
2020-07-21 14:16:25 +02:00
|
|
|
#endif
|
2018-11-26 22:55:24 +01:00
|
|
|
DesiredRect = core::rect<s32>(
|
|
|
|
screensize.X / 2 - 580 * s / 2,
|
|
|
|
screensize.Y / 2 - 300 * s / 2,
|
|
|
|
screensize.X / 2 + 580 * s / 2,
|
|
|
|
screensize.Y / 2 + 300 * s / 2
|
2011-05-22 22:09:12 +02:00
|
|
|
);
|
|
|
|
recalculateAbsolutePosition(false);
|
|
|
|
|
2018-11-26 22:55:24 +01:00
|
|
|
v2s32 size = DesiredRect.getSize();
|
|
|
|
v2s32 topleft_client(40 * s, 0);
|
2011-05-22 22:09:12 +02:00
|
|
|
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text;
|
|
|
|
|
2011-05-22 22:09:12 +02:00
|
|
|
/*
|
|
|
|
Add stuff
|
|
|
|
*/
|
2018-11-26 22:55:24 +01:00
|
|
|
s32 ypos = 50 * s;
|
2011-05-22 22:09:12 +02:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 150 * s, 20 * s);
|
|
|
|
rect += topleft_client + v2s32(25 * s, ypos + 6 * s);
|
2015-02-01 23:59:23 +01:00
|
|
|
text = wgettext("Old Password");
|
2013-04-07 19:15:17 +02:00
|
|
|
Environment->addStaticText(text, rect, false, true, this, -1);
|
|
|
|
delete[] text;
|
2011-05-22 22:09:12 +02:00
|
|
|
}
|
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 230 * s, 30 * s);
|
|
|
|
rect += topleft_client + v2s32(160 * s, ypos);
|
2017-05-09 11:04:45 +02:00
|
|
|
gui::IGUIEditBox *e = Environment->addEditBox(
|
2017-05-20 12:29:44 +02:00
|
|
|
m_oldpass.c_str(), rect, true, this, ID_oldPassword);
|
2011-05-22 22:09:12 +02:00
|
|
|
Environment->setFocus(e);
|
|
|
|
e->setPasswordBox(true);
|
|
|
|
}
|
2018-11-26 22:55:24 +01:00
|
|
|
ypos += 50 * s;
|
2011-05-22 22:09:12 +02:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 150 * s, 20 * s);
|
|
|
|
rect += topleft_client + v2s32(25 * s, ypos + 6 * s);
|
2015-02-01 23:59:23 +01:00
|
|
|
text = wgettext("New Password");
|
2013-04-07 19:15:17 +02:00
|
|
|
Environment->addStaticText(text, rect, false, true, this, -1);
|
|
|
|
delete[] text;
|
2011-05-22 22:09:12 +02:00
|
|
|
}
|
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 230 * s, 30 * s);
|
|
|
|
rect += topleft_client + v2s32(160 * s, ypos);
|
2017-05-09 11:04:45 +02:00
|
|
|
gui::IGUIEditBox *e = Environment->addEditBox(
|
2017-05-20 12:29:44 +02:00
|
|
|
m_newpass.c_str(), rect, true, this, ID_newPassword1);
|
2011-05-22 22:09:12 +02:00
|
|
|
e->setPasswordBox(true);
|
|
|
|
}
|
2018-11-26 22:55:24 +01:00
|
|
|
ypos += 50 * s;
|
2011-05-22 22:09:12 +02:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 150 * s, 20 * s);
|
|
|
|
rect += topleft_client + v2s32(25 * s, ypos + 6 * s);
|
2015-02-01 23:59:23 +01:00
|
|
|
text = wgettext("Confirm Password");
|
2013-04-07 19:15:17 +02:00
|
|
|
Environment->addStaticText(text, rect, false, true, this, -1);
|
|
|
|
delete[] text;
|
2011-05-22 22:09:12 +02:00
|
|
|
}
|
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 230 * s, 30 * s);
|
|
|
|
rect += topleft_client + v2s32(160 * s, ypos);
|
2017-05-09 11:04:45 +02:00
|
|
|
gui::IGUIEditBox *e = Environment->addEditBox(
|
2017-05-20 12:29:44 +02:00
|
|
|
m_newpass_confirm.c_str(), rect, true, this, ID_newPassword2);
|
2011-05-22 22:09:12 +02:00
|
|
|
e->setPasswordBox(true);
|
|
|
|
}
|
|
|
|
|
2018-11-26 22:55:24 +01:00
|
|
|
ypos += 50 * s;
|
2011-05-22 22:09:12 +02:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 100 * s, 30 * s);
|
|
|
|
rect = rect + v2s32(size.X / 4 + 56 * s, ypos);
|
2015-02-01 23:59:23 +01:00
|
|
|
text = wgettext("Change");
|
2020-04-11 22:39:30 +02:00
|
|
|
GUIButton::addButton(Environment, rect, m_tsrc, this, ID_change, text);
|
2013-04-07 19:15:17 +02:00
|
|
|
delete[] text;
|
2011-05-22 22:09:12 +02:00
|
|
|
}
|
2017-05-09 11:04:45 +02:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 100 * s, 30 * s);
|
|
|
|
rect = rect + v2s32(size.X / 4 + 185 * s, ypos);
|
2017-05-09 11:04:45 +02:00
|
|
|
text = wgettext("Cancel");
|
2020-04-11 22:39:30 +02:00
|
|
|
GUIButton::addButton(Environment, rect, m_tsrc, this, ID_cancel, text);
|
2017-05-09 11:04:45 +02:00
|
|
|
delete[] text;
|
|
|
|
}
|
2011-05-22 22:09:12 +02:00
|
|
|
|
2018-11-26 22:55:24 +01:00
|
|
|
ypos += 50 * s;
|
2011-05-22 22:09:12 +02:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 300 * s, 20 * s);
|
|
|
|
rect += topleft_client + v2s32(35 * s, ypos);
|
2015-02-01 23:59:23 +01:00
|
|
|
text = wgettext("Passwords do not match!");
|
2015-04-17 06:10:30 +02:00
|
|
|
IGUIElement *e =
|
2017-05-09 11:04:45 +02:00
|
|
|
Environment->addStaticText(
|
|
|
|
text, rect, false, true, this, ID_message);
|
2011-05-22 22:09:12 +02:00
|
|
|
e->setVisible(false);
|
2013-04-07 19:15:17 +02:00
|
|
|
delete[] text;
|
2011-05-22 22:09:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIPasswordChange::drawMenu()
|
|
|
|
{
|
2017-05-09 11:04:45 +02:00
|
|
|
gui::IGUISkin *skin = Environment->getSkin();
|
2011-05-22 22:09:12 +02:00
|
|
|
if (!skin)
|
|
|
|
return;
|
2017-05-09 11:04:45 +02:00
|
|
|
video::IVideoDriver *driver = Environment->getVideoDriver();
|
2015-04-17 06:10:30 +02:00
|
|
|
|
2017-05-09 11:04:45 +02:00
|
|
|
video::SColor bgcolor(140, 0, 0, 0);
|
2011-05-22 22:09:12 +02:00
|
|
|
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
|
|
|
|
|
|
|
|
gui::IGUIElement::draw();
|
2018-06-24 21:50:57 +02:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
getAndroidUIInput();
|
|
|
|
#endif
|
2011-05-22 22:09:12 +02:00
|
|
|
}
|
|
|
|
|
2017-05-20 12:29:44 +02:00
|
|
|
void GUIPasswordChange::acceptInput()
|
2011-05-22 22:09:12 +02:00
|
|
|
{
|
2017-05-09 11:04:45 +02:00
|
|
|
gui::IGUIElement *e;
|
|
|
|
e = getElementFromId(ID_oldPassword);
|
|
|
|
if (e != NULL)
|
2017-05-20 12:29:44 +02:00
|
|
|
m_oldpass = e->getText();
|
2017-05-09 11:04:45 +02:00
|
|
|
e = getElementFromId(ID_newPassword1);
|
|
|
|
if (e != NULL)
|
2017-05-20 12:29:44 +02:00
|
|
|
m_newpass = e->getText();
|
2017-05-09 11:04:45 +02:00
|
|
|
e = getElementFromId(ID_newPassword2);
|
2017-05-20 12:29:44 +02:00
|
|
|
if (e != NULL)
|
|
|
|
m_newpass_confirm = e->getText();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GUIPasswordChange::processInput()
|
|
|
|
{
|
|
|
|
if (m_newpass != m_newpass_confirm) {
|
|
|
|
gui::IGUIElement *e = getElementFromId(ID_message);
|
2017-05-09 11:04:45 +02:00
|
|
|
if (e != NULL)
|
|
|
|
e->setVisible(true);
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-20 12:29:44 +02:00
|
|
|
m_client->sendChangePassword(wide_to_utf8(m_oldpass), wide_to_utf8(m_newpass));
|
2017-05-09 11:04:45 +02:00
|
|
|
return true;
|
2011-05-22 22:09:12 +02:00
|
|
|
}
|
|
|
|
|
2017-05-09 11:04:45 +02:00
|
|
|
bool GUIPasswordChange::OnEvent(const SEvent &event)
|
2011-05-22 22:09:12 +02:00
|
|
|
{
|
2017-05-09 11:04:45 +02:00
|
|
|
if (event.EventType == EET_KEY_INPUT_EVENT) {
|
2018-06-24 21:50:57 +02:00
|
|
|
// clang-format off
|
|
|
|
if ((event.KeyInput.Key == KEY_ESCAPE ||
|
|
|
|
event.KeyInput.Key == KEY_CANCEL) &&
|
|
|
|
event.KeyInput.PressedDown) {
|
2011-05-22 22:09:12 +02:00
|
|
|
quitMenu();
|
|
|
|
return true;
|
|
|
|
}
|
2018-06-24 21:50:57 +02:00
|
|
|
// clang-format on
|
2017-05-09 11:04:45 +02:00
|
|
|
if (event.KeyInput.Key == KEY_RETURN && event.KeyInput.PressedDown) {
|
2017-05-20 12:29:44 +02:00
|
|
|
acceptInput();
|
|
|
|
if (processInput())
|
2011-05-22 22:09:12 +02:00
|
|
|
quitMenu();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-05-09 11:04:45 +02:00
|
|
|
if (event.EventType == EET_GUI_EVENT) {
|
|
|
|
if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST &&
|
|
|
|
isVisible()) {
|
|
|
|
if (!canTakeFocus(event.GUIEvent.Element)) {
|
2020-07-14 22:37:28 +02:00
|
|
|
infostream << "GUIPasswordChange: Not allowing focus change."
|
2017-05-09 11:04:45 +02:00
|
|
|
<< std::endl;
|
2011-05-22 22:09:12 +02:00
|
|
|
// Returning true disables focus change
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-05-09 11:04:45 +02:00
|
|
|
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
|
|
|
|
switch (event.GUIEvent.Caller->getID()) {
|
2011-05-22 22:09:12 +02:00
|
|
|
case ID_change:
|
2017-05-20 12:29:44 +02:00
|
|
|
acceptInput();
|
|
|
|
if (processInput())
|
2011-05-22 22:09:12 +02:00
|
|
|
quitMenu();
|
|
|
|
return true;
|
2017-05-09 11:04:45 +02:00
|
|
|
case ID_cancel:
|
|
|
|
quitMenu();
|
|
|
|
return true;
|
2011-05-22 22:09:12 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-09 11:04:45 +02:00
|
|
|
if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
|
|
|
|
switch (event.GUIEvent.Caller->getID()) {
|
2011-05-22 22:09:12 +02:00
|
|
|
case ID_oldPassword:
|
|
|
|
case ID_newPassword1:
|
|
|
|
case ID_newPassword2:
|
2017-05-20 12:29:44 +02:00
|
|
|
acceptInput();
|
|
|
|
if (processInput())
|
2011-05-22 22:09:12 +02:00
|
|
|
quitMenu();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Parent ? Parent->OnEvent(event) : false;
|
|
|
|
}
|
2018-06-24 21:50:57 +02:00
|
|
|
|
|
|
|
std::string GUIPasswordChange::getNameByID(s32 id)
|
|
|
|
{
|
|
|
|
switch (id) {
|
|
|
|
case ID_oldPassword:
|
|
|
|
return "old_password";
|
|
|
|
case ID_newPassword1:
|
|
|
|
return "new_password_1";
|
|
|
|
case ID_newPassword2:
|
|
|
|
return "new_password_2";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
bool GUIPasswordChange::getAndroidUIInput()
|
|
|
|
{
|
|
|
|
if (!hasAndroidUIInput())
|
|
|
|
return false;
|
|
|
|
|
2020-07-21 14:16:25 +02:00
|
|
|
// still waiting
|
|
|
|
if (porting::getInputDialogState() == -1)
|
|
|
|
return true;
|
|
|
|
|
2018-06-24 21:50:57 +02:00
|
|
|
gui::IGUIElement *e = nullptr;
|
|
|
|
if (m_jni_field_name == "old_password")
|
|
|
|
e = getElementFromId(ID_oldPassword);
|
|
|
|
else if (m_jni_field_name == "new_password_1")
|
|
|
|
e = getElementFromId(ID_newPassword1);
|
|
|
|
else if (m_jni_field_name == "new_password_2")
|
|
|
|
e = getElementFromId(ID_newPassword2);
|
|
|
|
m_jni_field_name.clear();
|
2020-07-21 14:16:25 +02:00
|
|
|
|
|
|
|
if (!e || e->getType() != irr::gui::EGUIET_EDIT_BOX)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::string text = porting::getInputDialogValue();
|
|
|
|
e->setText(utf8_to_wide(text).c_str());
|
2018-06-24 21:50:57 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|