Refactor dialog package.

This commit is contained in:
Krad
2022-06-13 11:21:44 +08:00
parent 9a233251dc
commit 69a506ff94
27 changed files with 870 additions and 828 deletions

View File

@@ -9,82 +9,88 @@
#include "log/UserOperationLog.h"
#include "ChangePasswordFormDialog.h"
ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget* parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
QVBoxLayout* layout = new QVBoxLayout(formWidget);
layout->setSpacing(10);
// add title
QLabel* lbl_title = new QLabel(this);
lbl_title->setAlignment(Qt::AlignCenter);
lbl_title->setText(tr("Change Password"));
lbl_title->setObjectName("title");
layout->addWidget(lbl_title);
//add old password
QLabel* lbl_Old = new QLabel(this);
lbl_Old->setText(tr("Current Password"));
pwd = new QLineEdit(this);
pwd->setEchoMode(QLineEdit::Password);
layout->addWidget(lbl_Old);
layout->addWidget(pwd);
QLabel* lbl_endline1 = new QLabel(this);
lbl_endline1->setObjectName("endline");
layout->addWidget(lbl_endline1);
//add new password
QLabel* lbl_New = new QLabel(this);
lbl_New->setText(tr("New Password"));
new_pwd = new QLineEdit(this);
new_pwd->setEchoMode(QLineEdit::Password);
layout->addWidget(lbl_New);
layout->addWidget(new_pwd);
QLabel* lbl_endline2 = new QLabel(this);
lbl_endline2->setObjectName("endline");
layout->addWidget(lbl_endline2);
//add confirm password
QLabel* lbl_Confirm = new QLabel(this);
lbl_Confirm->setText(tr("Confirm Password"));
confirm_pwd = new QLineEdit(this);
confirm_pwd->setEchoMode(QLineEdit::Password);
layout->addWidget(lbl_Confirm);
layout->addWidget(confirm_pwd);
QLabel* lbl_endline3 = new QLabel(this);
lbl_endline3->setObjectName("endline");
layout->addWidget(lbl_endline3);
lbl_error = new QLabel(this);
lbl_error->setObjectName("warn");
layout->addWidget(lbl_error);
ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget* parent, Qt::WindowFlags f)
: GUIFormBaseDialog(parent, f)
, mLEPasswd(new QLineEdit(this))
, mLENewPasswd(new QLineEdit(this))
, mLEConfirmPasswd(new QLineEdit(this))
, mLblError(new QLabel(this))
{
initLayout();
}
ChangePasswordFormDialog::~ChangePasswordFormDialog() {
void ChangePasswordFormDialog::initLayout() {
auto layout = new QVBoxLayout(mFormWidget);
layout->setSpacing(10);
// add title
auto lblTitle = new QLabel(this);
lblTitle->setAlignment(Qt::AlignCenter);
lblTitle->setText(tr("Change Password"));
lblTitle->setObjectName("title");
layout->addWidget(lblTitle);
//add old password
auto lblOld = new QLabel(this);
lblOld->setText(tr("Current Password"));
mLEPasswd->setEchoMode(QLineEdit::Password);
layout->addWidget(lblOld);
layout->addWidget(mLEPasswd);
auto lblEndline1 = new QLabel(this);
lblEndline1->setObjectName("endline");
layout->addWidget(lblEndline1);
//add new password
auto lblNewPasswd = new QLabel(this);
lblNewPasswd->setText(tr("New Password"));
mLENewPasswd->setEchoMode(QLineEdit::Password);
layout->addWidget(lblNewPasswd);
layout->addWidget(mLENewPasswd);
auto lblEndline2 = new QLabel(this);
lblEndline2->setObjectName("endline");
layout->addWidget(lblEndline2);
//add confirm password
auto lblConfirm = new QLabel(this);
lblConfirm->setText(tr("Confirm Password"));
mLEConfirmPasswd->setEchoMode(QLineEdit::Password);
layout->addWidget(lblConfirm);
layout->addWidget(mLEConfirmPasswd);
auto lblEndline3 = new QLabel(this);
lblEndline3->setObjectName("endline");
layout->addWidget(lblEndline3);
mLblError->setObjectName("warn");
layout->addWidget(mLblError);
}
bool ChangePasswordFormDialog::updateReferenceData() {
if (pwd->text().isEmpty())
if (mLEPasswd->text().isEmpty())
{
lbl_error->setText(tr("Please enter your old password!"));
mLblError->setText(tr("Please enter your old password!"));
return false;
}
if (new_pwd->text().length() < 6) {
lbl_error->setText(tr("New password should at least 6 characters!"));
if (mLENewPasswd->text().length() < 6) {
mLblError->setText(tr("New password should at least 6 characters!"));
return false;
}
QString encryptPwd = User::getEncryptedPassword(pwd->text());
QString encryptPwd = User::getEncryptedPassword(mLEPasswd->text());
if (encryptPwd != User::Current()->getPassword())
{
lbl_error->setText(tr("Wrong password!"));
mLblError->setText(tr("Wrong password!"));
return false;
}
if (new_pwd->text() != confirm_pwd->text())
if (mLENewPasswd->text() != mLEConfirmPasswd->text())
{
lbl_error->setText(tr("Your new password does not match!"));
mLblError->setText(tr("Your new password does not match!"));
return false;
}
User::Current()->setPassword(User::getEncryptedPassword(new_pwd->text()));
User::Current()->setPassword(User::getEncryptedPassword(mLENewPasswd->text()));
if (!User::Current()->submitChange()) {
lbl_error->setText(tr("Database update error!"));
mLblError->setText(tr("Database update error!"));
User::Current()->restorePassword(encryptPwd);
return false;
}