Moved user search and password change from CurrentUser into the
corresponding dialogs.
This commit is contained in:
parent
800a012283
commit
0a107897ca
@ -20,8 +20,6 @@
|
||||
#include "online/current_user.hpp"
|
||||
|
||||
#include "achievements/achievements_manager.hpp"
|
||||
#include "addons/addon.hpp"
|
||||
#include "addons/addons_manager.hpp"
|
||||
#include "config/player_manager.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "guiengine/dialog_queue.hpp"
|
||||
@ -262,68 +260,6 @@ namespace Online
|
||||
//FIXME needs changes for actual valid joining
|
||||
} // ServerJoinRequest::callback
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** A request to the server, to fetch matching results for the supplied
|
||||
* search term.
|
||||
* \param search_string the string to search for.
|
||||
*/
|
||||
XMLRequest*
|
||||
CurrentUser::requestUserSearch(const core::stringw &search_string) const
|
||||
{
|
||||
assert(m_state == US_SIGNED_IN);
|
||||
XMLRequest * request = new XMLRequest();
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action", "user-search");
|
||||
request->addParameter("token", getToken());
|
||||
request->addParameter("userid", getID());
|
||||
request->addParameter("search-string", search_string);
|
||||
request->queue();
|
||||
return request;
|
||||
} // requestUserSearch
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** A request to the server, to change the password of the signed in user.
|
||||
* \param current_password The active password of the currently signed in
|
||||
* user.
|
||||
* \param new_password The password the user wants to change to.
|
||||
* \param new_password_ver Confirmation of that password. Has to be the
|
||||
* exact same.
|
||||
*/
|
||||
void CurrentUser::requestPasswordChange(const core::stringw ¤t_password,
|
||||
const core::stringw &new_password,
|
||||
const core::stringw &new_password_ver) const
|
||||
{
|
||||
assert(m_state == US_SIGNED_IN);
|
||||
ChangePasswordRequest * request = new ChangePasswordRequest();
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action", "change_password");
|
||||
request->addParameter("userid", getID());
|
||||
request->addParameter("current", current_password);
|
||||
request->addParameter("new1", new_password);
|
||||
request->addParameter("new2", new_password_ver);
|
||||
request->queue();
|
||||
} // requestPasswordChange
|
||||
// ------------------------------------------------------------------------
|
||||
/** Callback for the change password request. If the matching dialog is
|
||||
* still open, show a confirmation message.
|
||||
*/
|
||||
void CurrentUser::ChangePasswordRequest::callback()
|
||||
{
|
||||
if(GUIEngine::ModalDialog::isADialogActive())
|
||||
{
|
||||
ChangePasswordDialog * dialog =
|
||||
dynamic_cast<ChangePasswordDialog*>(GUIEngine::ModalDialog
|
||||
::getCurrent());
|
||||
if(dialog != NULL)
|
||||
{
|
||||
if(isSuccess())
|
||||
dialog->success();
|
||||
else
|
||||
dialog->error(getInfo());
|
||||
}
|
||||
}
|
||||
} // ChangePasswordRequest::callback
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sends a request to the server to see if any new information is
|
||||
* available. (online friends, notifications, etc.).
|
||||
|
@ -87,15 +87,6 @@ namespace Online
|
||||
PollRequest() : XMLRequest(true) {}
|
||||
}; // PollRequest
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
class ChangePasswordRequest : public XMLRequest
|
||||
{
|
||||
virtual void callback ();
|
||||
public:
|
||||
ChangePasswordRequest() : XMLRequest(true) {}
|
||||
}; // ChangePasswordRequest
|
||||
|
||||
|
||||
private:
|
||||
std::string m_token;
|
||||
bool m_save_session;
|
||||
@ -124,12 +115,6 @@ namespace Online
|
||||
ServerJoinRequest * requestServerJoin(uint32_t server_id, bool request_now = true);
|
||||
|
||||
void requestFriendRequest(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;
|
||||
|
||||
XMLRequest * requestUserSearch(const irr::core::stringw & search_string) const;
|
||||
|
||||
void onSTKQuit() const;
|
||||
void onAchieving(uint32_t achievement_id) const;
|
||||
void requestPoll() const;
|
||||
|
@ -33,10 +33,12 @@ using namespace irr::core;
|
||||
using namespace irr::gui;
|
||||
using namespace Online;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ChangePasswordDialog::ChangePasswordDialog() :
|
||||
ModalDialog(0.8f,0.7f)
|
||||
/** Creates a modal dialog with given percentage of screen width and height
|
||||
*/
|
||||
ChangePasswordDialog::ChangePasswordDialog()
|
||||
: ModalDialog(0.8f,0.7f)
|
||||
{
|
||||
m_self_destroy = false;
|
||||
m_success = false;
|
||||
@ -65,15 +67,62 @@ ChangePasswordDialog::ChangePasswordDialog() :
|
||||
assert(m_submit_widget != NULL);
|
||||
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
|
||||
assert(m_cancel_widget != NULL);
|
||||
}
|
||||
} // ChangePasswordDialog
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
ChangePasswordDialog::~ChangePasswordDialog()
|
||||
{
|
||||
}
|
||||
} // ~ChangePasswordDialog
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Create and submit the request to the server to change the password.
|
||||
* \param current_password The current password.
|
||||
* \param new_password The new password.
|
||||
*/
|
||||
void ChangePasswordDialog::changePassword(const stringw ¤t_password,
|
||||
const stringw &new_password )
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
class ChangePasswordRequest : public XMLRequest
|
||||
{
|
||||
/** Callback for the change password request. If the matching dialog is
|
||||
* still open, show a confirmation message. */
|
||||
virtual void callback()
|
||||
{
|
||||
if (!GUIEngine::ModalDialog::isADialogActive()) return;
|
||||
ChangePasswordDialog * dialog =
|
||||
dynamic_cast<ChangePasswordDialog*>(GUIEngine::ModalDialog
|
||||
::getCurrent());
|
||||
if (dialog)
|
||||
{
|
||||
if (isSuccess())
|
||||
dialog->success();
|
||||
else
|
||||
dialog->error(getInfo());
|
||||
} // if dialog
|
||||
} // callback
|
||||
|
||||
public:
|
||||
ChangePasswordRequest() : XMLRequest(true) {}
|
||||
}; // ChangePasswordRequest
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
ChangePasswordRequest * request = new ChangePasswordRequest();
|
||||
CurrentUser::get()->setUserDetails(request);
|
||||
request->setServerURL("client-user.php");
|
||||
request->addParameter("action", "change_password");
|
||||
request->addParameter("userid", CurrentUser::get()->getID());
|
||||
request->addParameter("current", current_password);
|
||||
// The server code expects two passwords (and verifies again that they
|
||||
// are identical), so send the passwod twice.
|
||||
request->addParameter("new1", new_password);
|
||||
request->addParameter("new2", new_password);
|
||||
request->queue();
|
||||
} // changePassword
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ChangePasswordDialog::submit()
|
||||
{
|
||||
const stringw current_password = m_current_password_widget->getText().trim();
|
||||
@ -89,7 +138,8 @@ void ChangePasswordDialog::submit()
|
||||
{
|
||||
sfx_manager->quickSound("anvil");
|
||||
m_info_widget->setErrorColor();
|
||||
m_info_widget->setText(_("Password has to be between 8 and 30 characters long!"), false);
|
||||
m_info_widget->setText(_("Password has to be between 8 and 30 "
|
||||
"characters long!"), false);
|
||||
}
|
||||
else if (new_password1 != new_password2)
|
||||
{
|
||||
@ -101,17 +151,21 @@ void ChangePasswordDialog::submit()
|
||||
{
|
||||
m_options_widget->setDeactivated();
|
||||
m_info_widget->setDefaultColor();
|
||||
Online::CurrentUser::get()->requestPasswordChange(current_password, new_password1, new_password2);
|
||||
// We don't need to use password 2 anymore, it was already confirmed
|
||||
// that both passwords are identical.
|
||||
changePassword(current_password, new_password1);
|
||||
}
|
||||
}
|
||||
} // submit
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
GUIEngine::EventPropagation ChangePasswordDialog::processEvent(const std::string& eventSource)
|
||||
// ----------------------------------------------------------------------------
|
||||
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);
|
||||
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;
|
||||
@ -124,9 +178,9 @@ GUIEngine::EventPropagation ChangePasswordDialog::processEvent(const std::string
|
||||
}
|
||||
}
|
||||
return GUIEngine::EVENT_LET;
|
||||
}
|
||||
} // processEvent
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ChangePasswordDialog::onEnterPressedInternal()
|
||||
{
|
||||
@ -135,18 +189,18 @@ void ChangePasswordDialog::onEnterPressedInternal()
|
||||
return;
|
||||
if (m_submit_widget->isActivated())
|
||||
submit();
|
||||
}
|
||||
} // onEnterPressedInternal
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool ChangePasswordDialog::onEscapePressed()
|
||||
{
|
||||
if (m_cancel_widget->isActivated())
|
||||
m_self_destroy = true;
|
||||
return false;
|
||||
}
|
||||
} // onEscapePressed
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
void ChangePasswordDialog::success()
|
||||
{
|
||||
m_info_widget->setDefaultColor();
|
||||
@ -155,9 +209,9 @@ void ChangePasswordDialog::success()
|
||||
m_current_password_widget->setText("");
|
||||
m_new_password1_widget->setText("");
|
||||
m_new_password2_widget->setText("");
|
||||
}
|
||||
} // success
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
void ChangePasswordDialog::error(const irr::core::stringw & error)
|
||||
{
|
||||
sfx_manager->quickSound("anvil");
|
||||
@ -167,7 +221,7 @@ void ChangePasswordDialog::error(const irr::core::stringw & error)
|
||||
m_current_password_widget->setText("");
|
||||
m_new_password1_widget->setText("");
|
||||
m_new_password2_widget->setText("");
|
||||
}
|
||||
} // error
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@ -181,4 +235,4 @@ void ChangePasswordDialog::onUpdate(float dt)
|
||||
{
|
||||
ModalDialog::dismiss();
|
||||
}
|
||||
}
|
||||
} // onUpdate
|
||||
|
@ -19,13 +19,13 @@
|
||||
#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"
|
||||
|
||||
#include <irrString.h>
|
||||
|
||||
/**
|
||||
* \brief Dialog that allows a user to sign in
|
||||
* \ingroup states_screens
|
||||
@ -35,9 +35,6 @@ class ChangePasswordDialog : public GUIEngine::ModalDialog
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a modal dialog with given percentage of screen width and height
|
||||
*/
|
||||
ChangePasswordDialog();
|
||||
~ChangePasswordDialog();
|
||||
|
||||
@ -49,6 +46,8 @@ public:
|
||||
virtual void onUpdate(float dt);
|
||||
void success();
|
||||
void error(const irr::core::stringw & error_message);
|
||||
void changePassword(const irr::core::stringw ¤t_password,
|
||||
const irr::core::stringw &new_password);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -191,7 +191,12 @@ void OnlineUserSearch::search()
|
||||
{
|
||||
if (m_search_string != "" && m_last_search_string != m_search_string)
|
||||
{
|
||||
m_search_request = CurrentUser::get()->requestUserSearch(m_search_string);
|
||||
m_search_request = new XMLRequest();
|
||||
CurrentUser::get()->setUserDetails(m_search_request);
|
||||
m_search_request->addParameter("action", "user-search");
|
||||
m_search_request->addParameter("search-string", m_search_string);
|
||||
m_search_request->queue();
|
||||
|
||||
m_user_list_widget->clear();
|
||||
m_user_list_widget->addItem("spacer", L"");
|
||||
m_user_list_widget->addItem("loading", Messages::searching());
|
||||
@ -199,7 +204,7 @@ void OnlineUserSearch::search()
|
||||
m_search_box_widget->setDeactivated();
|
||||
m_search_button_widget->setDeactivated();
|
||||
}
|
||||
} // sarch
|
||||
} // search
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user