summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog15
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/gui/changepassworddialog.cpp192
-rw-r--r--src/gui/changepassworddialog.h74
-rw-r--r--src/gui/char_select.cpp37
-rw-r--r--src/gui/char_select.h2
-rw-r--r--src/gui/unregisterdialog.cpp70
-rw-r--r--src/gui/unregisterdialog.h1
-rw-r--r--src/logindata.h2
-rw-r--r--src/main.cpp26
-rw-r--r--src/main.h2
11 files changed, 353 insertions, 70 deletions
diff --git a/ChangeLog b/ChangeLog
index a9a924b8..2bd16773 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,15 @@
+2008-04-18 Yohann Ferreira <bertram@cegetel.net>
+
+ * src/gui/char_select.h, src/gui/char_select.cpp,
+ src/gui/unregisterdialog.h, src/gui/unregisterdialog.cpp,
+ src/main.cpp, src/main.h, src/logindata.h,
+ src/gui/changepassworddialog.h, src/gui/changepassworddialog.cpp,
+ src/CMakeLists.txt: Added a change password dialog. State code is to
+ be reworked.
+
2008-04-18 David Athay <ko2fan@gmail.com>
- * src/gui/chat.h, src/gui/widgets/tabbedarea.h,
+ * src/gui/chat.h, src/gui/widgets/tabbedarea.h,
src/gui/widgets/tabbedarea.cpp, src/gui/chat.cpp,
src/gui/guildwindow.cpp, src/gui/gui.cpp, src/CMakeLists.txt,
src/net/guildhandler.cpp, src/net/chathandler.cpp, src/Makefile.am,
@@ -32,7 +41,7 @@
2008-04-16 David Athay <ko2fan@gmail.com>
- * src/gui/guildlistbox.cpp, src/gui/guildwindow.h,
+ * src/gui/guildlistbox.cpp, src/gui/guildwindow.h,
src/gui/widgets/tabbedarea.cpp, src/gui/chat.cpp,
src/gui/guildlistbox.h, src/gui/guildwindow.cpp, src/guild.cpp,
src/guild.h, src/net/guildhandler.cpp: Fixed online status so that
@@ -42,7 +51,7 @@
2008-04-15 David Athay <ko2fan@gmail.com>
- * src/gui/guildlistbox.cpp, src/gui/guildwindow.h
+ * src/gui/guildlistbox.cpp, src/gui/guildwindow.h
src/gui/widgets/tabbedarea.h, src/gui/widgets/tabbedarea.cpp,
src/gui/guildlistbox.h, src/gui/guildwindow.cpp,
src/net/guildhandler.cpp, src/net/protocol.h, src/net/chathandler.cpp,
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dcc1ba08..9a35e7fc 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/changepassworddialog.cpp
+ gui/changepassworddialog.h
gui/chargedialog.cpp
gui/chargedialog.h
gui/char_select.cpp
diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp
new file mode 100644
index 00000000..1a7c043e
--- /dev/null
+++ b/src/gui/changepassworddialog.cpp
@@ -0,0 +1,192 @@
+/*
+ * The Mana World
+ * Copyright 2004 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 "changepassworddialog.h"
+
+#include <string>
+#include <sstream>
+
+#include <guichan/widgets/label.hpp>
+
+#include "../main.h"
+#include "../log.h"
+#include "../logindata.h"
+
+#include "button.h"
+#include "checkbox.h"
+#include "register.h"
+#include "passwordfield.h"
+#include "textfield.h"
+#include "ok_dialog.h"
+
+#include "../utils/gettext.h"
+#include "../utils/strprintf.h"
+
+ChangePasswordDialog::ChangePasswordDialog(Window *parent, LoginData *loginData):
+ Window("Change Password", true, parent),
+ mWrongDataNoticeListener(new WrongDataNoticeListener()),
+ mLoginData(loginData)
+{
+ gcn::Label *accountLabel = new gcn::Label(strprintf(_("Account: %s"),
+ mLoginData->username.c_str()));
+ gcn::Label *oldPassLabel = new gcn::Label(_("Password:"));
+ mOldPassField = new PasswordField();
+ 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);
+
+ const int width = 200;
+ const int height = 170;
+ setContentSize(width, height);
+
+ accountLabel->setPosition(5, 5);
+ accountLabel->setWidth(130);
+ oldPassLabel->setPosition(
+ 5, accountLabel->getY() + accountLabel->getHeight() + 7);
+ oldPassLabel->setWidth(130);
+
+ mOldPassField->setPosition(
+ 5, oldPassLabel->getY() + oldPassLabel->getHeight() + 7);
+ mOldPassField->setWidth(130);
+
+ newPassLabel->setPosition(
+ 5, mOldPassField->getY() + mOldPassField->getHeight() + 7);
+ newPassLabel->setWidth(width - 5);
+
+ mFirstPassField->setPosition(
+ 5, newPassLabel->getY() + newPassLabel->getHeight() + 7);
+ mFirstPassField->setWidth(130);
+
+ mSecondPassField->setPosition(
+ 5, mFirstPassField->getY() + mFirstPassField->getHeight() + 7);
+ mSecondPassField->setWidth(130);
+
+ mCancelButton->setPosition(
+ width - 5 - mCancelButton->getWidth(),
+ height - 5 - mCancelButton->getHeight());
+ mChangePassButton->setPosition(
+ mCancelButton->getX() - 5 - mChangePassButton->getWidth(),
+ mCancelButton->getY());
+
+ add(accountLabel);
+ add(oldPassLabel);
+ add(mOldPassField);
+ add(newPassLabel);
+ add(mFirstPassField);
+ add(mSecondPassField);
+ add(mChangePassButton);
+ add(mCancelButton);
+
+ setLocationRelativeTo(getParent());
+ setVisible(true);
+ mFirstPassField->requestFocus();
+}
+
+ChangePasswordDialog::~ChangePasswordDialog()
+{
+ delete mWrongDataNoticeListener;
+}
+
+void
+ChangePasswordDialog::action(const gcn::ActionEvent &event)
+{
+ if (event.getId() == "cancel")
+ {
+ scheduleDelete();
+ }
+ else if (event.getId() == "change_password")
+ {
+
+ const std::string username = mLoginData->username.c_str();
+ const std::string oldPassword = mOldPassField->getText();
+ const std::string newFirstPass = mFirstPassField->getText();
+ const std::string newSecondPass = mSecondPassField->getText();
+ logger->log("ChangePasswordDialog::Password change, Username is %s",
+ username.c_str());
+
+ std::stringstream errorMsg;
+ int error = 0;
+
+ // Check old Password
+ if (oldPassword.empty())
+ {
+ // No old password
+ errorMsg << "Enter the old Password first.";
+ error = 1;
+ }
+ else if (newFirstPass.length() < LEN_MIN_PASSWORD)
+ {
+ // First password too short
+ errorMsg << "The new password needs to be at least "
+ << LEN_MIN_PASSWORD
+ << " characters long.";
+ error = 2;
+ }
+ else if (newFirstPass.length() > LEN_MAX_PASSWORD - 1 )
+ {
+ // First password too long
+ errorMsg << "The new password needs to be less than "
+ << LEN_MAX_PASSWORD
+ << " characters long.";
+ error = 2;
+ }
+ else if (newFirstPass != newSecondPass)
+ {
+ // Second Pass mismatch
+ errorMsg << "The new password entries mismatch.";
+ error = 3;
+ }
+
+ if (error > 0)
+ {
+ if (error == 1)
+ {
+ mWrongDataNoticeListener->setTarget(this->mOldPassField);
+ }
+ else if (error == 2)
+ {
+ mWrongDataNoticeListener->setTarget(this->mFirstPassField);
+ }
+ else if (error == 3)
+ {
+ mWrongDataNoticeListener->setTarget(this->mSecondPassField);
+ }
+
+ OkDialog *dlg = new OkDialog("Error", errorMsg.str());
+ dlg->addActionListener(mWrongDataNoticeListener);
+ }
+ else
+ {
+ // No errors detected, change account password.
+ mChangePassButton->setEnabled(false);
+ // Set the new password
+ mLoginData->password = oldPassword;
+ mLoginData->newPassword = newFirstPass;
+ state = STATE_CHANGEPASSWORD_ATTEMPT;
+ scheduleDelete();
+ }
+
+ }
+}
diff --git a/src/gui/changepassworddialog.h b/src/gui/changepassworddialog.h
new file mode 100644
index 00000000..9a809745
--- /dev/null
+++ b/src/gui/changepassworddialog.h
@@ -0,0 +1,74 @@
+/*
+ * The Mana World
+ * Copyright 2004 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_CHANGEPASSWORDDIALOG_H
+#define _TMW_CHANGEPASSWORDDIALOG_H
+
+#include <iosfwd>
+#include <guichan/actionlistener.hpp>
+
+#include "window.h"
+#include "../guichanfwd.h"
+
+class LoginData;
+class OkDialog;
+class WrongDataNoticeListener;
+
+/**
+ * The Change password dialog.
+ *
+ * \ingroup Interface
+ */
+class ChangePasswordDialog : public Window, public gcn::ActionListener {
+ public:
+ /**
+ * Constructor
+ *
+ * @see Window::Window
+ */
+ ChangePasswordDialog(Window *parent,LoginData *loginData);
+
+ /**
+ * Destructor
+ */
+ ~ChangePasswordDialog();
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const gcn::ActionEvent &event);
+
+ private:
+ gcn::TextField *mOldPassField;
+ gcn::TextField *mFirstPassField;
+ gcn::TextField *mSecondPassField;
+
+ gcn::Button *mChangePassButton;
+ gcn::Button *mCancelButton;
+
+ WrongDataNoticeListener *mWrongDataNoticeListener;
+
+ LoginData *mLoginData;
+};
+
+#endif
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index b2d3b53e..71018b1e 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -36,6 +36,7 @@
#include "textfield.h"
#include "unregisterdialog.h"
+#include "changepassworddialog.h"
#include "widgets/layout.h"
@@ -86,7 +87,7 @@ void CharDeleteConfirm::action(const gcn::ActionEvent &event)
CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo,
LoginData *loginData):
- Window(_("Select Character")),
+ Window(_("Account and Character Management")),
mCharInfo(charInfo), mCharSelected(false), mLoginData(loginData)
{
@@ -96,8 +97,10 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo,
mDelCharButton = new Button(_("Delete"), "delete", this);
mPreviousButton = new Button(_("Previous"), "previous", this);
mNextButton = new Button(_("Next"), "next", this);
- mUnRegisterButton = new Button(_("Delete"), "unregister", this);
+ mUnRegisterButton = new Button(_("Unregister"), "unregister", this);
+ mChangePasswordButton = new Button(_("Change Password"), "change_password", this);
+ mAccountNameLabel = new gcn::Label(strprintf(_("Account: %s"), mLoginData->username.c_str()));
mNameLabel = new gcn::Label(strprintf(_("Name: %s"), ""));
mLevelLabel = new gcn::Label(strprintf(_("Level: %d"), 0));
mMoneyLabel = new gcn::Label(strprintf(_("Money: %d"), 0));
@@ -108,20 +111,22 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo,
ContainerPlacer place;
place = getPlacer(0, 0);
- 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(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 = getPlacer(0, 1);
- place(0, 0, mUnRegisterButton);
- place(2, 0, mSelectButton);
- place(3, 0, mCancelButton);
- reflowLayout(250, 0);
+ place(0, 0, mSelectButton);
+ place(1, 0, mCancelButton);
+ reflowLayout(350, 0);
setLocationRelativeTo(getParent());
setVisible(true);
@@ -181,6 +186,10 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
{
new UnRegisterDialog(this, mLoginData);
}
+ else if (event.getId() == "change_password")
+ {
+ new ChangePasswordDialog(this, mLoginData);
+ }
}
void CharSelectDialog::updatePlayerInfo()
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index d275c451..9c7bac24 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -70,7 +70,9 @@ class CharSelectDialog : public Window, public gcn::ActionListener
gcn::Button *mPreviousButton;
gcn::Button *mNextButton;
gcn::Button *mUnRegisterButton;
+ gcn::Button *mChangePasswordButton;
+ gcn::Label *mAccountNameLabel;
gcn::Label *mNameLabel;
gcn::Label *mLevelLabel;
gcn::Label *mMoneyLabel;
diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp
index 5558e8fc..06ba729d 100644
--- a/src/gui/unregisterdialog.cpp
+++ b/src/gui/unregisterdialog.cpp
@@ -39,29 +39,30 @@
#include "textfield.h"
#include "ok_dialog.h"
+#include "../utils/gettext.h"
+#include "../utils/strprintf.h"
+
UnRegisterDialog::UnRegisterDialog(Window *parent, LoginData *loginData):
Window("Unregister", true, parent),
mWrongDataNoticeListener(new WrongDataNoticeListener()),
mLoginData(loginData)
{
- gcn::Label *userLabel = new gcn::Label("Name:");
- gcn::Label *passwordLabel = new gcn::Label("Password:");
- mUserField = new TextField(mLoginData->username);
+ gcn::Label *userLabel = new gcn::Label(strprintf(_("Name: %s"), mLoginData->username.c_str()));
+ gcn::Label *passwordLabel = new gcn::Label(_("Password:"));
mPasswordField = new PasswordField(mLoginData->password);
- mUnRegisterButton = new Button("Unregister", "unregister", this);
- mCancelButton = new Button("Cancel", "cancel", this);
+ mUnRegisterButton = new Button(_("Unregister"), "unregister", this);
+ mCancelButton = new Button(_("Cancel"), "cancel", this);
- const int width = 200;
- const int height = 70;
+ const int width = 210;
+ const int height = 80;
setContentSize(width, height);
- mUserField->setPosition(65, 5);
- mUserField->setWidth(130);
+ userLabel->setPosition(5, 5);
+ userLabel->setWidth(width - 5);
mPasswordField->setPosition(
- 65, mUserField->getY() + mUserField->getHeight() + 7);
+ 68, userLabel->getY() + userLabel->getHeight() + 7);
mPasswordField->setWidth(130);
- userLabel->setPosition(5, mUserField->getY() + 1);
passwordLabel->setPosition(5, mPasswordField->getY() + 1);
mCancelButton->setPosition(
@@ -73,7 +74,6 @@ UnRegisterDialog::UnRegisterDialog(Window *parent, LoginData *loginData):
add(userLabel);
add(passwordLabel);
- add(mUserField);
add(mPasswordField);
add(mUnRegisterButton);
add(mCancelButton);
@@ -97,44 +97,22 @@ UnRegisterDialog::action(const gcn::ActionEvent &event)
}
else if (event.getId() == "unregister")
{
- const std::string username = mUserField->getText();
+ const std::string username = mLoginData->username.c_str();
const std::string password = mPasswordField->getText();
logger->log("UnregisterDialog::unregistered, Username is %s",
username.c_str());
std::stringstream errorMsg;
- int error = 0;
+ bool error = false;
- // Check login
- if (username.empty())
- {
- // No username
- errorMsg << "Enter your username first.";
- error = 1;
- }
- else if (username.length() < LEN_MIN_USERNAME)
- {
- // Name too short
- errorMsg << "The username needs to be at least "
- << LEN_MIN_USERNAME
- << " characters long.";
- error = 1;
- }
- else if (username.length() > LEN_MAX_USERNAME - 1 )
- {
- // Name too long
- errorMsg << "The username needs to be less than "
- << LEN_MAX_USERNAME
- << " characters long.";
- error = 1;
- }
- else if (password.length() < LEN_MIN_PASSWORD)
+ // Check password
+ if (password.length() < LEN_MIN_PASSWORD)
{
// Pass too short
errorMsg << "The password needs to be at least "
<< LEN_MIN_PASSWORD
<< " characters long.";
- error = 2;
+ error = true;
}
else if (password.length() > LEN_MAX_PASSWORD - 1 )
{
@@ -142,19 +120,12 @@ UnRegisterDialog::action(const gcn::ActionEvent &event)
errorMsg << "The password needs to be less than "
<< LEN_MAX_PASSWORD
<< " characters long.";
- error = 2;
+ error = true;
}
- if (error > 0)
+ if (error)
{
- if (error == 1)
- {
- mWrongDataNoticeListener->setTarget(this->mUserField);
- }
- else if (error == 2)
- {
- mWrongDataNoticeListener->setTarget(this->mPasswordField);
- }
+ mWrongDataNoticeListener->setTarget(this->mPasswordField);
OkDialog *dlg = new OkDialog("Error", errorMsg.str());
dlg->addActionListener(mWrongDataNoticeListener);
@@ -163,7 +134,6 @@ UnRegisterDialog::action(const gcn::ActionEvent &event)
{
// No errors detected, unregister the new user.
mUnRegisterButton->setEnabled(false);
- mLoginData->username = username;
mLoginData->password = password;
state = STATE_UNREGISTER_ATTEMPT;
scheduleDelete();
diff --git a/src/gui/unregisterdialog.h b/src/gui/unregisterdialog.h
index 8ba380dd..8c8eaf64 100644
--- a/src/gui/unregisterdialog.h
+++ b/src/gui/unregisterdialog.h
@@ -59,7 +59,6 @@ class UnRegisterDialog : public Window, public gcn::ActionListener {
void action(const gcn::ActionEvent &event);
private:
- gcn::TextField *mUserField;
gcn::TextField *mPasswordField;
gcn::Button *mUnRegisterButton;
diff --git a/src/logindata.h b/src/logindata.h
index ad6537b6..a43f13bb 100644
--- a/src/logindata.h
+++ b/src/logindata.h
@@ -30,6 +30,7 @@ struct LoginData
{
std::string username;
std::string password;
+ std::string newPassword;
std::string hostname;
std::string email;
short port;
@@ -41,6 +42,7 @@ struct LoginData
{
username = "";
password = "";
+ newPassword = "";
hostname = "";
email = "";
port = 0;
diff --git a/src/main.cpp b/src/main.cpp
index a1146c27..55a3d425 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -552,6 +552,14 @@ void accountUnRegister(LoginData *loginData)
}
+void accountChangePassword(LoginData *loginData)
+{
+ Net::registerHandler(&loginHandler);
+
+ Net::AccountServer::Account::changePassword(loginData->password,
+ loginData->newPassword);
+}
+
void switchCharacter(std::string* passToken)
{
Net::registerHandler(&logoutHandler);
@@ -721,7 +729,7 @@ int main(int argc, char *argv[])
gcn::Container *top = static_cast<gcn::Container*>(gui->getTop());
#ifdef PACKAGE_VERSION
gcn::Label *versionLabel = new gcn::Label(PACKAGE_VERSION);
- top->add(versionLabel, 2, 2);
+ top->add(versionLabel, 25, 2);
#endif
sound.playMusic("Magick - Real.ogg");
@@ -967,6 +975,20 @@ int main(int argc, char *argv[])
break;
+ case STATE_CHANGEPASSWORD_ATTEMPT:
+ logger->log("State: CHANGE PASSWORD ATTEMPT");
+ accountChangePassword(&loginData);
+ break;
+
+ case STATE_CHANGEPASSWORD:
+ logger->log("State: CHANGE PASSWORD");
+ currentDialog = new OkDialog("Password change",
+ "Password changed successfully!");
+ loginData.password = loginData.newPassword;
+ loginData.newPassword = "";
+ state = STATE_LOGIN;
+ break;
+
case STATE_UNREGISTER_ATTEMPT:
logger->log("State: UNREGISTER ATTEMPT");
accountUnRegister(&loginData);
@@ -976,7 +998,7 @@ int main(int argc, char *argv[])
case STATE_UNREGISTER:
logger->log("State: UNREGISTER");
accountServerConnection->disconnect();
- currentDialog = new OkDialog("Unregister succesfull",
+ currentDialog = new OkDialog("Unregister successful",
"Farewell, come back any time ....");
//The errorlistener sets the state to STATE_CHOOSE_SERVER
diff --git a/src/main.h b/src/main.h
index 3835f355..3522405f 100644
--- a/src/main.h
+++ b/src/main.h
@@ -79,6 +79,8 @@ enum {
STATE_REGISTER_ATTEMPT,
STATE_ERROR,
STATE_CHAR_SELECT,
+ STATE_CHANGEPASSWORD_ATTEMPT,
+ STATE_CHANGEPASSWORD,
STATE_UNREGISTER_ATTEMPT,
STATE_UNREGISTER,
STATE_SWITCH_CHARACTER,