summaryrefslogtreecommitdiff
path: root/src/pincodemanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-03-08 06:07:15 +0300
committerAndrei Karas <akaras@inbox.ru>2018-03-08 06:07:15 +0300
commitfc1ca42ed5a1b2d83a1dc8f94709a057b8e28e9d (patch)
treef7f8af4849bc214a27ea8205410568b76ce5ec30 /src/pincodemanager.cpp
parent6b3b81988ea37207eeeb2994761e307c6b6fb340 (diff)
downloadmanaverse-fc1ca42ed5a1b2d83a1dc8f94709a057b8e28e9d.tar.gz
manaverse-fc1ca42ed5a1b2d83a1dc8f94709a057b8e28e9d.tar.bz2
manaverse-fc1ca42ed5a1b2d83a1dc8f94709a057b8e28e9d.tar.xz
manaverse-fc1ca42ed5a1b2d83a1dc8f94709a057b8e28e9d.zip
Add support for change pin code by server request.
Diffstat (limited to 'src/pincodemanager.cpp')
-rw-r--r--src/pincodemanager.cpp80
1 files changed, 79 insertions, 1 deletions
diff --git a/src/pincodemanager.cpp b/src/pincodemanager.cpp
index d8f2cea5a..67b14f2bf 100644
--- a/src/pincodemanager.cpp
+++ b/src/pincodemanager.cpp
@@ -27,6 +27,7 @@
#include "gui/widgets/createwidget.h"
+#include "listeners/changepincodelistener.h"
#include "listeners/newpincodelistener.h"
#include "listeners/newpincoderetrylistener.h"
#include "listeners/pincodelistener.h"
@@ -40,6 +41,7 @@
PincodeManager pincodeManager;
PincodeManager::PincodeManager() :
+ mOldPincode(),
mNewPincode(),
mSeed(0U),
mAccountId(BeingId_zero),
@@ -57,6 +59,7 @@ void PincodeManager::init()
mSeed = 0;
mAccountId = BeingId_zero;
mState = PincodeState::None;
+ mNewPincode.clear();
}
void PincodeManager::clearDialog(const PincodeDialog *const PincodeDialog)
@@ -82,11 +85,12 @@ void PincodeManager::updateState()
mDialog->addActionListener(&pincodeListener);
break;
case PincodeState::Create:
+ mNewPincode.clear();
CREATEWIDGETV(mDialog, PincodeDialog,
// TRANSLATORS: dialog caption
_("New pincode"),
// TRANSLATORS: dialog label
- _("Set new pincode"),
+ _("Enter new pincode"),
mSeed,
nullptr);
mDialog->requestFocus();
@@ -94,6 +98,19 @@ void PincodeManager::updateState()
mDialog->addActionListener(&newPincodeListener);
break;
case PincodeState::Change:
+ mOldPincode.clear();
+ mNewPincode.clear();
+ CREATEWIDGETV(mDialog, PincodeDialog,
+ // TRANSLATORS: dialog caption
+ _("Change pincode"),
+ // TRANSLATORS: dialog label
+ _("Enter old pincode"),
+ mSeed,
+ nullptr);
+ mDialog->requestFocus();
+ mDialog->setActionEventId("ok");
+ mDialog->addActionListener(&changePincodeListener);
+ break;
case PincodeState::None:
default:
break;
@@ -144,6 +161,67 @@ void PincodeManager::setNewPincode(const std::string &pincode)
}
}
+void PincodeManager::changePincode(const std::string &pincode)
+{
+ if (mOldPincode.empty())
+ { // set old pincode
+ mOldPincode = pincode;
+ CREATEWIDGETV(mDialog, PincodeDialog,
+ // TRANSLATORS: dialog caption
+ _("Change pincode"),
+ // TRANSLATORS: dialog label
+ _("Enter new pincode"),
+ mSeed,
+ nullptr);
+ mDialog->requestFocus();
+ mDialog->setActionEventId("ok");
+ mDialog->addActionListener(&changePincodeListener);
+ }
+ else if (mNewPincode.empty())
+ { // set first new pincode
+ mNewPincode = pincode;
+ CREATEWIDGETV(mDialog, PincodeDialog,
+ // TRANSLATORS: dialog caption
+ _("Change pincode"),
+ // TRANSLATORS: dialog label
+ _("Confirm new pincode"),
+ mSeed,
+ nullptr);
+ mDialog->requestFocus();
+ mDialog->setActionEventId("ok");
+ mDialog->addActionListener(&changePincodeListener);
+ }
+ else
+ { // new pincode confirmation
+ if (mNewPincode != pincode)
+ {
+ mOldPincode.clear();
+ mNewPincode.clear();
+ CREATEWIDGETV(mDialog, OkDialog,
+ // TRANSLATORS: error header
+ _("Pincode"),
+ // TRANSLATORS: error message
+ _("Wrong pincode confirmation!"),
+ // TRANSLATORS: ok dialog button
+ _("OK"),
+ DialogType::ERROR,
+ Modal_true,
+ ShowCenter_true,
+ nullptr,
+ 260);
+ mDialog->addActionListener(&newPincodeRetryListener);
+ }
+ else
+ {
+ charServerHandler->changePincode(mAccountId,
+ mOldPincode,
+ mNewPincode);
+ mOldPincode.clear();
+ mNewPincode.clear();
+ }
+ }
+}
+
void PincodeManager::sendPincode(const std::string &pincode)
{
charServerHandler->sendCheckPincode(mAccountId,