diff --git a/data/gui/online/change_password.stkgui b/data/gui/online/change_password.stkgui
new file mode 100644
index 000000000..0f9f16a04
--- /dev/null
+++ b/data/gui/online/change_password.stkgui
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/data/gui/online/login_dialog.stkgui b/data/gui/online/login_dialog.stkgui
index bd60928fb..b60b8599e 100644
--- a/data/gui/online/login_dialog.stkgui
+++ b/data/gui/online/login_dialog.stkgui
@@ -3,7 +3,7 @@
+ I18N="In the login dialog" text="Sign in"/>
diff --git a/data/gui/online/profile_settings.stkgui b/data/gui/online/profile_settings.stkgui
index 1e9fc1501..35abe5ee3 100644
--- a/data/gui/online/profile_settings.stkgui
+++ b/data/gui/online/profile_settings.stkgui
@@ -17,7 +17,11 @@
diff --git a/sources.cmake b/sources.cmake
index 7159b37c0..c1c45fafc 100644
--- a/sources.cmake
+++ b/sources.cmake
@@ -206,6 +206,7 @@ src/states_screens/credits.cpp
src/states_screens/cutscene_gui.cpp
src/states_screens/dialogs/add_device_dialog.cpp
src/states_screens/dialogs/addons_loading.cpp
+src/states_screens/dialogs/change_password_dialog.cpp
src/states_screens/dialogs/confirm_resolution_dialog.cpp
src/states_screens/dialogs/custom_video_settings.cpp
src/states_screens/dialogs/enter_player_name_dialog.cpp
@@ -515,6 +516,7 @@ src/states_screens/credits.hpp
src/states_screens/cutscene_gui.hpp
src/states_screens/dialogs/add_device_dialog.hpp
src/states_screens/dialogs/addons_loading.hpp
+src/states_screens/dialogs/change_password_dialog.hpp
src/states_screens/dialogs/confirm_resolution_dialog.hpp
src/states_screens/dialogs/custom_video_settings.hpp
src/states_screens/dialogs/enter_player_name_dialog.hpp
diff --git a/src/online/current_user.cpp b/src/online/current_user.cpp
index a2f54b602..51ac435a2 100644
--- a/src/online/current_user.cpp
+++ b/src/online/current_user.cpp
@@ -28,6 +28,7 @@
#include "utils/translation.hpp"
#include "addons/addon.hpp"
#include "guiengine/dialog_queue.hpp"
+#include "states_screens/dialogs/change_password_dialog.hpp"
#include "states_screens/dialogs/login_dialog.hpp"
#include "states_screens/dialogs/user_info_dialog.hpp"
#include "states_screens/dialogs/notification_dialog.hpp"
@@ -493,6 +494,37 @@ namespace Online{
GUIEngine::DialogQueue::get()->pushDialog( new UserInfoDialog(id, info_text,!m_success, true), true);
}
+
+ // ============================================================================
+ void CurrentUser::requestPasswordChange(const irr::core::stringw ¤t_password,
+ const irr::core::stringw &new_password,
+ const irr::core::stringw &new_password_ver) const
+ {
+ assert(m_state == US_SIGNED_IN);
+ ChangePasswordRequest * request = new ChangePasswordRequest();
+ request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
+ request->setParameter("action", std::string("change_password"));
+ request->setParameter("userid", getID());
+ request->setParameter("current", current_password);
+ request->setParameter("new1", new_password);
+ request->setParameter("new2", new_password_ver);
+ HTTPManager::get()->addRequest(request);
+ }
+
+ void CurrentUser::ChangePasswordRequest::callback()
+ {
+ if(GUIEngine::ModalDialog::isADialogActive())
+ {
+ ChangePasswordDialog * dialog = dynamic_cast(GUIEngine::ModalDialog::getCurrent());
+ if(dialog != NULL)
+ {
+ if(m_success)
+ dialog->success();
+ else
+ dialog->error(m_info);
+ }
+ }
+ }
// ============================================================================
void CurrentUser::requestPoll()
{
diff --git a/src/online/current_user.hpp b/src/online/current_user.hpp
index 2c0b838e9..6915c947c 100644
--- a/src/online/current_user.hpp
+++ b/src/online/current_user.hpp
@@ -120,6 +120,13 @@ namespace Online{
PollRequest() : XMLRequest(true) {}
};
+ class ChangePasswordRequest : public XMLRequest
+ {
+ virtual void callback ();
+ public:
+ ChangePasswordRequest() : XMLRequest(true) {}
+ };
+
private:
std::string m_token;
@@ -166,6 +173,9 @@ namespace Online{
void requestDeclineFriend(const uint32_t friend_id) const;
void requestRemoveFriend(const uint32_t friend_id) const;
void requestCancelFriend(const uint32_t friend_id) const;
+ void requestPasswordChange( const irr::core::stringw ¤t_password,
+ const irr::core::stringw &new_password,
+ const irr::core::stringw &new_password_ver) const;
const XMLRequest * requestUserSearch(const irr::core::stringw & search_string) const;
diff --git a/src/online/messages.cpp b/src/online/messages.cpp
index 13ac6d636..b2706a868 100644
--- a/src/online/messages.cpp
+++ b/src/online/messages.cpp
@@ -35,14 +35,9 @@ namespace Online
return irr::core::stringw(_("Signing out")) + loadingDots();
}
// ------------------------------------------------------------------------
- irr::core::stringw signingUp()
+ irr::core::stringw validatingInfo()
{
- return irr::core::stringw(_("Validating registration info")) + loadingDots();
- }
- // ------------------------------------------------------------------------
- irr::core::stringw recovery()
- {
- return irr::core::stringw(_("Validating recovery info")) + loadingDots();
+ return irr::core::stringw(_("Validating info")) + loadingDots();
}
// ------------------------------------------------------------------------
irr::core::stringw searching()
diff --git a/src/online/messages.hpp b/src/online/messages.hpp
index 856723dae..ed1b96aec 100644
--- a/src/online/messages.hpp
+++ b/src/online/messages.hpp
@@ -29,8 +29,7 @@ namespace Online
irr::core::stringw loadingDots (bool spaces = true, float interval = 0.5f, int max_dots = 3);
irr::core::stringw signingIn ();
irr::core::stringw signingOut ();
- irr::core::stringw signingUp ();
- irr::core::stringw recovery ();
+ irr::core::stringw validatingInfo ();
irr::core::stringw searching ();
irr::core::stringw joiningServer ();
irr::core::stringw creatingServer ();
diff --git a/src/states_screens/dialogs/change_password_dialog.cpp b/src/states_screens/dialogs/change_password_dialog.cpp
new file mode 100644
index 000000000..dd42330c4
--- /dev/null
+++ b/src/states_screens/dialogs/change_password_dialog.cpp
@@ -0,0 +1,184 @@
+// SuperTuxKart - a fun racing game with go-kart
+// Copyright (C) 2013 Glenn De Jonghe
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 3
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#include "states_screens/dialogs/change_password_dialog.hpp"
+
+#include
+
+#include "audio/sfx_manager.hpp"
+#include "config/player.hpp"
+#include "guiengine/engine.hpp"
+#include "states_screens/state_manager.hpp"
+#include "utils/translation.hpp"
+#include "utils/string_utils.hpp"
+#include "online/messages.hpp"
+
+
+using namespace GUIEngine;
+using namespace irr;
+using namespace irr::gui;
+using namespace Online;
+
+// -----------------------------------------------------------------------------
+
+ChangePasswordDialog::ChangePasswordDialog() :
+ ModalDialog(0.8f,0.7f)
+{
+ m_self_destroy = false;
+ m_success = false;
+
+ loadFromFile("online/change_password.stkgui");
+
+ m_current_password_widget = getWidget("current_password");
+ assert(m_current_password_widget != NULL);
+ m_current_password_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
+ m_current_password_widget->setPasswordBox(true,L'*');
+
+ m_new_password1_widget = getWidget("new_password1");
+ assert(m_new_password1_widget != NULL);
+ m_new_password1_widget->setPasswordBox(true,L'*');
+
+ m_new_password2_widget = getWidget("new_password2");
+ assert(m_new_password2_widget != NULL);
+ m_new_password2_widget->setPasswordBox(true,L'*');
+
+ m_info_widget = getWidget("info");
+ assert(m_info_widget != NULL);
+
+ m_options_widget = getWidget("options");
+ assert(m_options_widget != NULL);
+ m_submit_widget = getWidget("submit");
+ assert(m_submit_widget != NULL);
+ m_cancel_widget = getWidget("cancel");
+ assert(m_cancel_widget != NULL);
+}
+
+// -----------------------------------------------------------------------------
+
+ChangePasswordDialog::~ChangePasswordDialog()
+{
+}
+
+// -----------------------------------------------------------------------------
+void ChangePasswordDialog::submit()
+{
+ const stringw current_password = m_current_password_widget->getText().trim();
+ const stringw new_password1 = m_new_password1_widget->getText().trim();
+ const stringw new_password2 = m_new_password2_widget->getText().trim();
+ if (current_password.size() < 8 || current_password.size() > 30)
+ {
+ sfx_manager->quickSound("anvil");
+ m_info_widget->setErrorColor();
+ m_info_widget->setText(_("Current password invalid."), false);
+ }
+ else if (new_password1.size() < 8 || new_password1.size() > 30)
+ {
+ sfx_manager->quickSound("anvil");
+ m_info_widget->setErrorColor();
+ m_info_widget->setText(_("Password has to be between 8 and 30 characters long!"), false);
+ }
+ else if (new_password1 != new_password2)
+ {
+ sfx_manager->quickSound("anvil");
+ m_info_widget->setErrorColor();
+ m_info_widget->setText(_("Passwords don't match!"), false);
+ }
+ else
+ {
+ m_options_widget->setDeactivated();
+ m_info_widget->setDefaultColor();
+ Online::CurrentUser::get()->requestPasswordChange(current_password, new_password1, new_password2);
+ }
+}
+
+// -----------------------------------------------------------------------------
+GUIEngine::EventPropagation ChangePasswordDialog::processEvent(const std::string& eventSource)
+{
+
+ if (eventSource == m_options_widget->m_properties[PROP_ID])
+ {
+ const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
+ if (selection == m_cancel_widget->m_properties[PROP_ID])
+ {
+ m_self_destroy = true;
+ return GUIEngine::EVENT_BLOCK;
+ }
+ else if(selection == m_submit_widget->m_properties[PROP_ID])
+ {
+ submit();
+ return GUIEngine::EVENT_BLOCK;
+ }
+ }
+ return GUIEngine::EVENT_LET;
+}
+
+// -----------------------------------------------------------------------------
+
+void ChangePasswordDialog::onEnterPressedInternal()
+{
+ const int playerID = PLAYER_ID_GAME_MASTER;
+ if (GUIEngine::isFocusedForPlayer(m_options_widget, playerID))
+ return;
+ if (m_submit_widget->isActivated())
+ submit();
+}
+
+// -----------------------------------------------------------------------------
+
+bool ChangePasswordDialog::onEscapePressed()
+{
+ if (m_cancel_widget->isActivated())
+ m_self_destroy = true;
+ return false;
+}
+
+// -----------------------------------------------------------------------------
+void ChangePasswordDialog::success()
+{
+ m_info_widget->setDefaultColor();
+ m_info_widget->setText(_("Password successfully changed."), false);
+ m_options_widget->setActivated();
+ m_current_password_widget->setText("");
+ m_new_password1_widget->setText("");
+ m_new_password2_widget->setText("");
+}
+
+// -----------------------------------------------------------------------------
+void ChangePasswordDialog::error(const irr::core::stringw & error)
+{
+ sfx_manager->quickSound("anvil");
+ m_info_widget->setErrorColor();
+ m_info_widget->setText(error, false);
+ m_options_widget->setActivated();
+ m_current_password_widget->setText("");
+ m_new_password1_widget->setText("");
+ m_new_password2_widget->setText("");
+}
+
+// -----------------------------------------------------------------------------
+
+void ChangePasswordDialog::onUpdate(float dt)
+{
+ if(!m_options_widget->isActivated())
+ m_info_widget->setText(Online::Messages::validatingInfo(), false);
+
+ // It's unsafe to delete from inside the event handler so we do it here
+ if (m_self_destroy)
+ {
+ ModalDialog::dismiss();
+ }
+}
diff --git a/src/states_screens/dialogs/change_password_dialog.hpp b/src/states_screens/dialogs/change_password_dialog.hpp
new file mode 100644
index 000000000..cc699c51d
--- /dev/null
+++ b/src/states_screens/dialogs/change_password_dialog.hpp
@@ -0,0 +1,70 @@
+// SuperTuxKart - a fun racing game with go-kart
+// Copyright (C) 2013 Glenn De Jonghe
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 3
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifndef HEADER_CHANGE_PASSWORD_DIALOG_HPP
+#define HEADER_CHANGE_PASSWORD_DIALOG_HPP
+
+#include
+
+#include "online/current_user.hpp"
+
+#include "guiengine/modaldialog.hpp"
+#include "guiengine/widgets.hpp"
+
+/**
+ * \brief Dialog that allows a user to sign in
+ * \ingroup states_screens
+ */
+class ChangePasswordDialog : public GUIEngine::ModalDialog
+{
+
+public:
+
+ /**
+ * Creates a modal dialog with given percentage of screen width and height
+ */
+ ChangePasswordDialog();
+ ~ChangePasswordDialog();
+
+ virtual void onEnterPressedInternal();
+
+ GUIEngine::EventPropagation processEvent(const std::string& eventSource);
+
+ virtual bool onEscapePressed();
+ virtual void onUpdate(float dt);
+ void success();
+ void error(const irr::core::stringw & error_message);
+
+private:
+
+ bool m_self_destroy;
+ bool m_success;
+
+ GUIEngine::TextBoxWidget * m_current_password_widget;
+ GUIEngine::TextBoxWidget * m_new_password1_widget;
+ GUIEngine::TextBoxWidget * m_new_password2_widget;
+ GUIEngine::LabelWidget * m_info_widget;
+
+ GUIEngine::RibbonWidget * m_options_widget;
+ GUIEngine::IconButtonWidget * m_submit_widget;
+ GUIEngine::IconButtonWidget * m_cancel_widget;
+
+ void submit();
+};
+
+#endif
diff --git a/src/states_screens/dialogs/login_dialog.hpp b/src/states_screens/dialogs/login_dialog.hpp
index bfd80963e..171708443 100644
--- a/src/states_screens/dialogs/login_dialog.hpp
+++ b/src/states_screens/dialogs/login_dialog.hpp
@@ -40,8 +40,6 @@ public:
virtual void onClose() const = 0;
};
-public:
-
enum Message
{
Normal = 0, // If the user presses the sign in button himself
diff --git a/src/states_screens/dialogs/recovery_dialog.cpp b/src/states_screens/dialogs/recovery_dialog.cpp
index 7ed3cfec7..8d4eb9f1e 100644
--- a/src/states_screens/dialogs/recovery_dialog.cpp
+++ b/src/states_screens/dialogs/recovery_dialog.cpp
@@ -177,7 +177,7 @@ void RecoveryDialog::onUpdate(float dt)
}
else
{
- m_info_widget->setText(Messages::recovery(), false);
+ m_info_widget->setText(Messages::validatingInfo(), false);
}
}
// It's unsafe to delete from inside the event handler so we do it here
diff --git a/src/states_screens/dialogs/registration_dialog.cpp b/src/states_screens/dialogs/registration_dialog.cpp
index 25014efed..8fea4ad53 100644
--- a/src/states_screens/dialogs/registration_dialog.cpp
+++ b/src/states_screens/dialogs/registration_dialog.cpp
@@ -237,7 +237,7 @@ bool RegistrationDialog::processTermsEvent(const std::string& eventSource)
assert(m_accept_terms_widget->getState());
m_options_widget->setDeactivated();
m_info_widget->setDefaultColor();
- m_info_widget->setText(Messages::signingUp(), false);
+ m_info_widget->setText(Messages::validatingInfo(), false);
m_sign_up_request = CurrentUser::get()->requestSignUp(m_username, m_password, m_password_confirm, m_email, true);
return true;
}
@@ -333,7 +333,7 @@ void RegistrationDialog::onUpdate(float dt)
else
{
m_info_widget->setDefaultColor();
- m_info_widget->setText(Messages::signingUp(), false);
+ m_info_widget->setText(Messages::validatingInfo(), false);
}
}
}
diff --git a/src/states_screens/online_profile_settings.cpp b/src/states_screens/online_profile_settings.cpp
index f18270d9f..06abe7bde 100644
--- a/src/states_screens/online_profile_settings.cpp
+++ b/src/states_screens/online_profile_settings.cpp
@@ -22,6 +22,7 @@
#include "guiengine/screen.hpp"
#include "guiengine/widget.hpp"
#include "states_screens/state_manager.hpp"
+#include "states_screens/dialogs/change_password_dialog.hpp"
#include "utils/translation.hpp"
#include
@@ -47,7 +48,8 @@ OnlineProfileSettings::OnlineProfileSettings() : OnlineProfileBase("online/profi
void OnlineProfileSettings::loadedFromFile()
{
OnlineProfileBase::loadedFromFile();
-
+ m_change_password_button = this->getWidget("change_password_button");
+ assert(m_change_password_button != NULL);
} // loadedFromFile
// -----------------------------------------------------------------------------
@@ -63,5 +65,9 @@ void OnlineProfileSettings::init()
void OnlineProfileSettings::eventCallback(Widget* widget, const std::string& name, const int playerID)
{
OnlineProfileBase::eventCallback( widget, name, playerID);
+ if (name == m_change_password_button->m_properties[GUIEngine::PROP_ID])
+ {
+ new ChangePasswordDialog();
+ }
} // eventCallback
diff --git a/src/states_screens/online_profile_settings.hpp b/src/states_screens/online_profile_settings.hpp
index 5dc5284ca..36fbd2669 100644
--- a/src/states_screens/online_profile_settings.hpp
+++ b/src/states_screens/online_profile_settings.hpp
@@ -37,6 +37,7 @@ class OnlineProfileSettings : public OnlineProfileBase, public GUIEngine::Screen
{
protected:
OnlineProfileSettings();
+ GUIEngine::ButtonWidget * m_change_password_button;
public:
friend class GUIEngine::ScreenSingleton;