diff options
author | Yohann Ferreira <bertram@cegetel.net> | 2008-04-25 23:15:03 +0000 |
---|---|---|
committer | Yohann Ferreira <bertram@cegetel.net> | 2008-04-25 23:15:03 +0000 |
commit | 536f18bdaae32831aa92702535586f26d0628a42 (patch) | |
tree | f438efa69af7a6588bd00df126cd1f7c07bb8641 /src | |
parent | 23e6d031b6c9f20dea6ba48dd1826d3286e18233 (diff) | |
download | mana-client-536f18bdaae32831aa92702535586f26d0628a42.tar.gz mana-client-536f18bdaae32831aa92702535586f26d0628a42.tar.bz2 mana-client-536f18bdaae32831aa92702535586f26d0628a42.tar.xz mana-client-536f18bdaae32831aa92702535586f26d0628a42.zip |
Added client-side email address change ability.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/gui/changeemaildialog.cpp | 191 | ||||
-rw-r--r-- | src/gui/changeemaildialog.h | 74 | ||||
-rw-r--r-- | src/gui/changepassworddialog.cpp | 7 | ||||
-rw-r--r-- | src/gui/char_select.cpp | 31 | ||||
-rw-r--r-- | src/gui/char_select.h | 1 | ||||
-rw-r--r-- | src/logindata.h | 2 | ||||
-rw-r--r-- | src/main.cpp | 23 | ||||
-rw-r--r-- | src/main.h | 2 | ||||
-rw-r--r-- | src/net/loginhandler.cpp | 32 | ||||
-rw-r--r-- | src/net/protocol.h | 2 |
12 files changed, 356 insertions, 17 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2fb3b458..1a43ebb1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -69,6 +69,8 @@ SET(SRCS gui/buy.h gui/buysell.cpp gui/buysell.h + gui/changeemaildialog.cpp + gui/changeemaildialog.h gui/changepassworddialog.cpp gui/changepassworddialog.h gui/chargedialog.cpp @@ -134,6 +136,8 @@ SET(SRCS gui/npc_text.h gui/ok_dialog.cpp gui/ok_dialog.h + gui/partywindow.h + gui/partywindow.cpp gui/passwordfield.cpp gui/passwordfield.h gui/playerbox.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 9d739685..05f05d0b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,6 +21,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/buy.h \ gui/buysell.cpp \ gui/buysell.h \ + gui/changeemaildialog.cpp \ + gui/changeemaildialog.h \ gui/changepassworddialog.cpp \ gui/changepassworddialog.h \ gui/chargedialog.cpp \ @@ -88,6 +90,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/ok_dialog.h \ gui/truetypefont.cpp \ gui/truetypefont.h \ + gui/partywindow.h \ + gui/partywindow.cpp \ gui/passwordfield.cpp \ gui/passwordfield.h \ gui/playerbox.cpp \ diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp new file mode 100644 index 00000000..bb0329e6 --- /dev/null +++ b/src/gui/changeemaildialog.cpp @@ -0,0 +1,191 @@ +/* + * The Mana World + * Copyright 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World 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 2 of the License, or + * any later version. + * + * The Mana World 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 The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#include "changeemaildialog.h" + +#include <string> +#include <sstream> + +#include <guichan/widgets/label.hpp> + +#include "../main.h" +#include "../log.h" +#include "../logindata.h" + +#include "button.h" +#include "register.h" +#include "textfield.h" +#include "ok_dialog.h" + +#include "../utils/gettext.h" +#include "../utils/strprintf.h" + +ChangeEmailDialog::ChangeEmailDialog(Window *parent, LoginData *loginData): + Window(_("Change Email Address"), true, parent), + mWrongDataNoticeListener(new WrongDataNoticeListener()), + mLoginData(loginData) +{ + gcn::Label *accountLabel = new gcn::Label(strprintf(_("Account: %s"), + mLoginData->username.c_str())); + gcn::Label *oldEmailLabel = new gcn::Label(_("Current Email:")); + gcn::Label *newEmailLabel = new gcn::Label(_("Type New Email Address twice:")); + mOldEmailField = new TextField(); + mFirstEmailField = new TextField(); + mSecondEmailField = new TextField(); + mChangeEmailButton = new Button(_("Change Email Address"), "change_email", this); + mCancelButton = new Button(_("Cancel"), "cancel", this); + + const int width = 200; + const int height = 170; + setContentSize(width, height); + + accountLabel->setPosition(5, 5); + accountLabel->setWidth(130); + oldEmailLabel->setPosition( + 5, accountLabel->getY() + accountLabel->getHeight() + 7); + oldEmailLabel->setWidth(130); + + mOldEmailField->setPosition( + 5, oldEmailLabel->getY() + oldEmailLabel->getHeight() + 7); + mOldEmailField->setWidth(width - 5); + mOldEmailField->setWidth(130); + + newEmailLabel->setPosition( + 5, mOldEmailField->getY() + mOldEmailField->getHeight() + 7); + newEmailLabel->setWidth(width - 5); + + mFirstEmailField->setPosition( + 5, newEmailLabel->getY() + newEmailLabel->getHeight() + 7); + mFirstEmailField->setWidth(130); + + mSecondEmailField->setPosition( + 5, mFirstEmailField->getY() + mFirstEmailField->getHeight() + 7); + mSecondEmailField->setWidth(130); + + mCancelButton->setPosition( + width - 5 - mCancelButton->getWidth(), + height - 5 - mCancelButton->getHeight()); + mChangeEmailButton->setPosition( + mCancelButton->getX() - 5 - mChangeEmailButton->getWidth(), + mCancelButton->getY()); + + add(accountLabel); + add(oldEmailLabel); + add(mOldEmailField); + add(newEmailLabel); + add(mFirstEmailField); + add(mSecondEmailField); + add(mChangeEmailButton); + add(mCancelButton); + + setLocationRelativeTo(getParent()); + setVisible(true); + mOldEmailField->requestFocus(); + + mOldEmailField->setActionEventId("change_email"); + mFirstEmailField->setActionEventId("change_email"); + mSecondEmailField->setActionEventId("change_email"); +} + +ChangeEmailDialog::~ChangeEmailDialog() +{ + delete mWrongDataNoticeListener; +} + +void +ChangeEmailDialog::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "cancel") + { + scheduleDelete(); + } + else if (event.getId() == "change_email") + { + + const std::string username = mLoginData->username.c_str(); + const std::string oldEmail = mOldEmailField->getText(); + const std::string newFirstEmail = mFirstEmailField->getText(); + const std::string newSecondEmail = mSecondEmailField->getText(); + logger->log("ChangeEmailDialog::Email change, Username is %s", + username.c_str()); + + std::stringstream errorMsg; + int error = 0; + + // Checking current Email + if (oldEmail.empty()) + { + // First email address too short + errorMsg << "Please type your Email address."; + error = 1; + } + else if (newFirstEmail.length() < LEN_MIN_PASSWORD) + { + // First email address too short + errorMsg << "The new email address needs to be at least " + << LEN_MIN_PASSWORD + << " characters long."; + error = 2; + } + else if (newFirstEmail.length() > LEN_MAX_PASSWORD - 1 ) + { + // First email address too long + errorMsg << "The new email address needs to be less than " + << LEN_MAX_PASSWORD + << " characters long."; + error = 2; + } + else if (newFirstEmail != newSecondEmail) + { + // Second Pass mismatch + errorMsg << "The email address entries mismatch."; + error = 2; + } + + if (error > 0) + { + if (error == 1) + { + mWrongDataNoticeListener->setTarget(this->mOldEmailField); + } + else if (error == 2) + { + mWrongDataNoticeListener->setTarget(this->mFirstEmailField); + } + + OkDialog *dlg = new OkDialog("Error", errorMsg.str()); + dlg->addActionListener(mWrongDataNoticeListener); + } + else + { + // No errors detected, change account password. + mChangeEmailButton->setEnabled(false); + // Set the new email address + mLoginData->email = oldEmail; + mLoginData->newEmail = newFirstEmail; + state = STATE_CHANGEEMAIL_ATTEMPT; + scheduleDelete(); + } + + } +} diff --git a/src/gui/changeemaildialog.h b/src/gui/changeemaildialog.h new file mode 100644 index 00000000..22dc1263 --- /dev/null +++ b/src/gui/changeemaildialog.h @@ -0,0 +1,74 @@ +/* + * The Mana World + * Copyright 2008 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World 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 2 of the License, or + * any later version. + * + * The Mana World 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 The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $Id$ + */ + +#ifndef _TMW_GUI_CHANGEEMAIL_H +#define _TMW_GUI_CHANGEEMAIL_H + +#include <iosfwd> +#include <guichan/actionlistener.hpp> + +#include "window.h" +#include "../guichanfwd.h" + +class LoginData; +class OkDialog; +class WrongDataNoticeListener; + +/** + * The Change email dialog. + * + * \ingroup Interface + */ +class ChangeEmailDialog : public Window, public gcn::ActionListener { + public: + /** + * Constructor + * + * @see Window::Window + */ + ChangeEmailDialog(Window *parent, LoginData *loginData); + + /** + * Destructor + */ + ~ChangeEmailDialog(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + private: + gcn::TextField *mOldEmailField; + gcn::TextField *mFirstEmailField; + gcn::TextField *mSecondEmailField; + + gcn::Button *mChangeEmailButton; + gcn::Button *mCancelButton; + + WrongDataNoticeListener *mWrongDataNoticeListener; + + LoginData *mLoginData; +}; + +#endif diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp index 6f30d296..e3bb0511 100644 --- a/src/gui/changepassworddialog.cpp +++ b/src/gui/changepassworddialog.cpp @@ -33,7 +33,6 @@ #include "../logindata.h" #include "button.h" -#include "checkbox.h" #include "register.h" #include "passwordfield.h" #include "textfield.h" @@ -43,7 +42,7 @@ #include "../utils/strprintf.h" ChangePasswordDialog::ChangePasswordDialog(Window *parent, LoginData *loginData): - Window("Change Password", true, parent), + Window(_("Change Password"), true, parent), mWrongDataNoticeListener(new WrongDataNoticeListener()), mLoginData(loginData) { @@ -54,8 +53,8 @@ ChangePasswordDialog::ChangePasswordDialog(Window *parent, LoginData *loginData) gcn::Label *newPassLabel = new gcn::Label(_("Type New Password twice:")); mFirstPassField = new PasswordField(); mSecondPassField = new PasswordField(); - mChangePassButton = new Button("Change Password", "change_password", this); - mCancelButton = new Button("Cancel", "cancel", this); + mChangePassButton = new Button(_("Change Password"), "change_password", this); + mCancelButton = new Button(_("Cancel"), "cancel", this); const int width = 200; const int height = 170; diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index d5a487fb..c011aa84 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -37,6 +37,7 @@ #include "unregisterdialog.h" #include "changepassworddialog.h" +#include "changeemaildialog.h" #include "widgets/layout.h" @@ -99,6 +100,7 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo, mNextButton = new Button(_("Next"), "next", this); mUnRegisterButton = new Button(_("Unregister"), "unregister", this); mChangePasswordButton = new Button(_("Change Password"), "change_password", this); + mChangeEmailButton = new Button(_("Change Email Address"), "change_email", this); mAccountNameLabel = new gcn::Label(strprintf(_("Account: %s"), mLoginData->username.c_str())); mNameLabel = new gcn::Label(strprintf(_("Name: %s"), "")); @@ -113,25 +115,28 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo, place = getPlacer(0, 0); place(0, 0, mAccountNameLabel); place(0, 1, mUnRegisterButton); - place(1, 1, mChangePasswordButton); - place(0, 2, mPlayerBox, 1, 5).setPadding(3); - place(1, 2, mNameLabel, 3); - place(1, 3, mLevelLabel, 3); - place(1, 4, mMoneyLabel, 3); - place(1, 5, mPreviousButton); - place(2, 5, mNextButton); - place(1, 6, mNewCharButton); - place(2, 6, mDelCharButton); - place.getCell().matchColWidth(1, 2); + place(0, 2, mChangePasswordButton); + place(1, 2, mChangeEmailButton); place = getPlacer(0, 1); + place(0, 0, mPlayerBox, 1, 5).setPadding(3); + place(1, 0, mNameLabel, 3); + place(1, 1, mLevelLabel, 3); + place(1, 2, mMoneyLabel, 3); + place(1, 3, mPreviousButton); + place(2, 3, mNextButton); + place(1, 4, mNewCharButton); + place(2, 4, mDelCharButton); + place.getCell().matchColWidth(1, 2); + place = getPlacer(0, 2); place(0, 0, mSelectButton); place(1, 0, mCancelButton); - reflowLayout(350, 0); + reflowLayout(265, 0); setLocationRelativeTo(getParent()); setVisible(true); mSelectButton->requestFocus(); updatePlayerInfo(); + } void CharSelectDialog::action(const gcn::ActionEvent &event) @@ -191,6 +196,10 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) { new ChangePasswordDialog(this, mLoginData); } + else if (event.getId() == "change_email") + { + new ChangeEmailDialog(this, mLoginData); + } } void CharSelectDialog::updatePlayerInfo() diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 9c7bac24..0c1dbe45 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -71,6 +71,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener gcn::Button *mNextButton; gcn::Button *mUnRegisterButton; gcn::Button *mChangePasswordButton; + gcn::Button *mChangeEmailButton; gcn::Label *mAccountNameLabel; gcn::Label *mNameLabel; diff --git a/src/logindata.h b/src/logindata.h index a43f13bb..689a5aaa 100644 --- a/src/logindata.h +++ b/src/logindata.h @@ -33,6 +33,7 @@ struct LoginData std::string newPassword; std::string hostname; std::string email; + std::string newEmail; short port; bool remember; /**< Whether to store the username and host. */ @@ -45,6 +46,7 @@ struct LoginData newPassword = ""; hostname = ""; email = ""; + newEmail = ""; port = 0; }; }; diff --git a/src/main.cpp b/src/main.cpp index d5d99f31..3d1a0e27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -578,6 +578,14 @@ void accountChangePassword(LoginData *loginData) loginData->newPassword); } +void accountChangeEmail(LoginData *loginData) +{ + Net::registerHandler(&loginHandler); + + Net::AccountServer::Account::changeEmail(loginData->username, + loginData->newEmail); +} + void switchCharacter(std::string* passToken) { Net::registerHandler(&logoutHandler); @@ -1000,6 +1008,21 @@ int main(int argc, char *argv[]) break; + case STATE_CHANGEEMAIL_ATTEMPT: + logger->log("State: CHANGE EMAIL ATTEMPT"); + accountChangeEmail(&loginData); + break; + + case STATE_CHANGEEMAIL: + logger->log("State: CHANGE EMAIL"); + currentDialog = new OkDialog("Email Address change", + "Email Address changed successfully!"); + currentDialog->addActionListener(&accountListener); + currentDialog = NULL; // OkDialog deletes itself + loginData.email = loginData.newEmail; + loginData.newEmail = ""; + break; + case STATE_CHANGEPASSWORD_ATTEMPT: logger->log("State: CHANGE PASSWORD ATTEMPT"); accountChangePassword(&loginData); @@ -81,6 +81,8 @@ enum { STATE_ACCOUNTCHANGE_ERROR, STATE_ERROR, STATE_CHAR_SELECT, + STATE_CHANGEEMAIL_ATTEMPT, + STATE_CHANGEEMAIL, STATE_CHANGEPASSWORD_ATTEMPT, STATE_CHANGEPASSWORD, STATE_UNREGISTER_ATTEMPT, diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index 39b2e194..3a5b1c64 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -35,6 +35,7 @@ LoginHandler::LoginHandler() APMSG_REGISTER_RESPONSE, APMSG_RECONNECT_RESPONSE, APMSG_PASSWORD_CHANGE_RESPONSE, + APMSG_EMAIL_CHANGE_RESPONSE, 0 }; handledMessages = _messages; @@ -167,5 +168,36 @@ void LoginHandler::handleMessage(MessageIn &msg) } } break; + + case APMSG_EMAIL_CHANGE_RESPONSE: + { + int errMsg = msg.readInt8(); + // Successful pass change + if (errMsg == ERRMSG_OK) + { + state = STATE_CHANGEEMAIL; + } + // pass change failed + else + { + switch (errMsg) { + case ERRMSG_INVALID_ARGUMENT: + errorMessage = "New email address incorrect"; + break; + case ERRMSG_FAILURE: + errorMessage = "Old email address incorrect"; + break; + case ERRMSG_NO_LOGIN: + errorMessage = "Account not connected. Please login first."; + break; + default: + errorMessage = "Unknown error"; + break; + } + state = STATE_ACCOUNTCHANGE_ERROR; + } + } + break; + } } diff --git a/src/net/protocol.h b/src/net/protocol.h index e26e9ed5..76610635 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -54,8 +54,6 @@ enum { APMSG_CHAR_SELECT_RESPONSE = 0x0027, // B error, B*32 token, S game address, W game port, S chat address, W chat port PAMSG_EMAIL_CHANGE = 0x0030, // S email APMSG_EMAIL_CHANGE_RESPONSE = 0x0031, // B error - PAMSG_EMAIL_GET = 0x0032, // - - APMSG_EMAIL_GET_RESPONSE = 0x0033, // B error, S email PAMSG_PASSWORD_CHANGE = 0x0034, // S old password, S new password APMSG_PASSWORD_CHANGE_RESPONSE = 0x0035, // B error |