Simpler forgot password functionality (#2393)

* Simpler forgot password functionality (Server/Client)
This commit is contained in:
woogerboy21 2017-02-15 17:41:40 -05:00 committed by Zach H
parent b64eab204c
commit 0cfa6863d5
36 changed files with 1190 additions and 173 deletions

View file

@ -35,6 +35,9 @@ enum ClientStatus {
StatusActivating,
StatusLoggingIn,
StatusLoggedIn,
StatusRequestingForgotPassword,
StatusSubmitForgotPasswordReset,
StatusSubmitForgotPasswordChallenge,
};
class AbstractClient : public QObject {

View file

@ -11,6 +11,7 @@
#include <QMessageBox>
#include <iostream>
#include <QGroupBox>
#include <QPushButton>
#include "dlg_connect.h"
#include "settingscache.h"
@ -69,6 +70,17 @@ DlgConnect::DlgConnect(QWidget *parent)
connect(savePasswordCheckBox, SIGNAL(stateChanged(int)), this, SLOT(passwordSaved(int)));
btnForgotPassword = new QPushButton(tr("Forgot password"));
connect(btnForgotPassword, SIGNAL(released()), this, SLOT(actForgotPassword()));
btnOk = new QPushButton(tr("Connect"));
btnOk->setFixedWidth(100);
connect(btnOk, SIGNAL(released()), this, SLOT(actOk()));
btnCancel = new QPushButton(tr("Cancel"));
btnCancel->setFixedWidth(100);
connect(btnCancel, SIGNAL(released()), this, SLOT(actCancel()));
QGridLayout *connectionLayout = new QGridLayout;
connectionLayout->addWidget(previousHostButton, 0, 1);
connectionLayout->addWidget(previousHosts, 1, 1);
@ -79,6 +91,11 @@ DlgConnect::DlgConnect(QWidget *parent)
connectionLayout->addWidget(portEdit, 4, 1);
connectionLayout->addWidget(autoConnectCheckBox, 5, 1);
QGridLayout *buttons = new QGridLayout;
buttons->addWidget(btnOk, 0, 0);
buttons->addWidget(btnForgotPassword, 0, 1);
buttons->addWidget(btnCancel, 0, 2);
QGroupBox *restrictionsGroupBox = new QGroupBox(tr("Server"));
restrictionsGroupBox->setLayout(connectionLayout);
@ -92,17 +109,16 @@ DlgConnect::DlgConnect(QWidget *parent)
QGroupBox *loginGroupBox = new QGroupBox(tr("Login"));
loginGroupBox->setLayout(loginLayout);
QGroupBox *btnGroupBox = new QGroupBox(tr(""));
btnGroupBox->setLayout(buttons);
QGridLayout *grid = new QGridLayout;
grid->addWidget(restrictionsGroupBox, 0, 0);
grid->addWidget(loginGroupBox, 1, 0);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(actCancel()));
grid->addWidget(btnGroupBox, 2, 0);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(grid);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Connect to server"));
@ -204,3 +220,8 @@ bool DeleteHighlightedItemWhenShiftDelPressedEventFilter::eventFilter(QObject *o
}
return QObject::eventFilter(obj, event);
}
void DlgConnect::actForgotPassword()
{
emit sigStartForgotPasswordRequest();
}

View file

@ -20,6 +20,8 @@ protected:
class DlgConnect : public QDialog {
Q_OBJECT
signals :
void sigStartForgotPasswordRequest();
public:
DlgConnect(QWidget *parent = 0);
QString getHost() const;
@ -32,12 +34,14 @@ private slots:
void passwordSaved(int state);
void previousHostSelected(bool state);
void newHostSelected(bool state);
void actForgotPassword();
private:
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel;
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit;
QCheckBox *savePasswordCheckBox, *autoConnectCheckBox;
QComboBox *previousHosts;
QRadioButton *newHostButton, *previousHostButton;
QPushButton *btnOk, *btnCancel, *btnForgotPassword;
};
#endif

View file

@ -0,0 +1,100 @@
#include <QLabel>
#include <QCheckBox>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QDebug>
#include "dlg_forgotpasswordchallenge.h"
#include "settingscache.h"
DlgForgotPasswordChallenge::DlgForgotPasswordChallenge(QWidget *parent)
: QDialog(parent)
{
QString lastfphost; QString lastfpport; QString lastfpplayername;
lastfphost = settingsCache->servers().getHostname("cockatrice.woogerworks.com");
lastfpport = settingsCache->servers().getPort("4747");
lastfpplayername = settingsCache->servers().getPlayerName("Player");
if (!settingsCache->servers().getFPHostname().isEmpty() && !settingsCache->servers().getFPPort().isEmpty() && !settingsCache->servers().getFPPlayerName().isEmpty()) {
lastfphost = settingsCache->servers().getFPHostname();
lastfpport = settingsCache->servers().getFPPort();
lastfpplayername = settingsCache->servers().getFPPlayerName();
}
if (settingsCache->servers().getFPHostname().isEmpty() && settingsCache->servers().getFPPort().isEmpty() && settingsCache->servers().getFPPlayerName().isEmpty())
{
QMessageBox::warning(this, tr("Forgot Password Challenge Warning"), tr("Oops, looks like something has gone wrong. Please restart the forgot password process by using the forgot password button on the connection screen."));
actCancel();
}
hostLabel = new QLabel(tr("&Host:"));
hostEdit = new QLineEdit(lastfphost);
hostLabel->setBuddy(hostEdit);
portLabel = new QLabel(tr("&Port:"));
portEdit = new QLineEdit(lastfpport);
portLabel->setBuddy(portEdit);
playernameLabel = new QLabel(tr("Player &name:"));
playernameEdit = new QLineEdit(lastfpplayername);
playernameLabel->setBuddy(playernameEdit);
emailLabel = new QLabel(tr("Email:"));
emailEdit = new QLineEdit();
emailLabel->setBuddy(emailLabel);
if (!settingsCache->servers().getFPHostname().isEmpty() && !settingsCache->servers().getFPPort().isEmpty() && !settingsCache->servers().getFPPlayerName().isEmpty()) {
hostLabel->hide();
hostEdit->hide();
portLabel->hide();
portEdit->hide();
playernameLabel->hide();
playernameEdit->hide();
}
QGridLayout *grid = new QGridLayout;
grid->addWidget(hostLabel, 0, 0);
grid->addWidget(hostEdit, 0, 1);
grid->addWidget(portLabel, 1, 0);
grid->addWidget(portEdit, 1, 1);
grid->addWidget(playernameLabel, 2, 0);
grid->addWidget(playernameEdit, 2, 1);
grid->addWidget(emailLabel, 3, 0);
grid->addWidget(emailEdit, 3, 1);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(actCancel()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(grid);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Forgot Password Challenge"));
setFixedHeight(sizeHint().height());
setMinimumWidth(300);
}
void DlgForgotPasswordChallenge::actOk()
{
if (emailEdit->text().isEmpty())
{
QMessageBox::critical(this, tr("Forgot Password Challenge Warning"), tr("The email address can't be empty."));
return;
}
settingsCache->servers().setFPHostName(hostEdit->text());
settingsCache->servers().setFPPort(portEdit->text());
settingsCache->servers().setFPPlayerName(playernameEdit->text());
accept();
}
void DlgForgotPasswordChallenge::actCancel()
{
reject();
}

View file

@ -0,0 +1,28 @@
#ifndef DLG_FORGOTPASSWORDCHALLENGE_H
#define DLG_FORGOTPASSWORDCHALLENGE_H
#include <QDialog>
#include <QLineEdit>
#include <QComboBox>
class QLabel;
class QPushButton;
class QCheckBox;
class DlgForgotPasswordChallenge : public QDialog {
Q_OBJECT
public:
DlgForgotPasswordChallenge(QWidget *parent = 0);
QString getHost() const { return hostEdit->text(); }
int getPort() const { return portEdit->text().toInt(); }
QString getPlayerName() const { return playernameEdit->text(); }
QString getEmail() const { return emailEdit->text(); }
private slots:
void actOk();
void actCancel();
private:
QLabel *hostLabel, *portLabel, *playernameLabel, *emailLabel;
QLineEdit *hostEdit, *portEdit, *playernameEdit, *emailEdit;
};
#endif

View file

@ -0,0 +1,79 @@
#include <QLabel>
#include <QCheckBox>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QDebug>
#include "dlg_forgotpasswordrequest.h"
#include "settingscache.h"
DlgForgotPasswordRequest::DlgForgotPasswordRequest(QWidget *parent)
: QDialog(parent)
{
QString lastfphost; QString lastfpport; QString lastfpplayername;
lastfphost = settingsCache->servers().getHostname("cockatrice.woogerworks.com");
lastfpport = settingsCache->servers().getPort("4747");
lastfpplayername = settingsCache->servers().getPlayerName("Player");
if (!settingsCache->servers().getFPHostname().isEmpty() && !settingsCache->servers().getFPPort().isEmpty() && !settingsCache->servers().getFPPlayerName().isEmpty()) {
lastfphost = settingsCache->servers().getFPHostname();
lastfpport = settingsCache->servers().getFPPort();
lastfpplayername = settingsCache->servers().getFPPlayerName();
}
hostLabel = new QLabel(tr("&Host:"));
hostEdit = new QLineEdit(lastfphost);
hostLabel->setBuddy(hostEdit);
portLabel = new QLabel(tr("&Port:"));
portEdit = new QLineEdit(lastfpport);
portLabel->setBuddy(portEdit);
playernameLabel = new QLabel(tr("Player &name:"));
playernameEdit = new QLineEdit(lastfpplayername);
playernameLabel->setBuddy(playernameEdit);
QGridLayout *grid = new QGridLayout;
grid->addWidget(hostLabel, 0, 0);
grid->addWidget(hostEdit, 0, 1);
grid->addWidget(portLabel, 1, 0);
grid->addWidget(portEdit, 1, 1);
grid->addWidget(playernameLabel, 2, 0);
grid->addWidget(playernameEdit, 2, 1);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(actCancel()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(grid);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Forgot Password Request"));
setFixedHeight(sizeHint().height());
setMinimumWidth(300);
}
void DlgForgotPasswordRequest::actOk()
{
if(playernameEdit->text().isEmpty())
{
QMessageBox::critical(this, tr("Forgot Password Request Warning"), tr("The player name can't be empty."));
return;
}
settingsCache->servers().setFPHostName(hostEdit->text());
settingsCache->servers().setFPPort(portEdit->text());
settingsCache->servers().setFPPlayerName(playernameEdit->text());
accept();
}
void DlgForgotPasswordRequest::actCancel()
{
reject();
}

View file

@ -0,0 +1,27 @@
#ifndef DLG_FORGOTPASSWORDREQUEST_H
#define DLG_FORGOTPASSWORDREQUEST_H
#include <QDialog>
#include <QLineEdit>
#include <QComboBox>
class QLabel;
class QPushButton;
class QCheckBox;
class DlgForgotPasswordRequest : public QDialog {
Q_OBJECT
public:
DlgForgotPasswordRequest(QWidget *parent = 0);
QString getHost() const { return hostEdit->text(); }
int getPort() const { return portEdit->text().toInt(); }
QString getPlayerName() const { return playernameEdit->text(); }
private slots:
void actOk();
void actCancel();
private:
QLabel *hostLabel, *portLabel, *playernameLabel;
QLineEdit *hostEdit, *portEdit, *playernameEdit;
};
#endif

View file

@ -0,0 +1,132 @@
#include <QLabel>
#include <QCheckBox>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QDebug>
#include "dlg_forgotpasswordreset.h"
#include "settingscache.h"
DlgForgotPasswordReset::DlgForgotPasswordReset(QWidget *parent)
: QDialog(parent)
{
QString lastfphost; QString lastfpport; QString lastfpplayername;
lastfphost = settingsCache->servers().getHostname("cockatrice.woogerworks.com");
lastfpport = settingsCache->servers().getPort("4747");
lastfpplayername = settingsCache->servers().getPlayerName("Player");
if (!settingsCache->servers().getFPHostname().isEmpty() && !settingsCache->servers().getFPPort().isEmpty() && !settingsCache->servers().getFPPlayerName().isEmpty()) {
lastfphost = settingsCache->servers().getFPHostname();
lastfpport = settingsCache->servers().getFPPort();
lastfpplayername = settingsCache->servers().getFPPlayerName();
}
if (settingsCache->servers().getFPHostname().isEmpty() && settingsCache->servers().getFPPort().isEmpty() && settingsCache->servers().getFPPlayerName().isEmpty())
{
QMessageBox::warning(this, tr("Forgot Password Reset Warning"), tr("Opps, looks like something has gone wrong. Please re-start the forgot password process by using the forgot password button on the connection screen."));
actCancel();
}
hostLabel = new QLabel(tr("&Host:"));
hostEdit = new QLineEdit(lastfphost);
hostLabel->setBuddy(hostEdit);
portLabel = new QLabel(tr("&Port:"));
portEdit = new QLineEdit(lastfpport);
portLabel->setBuddy(portEdit);
playernameLabel = new QLabel(tr("Player &name:"));
playernameEdit = new QLineEdit(lastfpplayername);
playernameLabel->setBuddy(playernameEdit);
tokenLabel = new QLabel(tr("Token:"));
tokenEdit = new QLineEdit();
tokenLabel->setBuddy(tokenLabel);
newpasswordLabel = new QLabel(tr("New Password:"));
newpasswordEdit = new QLineEdit();
newpasswordLabel->setBuddy(newpasswordEdit);
newpasswordEdit->setEchoMode(QLineEdit::Password);
newpasswordverifyLabel = new QLabel(tr("New Password:"));
newpasswordverifyEdit = new QLineEdit();
newpasswordverifyLabel->setBuddy(newpasswordEdit);
newpasswordverifyEdit->setEchoMode(QLineEdit::Password);
if (!settingsCache->servers().getFPHostname().isEmpty() && !settingsCache->servers().getFPPort().isEmpty() && !settingsCache->servers().getFPPlayerName().isEmpty()) {
hostLabel->hide();
hostEdit->hide();
portLabel->hide();
portEdit->hide();
playernameLabel->hide();
playernameEdit->hide();
}
QGridLayout *grid = new QGridLayout;
grid->addWidget(hostLabel, 0, 0);
grid->addWidget(hostEdit, 0, 1);
grid->addWidget(portLabel, 1, 0);
grid->addWidget(portEdit, 1, 1);
grid->addWidget(playernameLabel, 2, 0);
grid->addWidget(playernameEdit, 2, 1);
grid->addWidget(tokenLabel, 3, 0);
grid->addWidget(tokenEdit, 3, 1);
grid->addWidget(newpasswordLabel, 4, 0);
grid->addWidget(newpasswordEdit, 4, 1);
grid->addWidget(newpasswordverifyLabel, 5, 0);
grid->addWidget(newpasswordverifyEdit, 5, 1);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(actCancel()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(grid);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Forgot Password Reset"));
setFixedHeight(sizeHint().height());
setMinimumWidth(300);
}
void DlgForgotPasswordReset::actOk()
{
if(playernameEdit->text().isEmpty())
{
QMessageBox::critical(this, tr("Forgot Password Reset Warning"), tr("The player name can't be empty."));
return;
}
if (tokenEdit->text().isEmpty())
{
QMessageBox::critical(this, tr("Forgot Password Reset Warning"), tr("The token can't be empty."));
return;
}
if (newpasswordEdit->text().isEmpty())
{
QMessageBox::critical(this, tr("Forgot Password Reset Warning"), tr("The new password can't be empty."));
return;
}
if (newpasswordEdit->text() != newpasswordverifyEdit->text())
{
QMessageBox::critical(this, tr("Forgot Password Reset Warning"), tr("The passwords do not match."));
return;
}
settingsCache->servers().setFPHostName(hostEdit->text());
settingsCache->servers().setFPPort(portEdit->text());
settingsCache->servers().setFPPlayerName(playernameEdit->text());
accept();
}
void DlgForgotPasswordReset::actCancel()
{
reject();
}

View file

@ -0,0 +1,29 @@
#ifndef DLG_FORGOTPASSWORDRESET_H
#define DLG_FORGOTPASSWORDRESET_H
#include <QDialog>
#include <QLineEdit>
#include <QComboBox>
class QLabel;
class QPushButton;
class QCheckBox;
class DlgForgotPasswordReset : public QDialog {
Q_OBJECT
public:
DlgForgotPasswordReset(QWidget *parent = 0);
QString getHost() const { return hostEdit->text(); }
int getPort() const { return portEdit->text().toInt(); }
QString getPlayerName() const { return playernameEdit->text(); }
QString getToken() const { return tokenEdit->text(); }
QString getPassword() const { return newpasswordEdit->text(); }
private slots:
void actOk();
void actCancel();
private:
QLabel *hostLabel, *portLabel, *playernameLabel, *tokenLabel, *newpasswordLabel, *newpasswordverifyLabel;
QLineEdit *hostEdit, *portEdit, *playernameEdit, *tokenEdit, *newpasswordEdit, *newpasswordverifyEdit;
};
#endif

View file

@ -13,6 +13,7 @@
#include "pb/response_login.pb.h"
#include "pb/response_register.pb.h"
#include "pb/response_activate.pb.h"
#include "pb/response_forgotpasswordrequest.pb.h"
#include "pb/server_message.pb.h"
#include "pb/event_server_identification.pb.h"
#include "settingscache.h"
@ -43,6 +44,9 @@ RemoteClient::RemoteClient(QObject *parent)
connect(this, SIGNAL(sigDisconnectFromServer()), this, SLOT(doDisconnectFromServer()));
connect(this, SIGNAL(sigRegisterToServer(QString, unsigned int, QString, QString, QString, int, QString, QString)), this, SLOT(doRegisterToServer(QString, unsigned int, QString, QString, QString, int, QString, QString)));
connect(this, SIGNAL(sigActivateToServer(QString)), this, SLOT(doActivateToServer(QString)));
connect(this, SIGNAL(sigRequestForgotPasswordToServer(QString, unsigned int, QString)), this, SLOT(doRequestForgotPasswordToServer(QString, unsigned int, QString)));
connect(this, SIGNAL(sigSubmitForgotPasswordResetToServer(QString, unsigned int, QString, QString, QString)), this, SLOT(doSubmitForgotPasswordResetToServer(QString, unsigned int, QString, QString, QString)));
connect(this, SIGNAL(sigSubmitForgotPasswordChallengeToServer(QString, unsigned int, QString, QString)), this, SLOT(doSubmitForgotPasswordChallengeToServer(QString, unsigned int, QString, QString)));
}
RemoteClient::~RemoteClient()
@ -77,6 +81,42 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica
return;
}
if (getStatus() == StatusRequestingForgotPassword)
{
Command_ForgotPasswordRequest cmdForgotPasswordRequest;
cmdForgotPasswordRequest.set_user_name(userName.toStdString());
cmdForgotPasswordRequest.set_clientid(getSrvClientID(lastHostname).toStdString());
PendingCommand *pend = prepareSessionCommand(cmdForgotPasswordRequest);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(requestForgotPasswordResponse(Response)));
sendCommand(pend);
return;
}
if (getStatus() == StatusSubmitForgotPasswordReset)
{
Command_ForgotPasswordReset cmdForgotPasswordReset;
cmdForgotPasswordReset.set_user_name(userName.toStdString());
cmdForgotPasswordReset.set_clientid(getSrvClientID(lastHostname).toStdString());
cmdForgotPasswordReset.set_token(token.toStdString());
cmdForgotPasswordReset.set_new_password(password.toStdString());
PendingCommand *pend = prepareSessionCommand(cmdForgotPasswordReset);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(submitForgotPasswordResetResponse(Response)));
sendCommand(pend);
return;
}
if (getStatus() == StatusSubmitForgotPasswordChallenge)
{
Command_ForgotPasswordChallenge cmdForgotPasswordChallenge;
cmdForgotPasswordChallenge.set_user_name(userName.toStdString());
cmdForgotPasswordChallenge.set_clientid(getSrvClientID(lastHostname).toStdString());
cmdForgotPasswordChallenge.set_email(email.toStdString());
PendingCommand *pend = prepareSessionCommand(cmdForgotPasswordChallenge);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(submitForgotPasswordChallengeResponse(Response)));
sendCommand(pend);
return;
}
if(getStatus() == StatusRegistering)
{
Command_Register cmdRegister;
@ -415,4 +455,97 @@ void RemoteClient::clearNewClientFeatures()
}
}
settingsCache->setKnownMissingFeatures(newKnownMissingFeatures);
}
void RemoteClient::requestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName)
{
emit sigRequestForgotPasswordToServer(hostname, port, _userName);
}
void RemoteClient::submitForgotPasswordResetToServer(const QString & hostname, unsigned int port, const QString & _userName, const QString & _token, const QString & _newpassword)
{
emit sigSubmitForgotPasswordResetToServer(hostname, port, _userName, _token, _newpassword);
}
void RemoteClient::doRequestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName)
{
doDisconnectFromServer();
userName = _userName;
lastHostname = hostname;
lastPort = port;
socket->connectToHost(lastHostname, lastPort);
setStatus(StatusRequestingForgotPassword);
}
void RemoteClient::requestForgotPasswordResponse(const Response &response)
{
const Response_ForgotPasswordRequest &resp = response.GetExtension(Response_ForgotPasswordRequest::ext);
if (response.response_code() == Response::RespOk)
{
if (resp.challenge_email()) {
emit sigPromptForForgotPasswordChallenge();
}
else
emit sigPromptForForgotPasswordReset();
}
else
emit sigForgotPasswordError();
doDisconnectFromServer();
}
void RemoteClient::doSubmitForgotPasswordResetToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_token, const QString &_newpassword)
{
doDisconnectFromServer();
userName = _userName;
lastHostname = hostname;
lastPort = port;
token = _token;
password = _newpassword;
socket->connectToHost(lastHostname, lastPort);
setStatus(StatusSubmitForgotPasswordReset);
}
void RemoteClient::submitForgotPasswordResetResponse(const Response &response)
{
if (response.response_code() == Response::RespOk) {
emit sigForgotPasswordSuccess();
} else
emit sigForgotPasswordError();
doDisconnectFromServer();
}
void RemoteClient::submitForgotPasswordChallengeToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_email)
{
emit sigSubmitForgotPasswordChallengeToServer(hostname, port, _userName, _email);
}
void RemoteClient::doSubmitForgotPasswordChallengeToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_email)
{
doDisconnectFromServer();
userName = _userName;
lastHostname = hostname;
lastPort = port;
email = _email;
socket->connectToHost(lastHostname, lastPort);
setStatus(StatusSubmitForgotPasswordChallenge);
}
void RemoteClient::submitForgotPasswordChallengeResponse(const Response &response)
{
if (response.response_code() == Response::RespOk) {
emit sigPromptForForgotPasswordReset();
}
else
emit sigForgotPasswordError();
doDisconnectFromServer();
}

View file

@ -22,6 +22,13 @@ signals:
void sigActivateToServer(const QString &_token);
void sigDisconnectFromServer();
void notifyUserAboutUpdate();
void sigRequestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName);
void sigForgotPasswordSuccess();
void sigForgotPasswordError();
void sigPromptForForgotPasswordReset();
void sigSubmitForgotPasswordResetToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_token, const QString &_newpassword);
void sigPromptForForgotPasswordChallenge();
void sigSubmitForgotPasswordChallengeToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_email);
private slots:
void slotConnected();
void readData();
@ -37,7 +44,12 @@ private slots:
void doLogin();
void doDisconnectFromServer();
void doActivateToServer(const QString &_token);
void doRequestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName);
void requestForgotPasswordResponse(const Response &response);
void doSubmitForgotPasswordResetToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_token, const QString &_newpassword);
void submitForgotPasswordResetResponse(const Response &response);
void doSubmitForgotPasswordChallengeToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_email);
void submitForgotPasswordChallengeResponse(const Response &response);
private:
static const int maxTimeout = 10;
int timeRunning, lastDataReceived;
@ -64,6 +76,9 @@ public:
void registerToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const int _gender, const QString &_country, const QString &_realname);
void activateToServer(const QString &_token);
void disconnectFromServer();
void requestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName);
void submitForgotPasswordResetToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_token, const QString &_newpassword);
void submitForgotPasswordChallengeToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_email);
};
#endif

View file

@ -100,3 +100,36 @@ int ServersSettings::getAutoConnect()
QVariant autoconnect = getValue("auto_connect", "server");
return autoconnect == QVariant() ? 0 : autoconnect.toInt();
}
void ServersSettings::setFPHostName(QString hostname)
{
setValue(hostname, "fphostname", "server");
}
QString ServersSettings::getFPHostname(QString defaultHost)
{
QVariant hostname = getValue("fphostname", "server");
return hostname == QVariant() ? defaultHost : hostname.toString();
}
void ServersSettings::setFPPort(QString port)
{
setValue(port, "fpport", "server");
}
QString ServersSettings::getFPPort(QString defaultPort)
{
QVariant port = getValue("fpport", "server");
return port == QVariant() ? defaultPort : port.toString();
}
void ServersSettings::setFPPlayerName(QString playerName)
{
setValue(playerName, "fpplayername", "server");
}
QString ServersSettings::getFPPlayerName(QString defaultName)
{
QVariant name = getValue("fpplayername", "server");
return name == QVariant() ? defaultName : name.toString();
}

View file

@ -16,6 +16,9 @@ public:
QString getHostname(QString defaultHost = "");
QString getPort(QString defaultPort = "");
QString getPlayerName(QString defaultName = "");
QString getFPHostname(QString defaultHost = "");
QString getFPPort(QString defaultPort = "");
QString getFPPlayerName(QString defaultName = "");
QString getPassword();
int getSavePassword();
int getAutoConnect();
@ -29,6 +32,9 @@ public:
void setPassword(QString password);
void setSavePassword(int save);
void setAutoConnect(int autoconnect);
void setFPHostName(QString hostname);
void setFPPort(QString port);
void setFPPlayerName(QString playerName);
signals:
public slots:

View file

@ -63,6 +63,9 @@ void SettingsCache::translateLegacySettings()
servers().setPassword(legacySetting.value("password").toString());
servers().setSavePassword(legacySetting.value("save_password").toInt());
servers().setAutoConnect(legacySetting.value("auto_connect").toInt());
servers().setFPHostName(legacySetting.value("fphostname").toString());
servers().setFPPort(legacySetting.value("fpport").toString());
servers().setFPPlayerName(legacySetting.value("fpplayername").toString());
usedKeys.append(legacySetting.allKeys());
QStringList allKeysServer = legacySetting.allKeys();
for (int i = 0; i < allKeysServer.size(); ++i) {

View file

@ -36,6 +36,9 @@
#include "main.h"
#include "window_main.h"
#include "dlg_connect.h"
#include "dlg_forgotpasswordrequest.h"
#include "dlg_forgotpasswordreset.h"
#include "dlg_forgotpasswordchallenge.h"
#include "dlg_register.h"
#include "dlg_settings.h"
#include "dlg_update.h"
@ -166,9 +169,10 @@ void MainWindow::activateAccepted()
void MainWindow::actConnect()
{
DlgConnect dlg(this);
if (dlg.exec())
client->connectToServer(dlg.getHost(), dlg.getPort(), dlg.getPlayerName(), dlg.getPassword());
DlgConnect *dlg = new DlgConnect(this);
connect(dlg, SIGNAL(sigStartForgotPasswordRequest()), this, SLOT(actForgotPasswordRequest()));
if (dlg->exec())
client->connectToServer(dlg->getHost(), dlg->getPort(), dlg->getPlayerName(), dlg->getPassword());
}
void MainWindow::actRegister()
@ -506,6 +510,9 @@ void MainWindow::setClientStatusTitle()
case StatusDisconnected: setWindowTitle(appName + " - " + tr("Disconnected")); break;
case StatusLoggingIn: setWindowTitle(appName + " - " + tr("Connected, logging in at %1").arg(client->peerName())); break;
case StatusLoggedIn: setWindowTitle(client->getUserName() + "@" + client->peerName()); break;
case StatusRequestingForgotPassword: setWindowTitle(appName + " - " + tr("Requesting forgot password to %1 as %2...").arg(client->peerName()).arg(client->getUserName())); break;
case StatusSubmitForgotPasswordChallenge: setWindowTitle(appName + " - " + tr("Requesting forgot password to %1 as %2...").arg(client->peerName()).arg(client->getUserName())); break;
case StatusSubmitForgotPasswordReset: setWindowTitle(appName + " - " + tr("Requesting forgot password to %1 as %2...").arg(client->peerName()).arg(client->getUserName())); break;
default: setWindowTitle(appName);
}
}
@ -666,6 +673,10 @@ MainWindow::MainWindow(QWidget *parent)
connect(client, SIGNAL(registerError(Response::ResponseCode, QString, quint32)), this, SLOT(registerError(Response::ResponseCode, QString, quint32)));
connect(client, SIGNAL(activateAccepted()), this, SLOT(activateAccepted()));
connect(client, SIGNAL(activateError()), this, SLOT(activateError()));
connect(client, SIGNAL(sigForgotPasswordSuccess()), this, SLOT(forgotPasswordSuccess()));
connect(client, SIGNAL(sigForgotPasswordError()), this, SLOT(forgotPasswordError()));
connect(client, SIGNAL(sigPromptForForgotPasswordReset()), this, SLOT(promptForgotPasswordReset()));
connect(client, SIGNAL(sigPromptForForgotPasswordChallenge()), this, SLOT(promptForgotPasswordChallenge()));
clientThread = new QThread(this);
client->moveToThread(clientThread);
@ -734,6 +745,13 @@ void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) {
}
}
void MainWindow::promptForgotPasswordChallenge()
{
DlgForgotPasswordChallenge dlg(this);
if (dlg.exec())
client->submitForgotPasswordChallengeToServer(dlg.getHost(),dlg.getPort(),dlg.getPlayerName(),dlg.getEmail());
}
void MainWindow::createTrayActions() {
closeAction = new QAction(tr("&Exit"), this);
@ -1054,3 +1072,34 @@ void MainWindow::actEditTokens()
dlg.exec();
db->saveCustomTokensToFile();
}
void MainWindow::actForgotPasswordRequest()
{
DlgForgotPasswordRequest dlg(this);
if (dlg.exec())
client->requestForgotPasswordToServer(dlg.getHost(), dlg.getPort(), dlg.getPlayerName());
}
void MainWindow::forgotPasswordSuccess()
{
QMessageBox::information(this, tr("Forgot Password"), tr("Your password has been reset successfully, you now may log in using the new credentials."));
settingsCache->servers().setFPHostName("");
settingsCache->servers().setFPPort("");
settingsCache->servers().setFPPlayerName("");
}
void MainWindow::forgotPasswordError()
{
QMessageBox::warning(this, tr("Forgot Password"), tr("Failed to reset user account password, please contact the server operator to reset your password."));
settingsCache->servers().setFPHostName("");
settingsCache->servers().setFPPort("");
settingsCache->servers().setFPPlayerName("");
}
void MainWindow::promptForgotPasswordReset()
{
QMessageBox::information(this, tr("Forgot Password"), tr("Activation request received, please check your email for an activation token."));
DlgForgotPasswordReset dlg(this);
if (dlg.exec())
client->submitForgotPasswordResetToServer(dlg.getHost(), dlg.getPort(), dlg.getPlayerName(), dlg.getToken(), dlg.getPassword());
}

View file

@ -67,13 +67,15 @@ private slots:
void actRegister();
void actSettings();
void actExit();
void actForgotPasswordRequest();
void actAbout();
void actUpdate();
void actViewLog();
void forgotPasswordSuccess();
void forgotPasswordError();
void promptForgotPasswordReset();
void iconActivated(QSystemTrayIcon::ActivationReason reason);
void promptForgotPasswordChallenge();
void showWindowIfHidden();
void actCheckCardUpdates();