Password changing done! (and some other small fixes)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13679 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
f710250867
commit
99e7b565bc
47
data/gui/online/change_password.stkgui
Normal file
47
data/gui/online/change_password.stkgui
Normal file
@ -0,0 +1,47 @@
|
||||
<stkgui>
|
||||
|
||||
<div x="2%" y="5%" width="96%" height="90%" layout="vertical-row" >
|
||||
|
||||
<header id="title" width="96%" height="fit" text_align="center" word_wrap="true"
|
||||
I18N="In the change password dialog" text="Password Change"/>
|
||||
|
||||
<spacer height="40" width="50">
|
||||
|
||||
<div width="80%" align="center" layout="vertical-row" height="fit" >
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label proportion="1" height="100%" text_align="left" I18N="In the change password dialog" text="Current Password"/>
|
||||
<textbox proportion="2" height="fit" id="current_password" I18N="In the change password dialog"/>
|
||||
</div>
|
||||
|
||||
<spacer height="20" width="20">
|
||||
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label proportion="1" height="100%" text_align="left" I18N="In the change password dialog" text="New Password"/>
|
||||
<textbox proportion="2" height="fit" id="new_password1" I18N="In the change password dialog"/>
|
||||
</div>
|
||||
|
||||
<spacer height="20" width="20">
|
||||
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label proportion="1" height="100%" text_align="left" I18N="In the change password dialog" text="Confirm"/>
|
||||
<textbox proportion="2" height="fit" id="new_password2" I18N="In the change password dialog"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<spacer height="20" width="50">
|
||||
|
||||
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true" text=""/>
|
||||
|
||||
<spacer height="20" width="50">
|
||||
|
||||
<buttonbar id="options" width="90%" height="16%" align="center">
|
||||
<icon-button id="submit" width="64" height="64" icon="gui/green_check.png"
|
||||
I18N="In the change password dialog" text="Submit" label_location="bottom"/>
|
||||
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
|
||||
I18N="In the change password dialog" text="Close" label_location="bottom"/>
|
||||
</buttonbar>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</stkgui>
|
@ -3,7 +3,7 @@
|
||||
<div x="2%" y="5%" width="96%" height="90%" layout="vertical-row" >
|
||||
|
||||
<header id="title" width="96%" height="fit" text_align="center" word_wrap="true"
|
||||
I18N="In the login dialog' dialog" text="Sign in"/>
|
||||
I18N="In the login dialog" text="Sign in"/>
|
||||
|
||||
<spacer height="25" width="50">
|
||||
|
||||
|
@ -17,7 +17,11 @@
|
||||
|
||||
<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" >
|
||||
<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>
|
||||
</div>
|
||||
</box>
|
||||
</div>
|
||||
|
@ -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
|
||||
|
@ -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<ChangePasswordDialog*>(GUIEngine::ModalDialog::getCurrent());
|
||||
if(dialog != NULL)
|
||||
{
|
||||
if(m_success)
|
||||
dialog->success();
|
||||
else
|
||||
dialog->error(m_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
// ============================================================================
|
||||
void CurrentUser::requestPoll()
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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 ();
|
||||
|
184
src/states_screens/dialogs/change_password_dialog.cpp
Normal file
184
src/states_screens/dialogs/change_password_dialog.cpp
Normal file
@ -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 <IGUIEnvironment.h>
|
||||
|
||||
#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<TextBoxWidget>("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<TextBoxWidget>("new_password1");
|
||||
assert(m_new_password1_widget != NULL);
|
||||
m_new_password1_widget->setPasswordBox(true,L'*');
|
||||
|
||||
m_new_password2_widget = getWidget<TextBoxWidget>("new_password2");
|
||||
assert(m_new_password2_widget != NULL);
|
||||
m_new_password2_widget->setPasswordBox(true,L'*');
|
||||
|
||||
m_info_widget = getWidget<LabelWidget>("info");
|
||||
assert(m_info_widget != NULL);
|
||||
|
||||
m_options_widget = getWidget<RibbonWidget>("options");
|
||||
assert(m_options_widget != NULL);
|
||||
m_submit_widget = getWidget<IconButtonWidget>("submit");
|
||||
assert(m_submit_widget != NULL);
|
||||
m_cancel_widget = getWidget<IconButtonWidget>("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();
|
||||
}
|
||||
}
|
70
src/states_screens/dialogs/change_password_dialog.hpp
Normal file
70
src/states_screens/dialogs/change_password_dialog.hpp
Normal file
@ -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 <irrString.h>
|
||||
|
||||
#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
|
@ -40,8 +40,6 @@ public:
|
||||
virtual void onClose() const = 0;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
enum Message
|
||||
{
|
||||
Normal = 0, // If the user presses the sign in button himself
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 <IGUIButton.h>
|
||||
@ -47,7 +48,8 @@ OnlineProfileSettings::OnlineProfileSettings() : OnlineProfileBase("online/profi
|
||||
void OnlineProfileSettings::loadedFromFile()
|
||||
{
|
||||
OnlineProfileBase::loadedFromFile();
|
||||
|
||||
m_change_password_button = this->getWidget<ButtonWidget>("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
|
||||
|
||||
|
@ -37,6 +37,7 @@ class OnlineProfileSettings : public OnlineProfileBase, public GUIEngine::Screen
|
||||
{
|
||||
protected:
|
||||
OnlineProfileSettings();
|
||||
GUIEngine::ButtonWidget * m_change_password_button;
|
||||
|
||||
public:
|
||||
friend class GUIEngine::ScreenSingleton<OnlineProfileSettings>;
|
||||
|
Loading…
x
Reference in New Issue
Block a user