Add login failed lock.
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QtWidgets/QLabel>
|
#include <QtWidgets/QLabel>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "event/EventCenter.h"
|
#include "event/EventCenter.h"
|
||||||
#include "dialogs/DialogManager.h"
|
#include "dialogs/DialogManager.h"
|
||||||
@@ -13,6 +14,12 @@
|
|||||||
#include "json/jsonobject.h"
|
#include "json/jsonobject.h"
|
||||||
#include "components/ULineEdit.h"
|
#include "components/ULineEdit.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const int LOGIN_LOCK_COUNT = 3;
|
||||||
|
const int LOGIN_LOCK_MINUTIES = 1;
|
||||||
|
}
|
||||||
|
|
||||||
LoginDialog::LoginDialog(QWidget* aParent)
|
LoginDialog::LoginDialog(QWidget* aParent)
|
||||||
: QDialog(aParent)
|
: QDialog(aParent)
|
||||||
, mVMainLayout(new QVBoxLayout(this))
|
, mVMainLayout(new QVBoxLayout(this))
|
||||||
@@ -27,11 +34,15 @@ LoginDialog::LoginDialog(QWidget* aParent)
|
|||||||
, mErrorMessage(new QLabel(this))
|
, mErrorMessage(new QLabel(this))
|
||||||
, mIsRunning(false)
|
, mIsRunning(false)
|
||||||
, mHideClickCount(0)
|
, mHideClickCount(0)
|
||||||
|
, mLoginFailedCount(0)
|
||||||
|
, mLoginFailedTimer(new QTimer(this))
|
||||||
{
|
{
|
||||||
initializeAllWidget();
|
initializeAllWidget();
|
||||||
setWindowFlags(windowFlags() | Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint| Qt::BypassWindowManagerHint);
|
setWindowFlags(windowFlags() | Qt::Window | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint| Qt::BypassWindowManagerHint);
|
||||||
setGeometry(QApplication::desktop()->screenGeometry());
|
setGeometry(QApplication::desktop()->screenGeometry());
|
||||||
mAccountEdit->setText(JsonObject::Instance()->defaultUser());
|
mAccountEdit->setText(JsonObject::Instance()->defaultUser());
|
||||||
|
mLoginFailedTimer->setSingleShot(true);
|
||||||
|
connect(mLoginFailedTimer, &QTimer::timeout, this, &LoginDialog::resetLoginFailedCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginDialog::~LoginDialog()
|
LoginDialog::~LoginDialog()
|
||||||
@@ -134,7 +145,6 @@ void LoginDialog::initializeLoginButton()
|
|||||||
void LoginDialog::initializeErrorMessage()
|
void LoginDialog::initializeErrorMessage()
|
||||||
{
|
{
|
||||||
mErrorMessage->setObjectName("warn");
|
mErrorMessage->setObjectName("warn");
|
||||||
mErrorMessage->setText("Login failed, username or password error!");
|
|
||||||
mErrorMessage->setVisible(false);
|
mErrorMessage->setVisible(false);
|
||||||
mDialogContentsLayout->addWidget(mErrorMessage, 0, Qt::AlignCenter);
|
mDialogContentsLayout->addWidget(mErrorMessage, 0, Qt::AlignCenter);
|
||||||
}
|
}
|
||||||
@@ -148,6 +158,13 @@ void LoginDialog::clearInputData()
|
|||||||
|
|
||||||
void LoginDialog::doLogin()
|
void LoginDialog::doLogin()
|
||||||
{
|
{
|
||||||
|
if(mLoginFailedCount >= LOGIN_LOCK_COUNT)
|
||||||
|
{
|
||||||
|
mErrorMessage->setText(QString(tr("Login locked. Please retry after %1 minutes.")).arg(LOGIN_LOCK_MINUTIES));
|
||||||
|
mErrorMessage->setVisible(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QString strUserCode = mAccountEdit->text();
|
QString strUserCode = mAccountEdit->text();
|
||||||
QString strPassWord = mPasswordEdit->text();
|
QString strPassWord = mPasswordEdit->text();
|
||||||
|
|
||||||
@@ -157,6 +174,7 @@ void LoginDialog::doLogin()
|
|||||||
QString encryptPwd = User::getEncryptedPassword(strPassWord);
|
QString encryptPwd = User::getEncryptedPassword(strPassWord);
|
||||||
if (User::QueryUser(strUserCode, encryptPwd))
|
if (User::QueryUser(strUserCode, encryptPwd))
|
||||||
{
|
{
|
||||||
|
resetLoginFailedCount();
|
||||||
mErrorMessage->setVisible(false);
|
mErrorMessage->setVisible(false);
|
||||||
accept();
|
accept();
|
||||||
LOG_USER_OPERATION("Login Sucessful");
|
LOG_USER_OPERATION("Login Sucessful");
|
||||||
@@ -166,7 +184,13 @@ void LoginDialog::doLogin()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_USER_OPERATION(QString("Login Failed, User Name: %1").arg(strUserCode));
|
LOG_USER_OPERATION(QString("Login Failed, User Name: %1").arg(strUserCode));
|
||||||
|
++mLoginFailedCount;
|
||||||
|
mErrorMessage->setText(QString(tr("Login failed, username or password error! Remaining retries: %1")).arg(LOGIN_LOCK_COUNT - mLoginFailedCount));
|
||||||
mErrorMessage->setVisible(true);
|
mErrorMessage->setVisible(true);
|
||||||
|
if(LOGIN_LOCK_COUNT - mLoginFailedCount == 0)
|
||||||
|
{
|
||||||
|
mLoginFailedTimer->start(LOGIN_LOCK_MINUTIES * 60000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,5 +222,8 @@ void LoginDialog::showEvent(QShowEvent* event)
|
|||||||
emit loginDialogShown();
|
emit loginDialogShown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoginDialog::resetLoginFailedCount()
|
||||||
|
{
|
||||||
|
mLoginFailedCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ signals:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void doLogin();
|
void doLogin();
|
||||||
|
void resetLoginFailedCount();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initializeAllWidget();
|
void initializeAllWidget();
|
||||||
@@ -56,6 +57,8 @@ private:
|
|||||||
QLabel* mErrorMessage;
|
QLabel* mErrorMessage;
|
||||||
bool mIsRunning;
|
bool mIsRunning;
|
||||||
int mHideClickCount;
|
int mHideClickCount;
|
||||||
|
int mLoginFailedCount;
|
||||||
|
QTimer* mLoginFailedTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOGINDIALOG_H
|
#endif // LOGINDIALOG_H
|
||||||
|
|||||||
Reference in New Issue
Block a user