Reset account password
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
#include "models/User.h"
|
#include "models/User.h"
|
||||||
#include "components/SlidePickerBox.h"
|
#include "components/SlidePickerBox.h"
|
||||||
#include "SelectDialog.h"
|
#include "SelectDialog.h"
|
||||||
|
#include "AlertDialog.h"
|
||||||
|
|
||||||
AccountFormDialog::AccountFormDialog(QWidget *parent,AccountEditMode mode, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
AccountFormDialog::AccountFormDialog(QWidget *parent,AccountEditMode mode, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
||||||
m_mode = mode;
|
m_mode = mode;
|
||||||
@@ -119,6 +120,29 @@ AccountFormDialog::AccountFormDialog(QWidget *parent,AccountEditMode mode, Qt::W
|
|||||||
btn_Role->setText("doctor");
|
btn_Role->setText("doctor");
|
||||||
m_RoleID = User::getRoleID("doctor");
|
m_RoleID = User::getRoleID("doctor");
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
connect(btn_Pwd,&QAbstractButton::clicked,[=](){
|
||||||
|
AlertDialog dialog(this);
|
||||||
|
dialog.setButtonMode(OkAndCancel);
|
||||||
|
dialog.setWindowModality(Qt::WindowModal);
|
||||||
|
dialog.setAlertMessage(tr("Reset password to \"123456\" ?"));
|
||||||
|
if (dialog.exec() == Accepted)
|
||||||
|
{
|
||||||
|
User user;
|
||||||
|
dialog.setButtonMode(OkOnly);
|
||||||
|
if (!User::getUser(m_UserID, user)) {
|
||||||
|
dialog.setAlertMessage(tr("Inner error, can't find reference user!"));
|
||||||
|
dialog.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!user.resetPassword())
|
||||||
|
{
|
||||||
|
dialog.setAlertMessage(tr("Submit change to database fail!"));
|
||||||
|
dialog.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
connect(btn_Role,&QAbstractButton::clicked,[=](){
|
connect(btn_Role,&QAbstractButton::clicked,[=](){
|
||||||
SelectDialog selectDialog(this);
|
SelectDialog selectDialog(this);
|
||||||
selectDialog.setAvailableDates(User::getAllRoleName());
|
selectDialog.setAvailableDates(User::getAllRoleName());
|
||||||
@@ -199,7 +223,7 @@ bool AccountFormDialog::updateReferenceData() {
|
|||||||
user.setUserName(m_NewUserName);
|
user.setUserName(m_NewUserName);
|
||||||
}
|
}
|
||||||
if (this->roleChanged) user.setRoleID(m_RoleID);
|
if (this->roleChanged) user.setRoleID(m_RoleID);
|
||||||
if (!this->commentChanged) user.setUserName(le_Comment->text());
|
if (!this->commentChanged) user.setComment(le_Comment->text());
|
||||||
bool ret = user.submitChange();
|
bool ret = user.submitChange();
|
||||||
if (ret) {
|
if (ret) {
|
||||||
LOG_USER_OPERATION(AdminChangeAcountInformation);
|
LOG_USER_OPERATION(AdminChangeAcountInformation);
|
||||||
|
|||||||
@@ -21,16 +21,19 @@ bool User::submitChange() {
|
|||||||
static QString updateSQL = "update Account %1 %2";
|
static QString updateSQL = "update Account %1 %2";
|
||||||
QString setString = "";
|
QString setString = "";
|
||||||
QMap<QString,QVariant> params;
|
QMap<QString,QVariant> params;
|
||||||
|
bool needUpdate = false;
|
||||||
#define USER_READONLY_PROPERTY(name)
|
#define USER_READONLY_PROPERTY(name)
|
||||||
#define USER_PROPERTY(name)\
|
#define USER_PROPERTY(name)\
|
||||||
USER_READONLY_PROPERTY(name)\
|
USER_READONLY_PROPERTY(name)\
|
||||||
if (mf_##name){\
|
if (mf_##name){\
|
||||||
setString += QString((!setString.isEmpty())?", ":"") + QString(QString("set %1=%2").arg(#name, ":" #name));\
|
setString += QString((!setString.isEmpty())?", ":"") + QString(QString("set %1=%2").arg(#name, ":" #name));\
|
||||||
params[":" #name] = m_##name;\
|
params[":" #name] = m_##name;\
|
||||||
|
needUpdate = true;\
|
||||||
}
|
}
|
||||||
USER_PROPERTIES_MACRO()
|
USER_PROPERTIES_MACRO()
|
||||||
#undef USER_PROPERTY
|
#undef USER_PROPERTY
|
||||||
#undef USER_READONLY_PROPERTY
|
#undef USER_READONLY_PROPERTY
|
||||||
|
if (!needUpdate) return true;
|
||||||
QString whereString = " where "+getIndexName()+" = '"+getIndexValue()+"'";
|
QString whereString = " where "+getIndexName()+" = '"+getIndexValue()+"'";
|
||||||
bool result = 1 == SQLHelper::ExecuteNoQuery(updateSQL.arg(setString,whereString),¶ms);
|
bool result = 1 == SQLHelper::ExecuteNoQuery(updateSQL.arg(setString,whereString),¶ms);
|
||||||
if (result)
|
if (result)
|
||||||
@@ -170,6 +173,12 @@ bool User::insertUser(QString UserCode, User &user) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool User::resetPassword() {
|
||||||
|
static QString defaultPwd = User::getEncryptedPassword("123456");
|
||||||
|
this->setPassword(defaultPwd);
|
||||||
|
return this->submitChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ public:
|
|||||||
}
|
}
|
||||||
bool submitChange();
|
bool submitChange();
|
||||||
bool isAdmin();
|
bool isAdmin();
|
||||||
|
bool resetPassword();
|
||||||
static QString getRoleName(QString RoleID);
|
static QString getRoleName(QString RoleID);
|
||||||
static QString getRoleID(QString RoleName);
|
static QString getRoleID(QString RoleName);
|
||||||
static QStringList getAllRoleName();
|
static QStringList getAllRoleName();
|
||||||
|
|||||||
Reference in New Issue
Block a user