Reset account password
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "models/User.h"
|
||||
#include "components/SlidePickerBox.h"
|
||||
#include "SelectDialog.h"
|
||||
#include "AlertDialog.h"
|
||||
|
||||
AccountFormDialog::AccountFormDialog(QWidget *parent,AccountEditMode mode, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
||||
m_mode = mode;
|
||||
@@ -119,6 +120,29 @@ AccountFormDialog::AccountFormDialog(QWidget *parent,AccountEditMode mode, Qt::W
|
||||
btn_Role->setText("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,[=](){
|
||||
SelectDialog selectDialog(this);
|
||||
selectDialog.setAvailableDates(User::getAllRoleName());
|
||||
@@ -199,7 +223,7 @@ bool AccountFormDialog::updateReferenceData() {
|
||||
user.setUserName(m_NewUserName);
|
||||
}
|
||||
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();
|
||||
if (ret) {
|
||||
LOG_USER_OPERATION(AdminChangeAcountInformation);
|
||||
@@ -238,23 +262,23 @@ bool AccountFormDialog::updateReferenceData() {
|
||||
refmodel->insertRow(0);
|
||||
refmodel->setData(refmodel->index(0, 0), QUuid::createUuid().toString());
|
||||
refmodel->setData(refmodel->index(0, 1), le_UserCode->text());
|
||||
#define USER_READONLY_PROPERTY(name) name,
|
||||
#define USER_PROPERTY(name)\
|
||||
#define USER_READONLY_PROPERTY(name) name,
|
||||
#define USER_PROPERTY(name)\
|
||||
USER_READONLY_PROPERTY(name)
|
||||
|
||||
enum user_index {
|
||||
USER_PROPERTIES_MACRO()
|
||||
};
|
||||
#undef USER_READONLY_PROPERTY
|
||||
#undef USER_PROPERTY
|
||||
#undef USER_READONLY_PROPERTY
|
||||
#undef USER_PROPERTY
|
||||
|
||||
#define USER_READONLY_PROPERTY(name)
|
||||
#define USER_PROPERTY(name)\
|
||||
#define USER_READONLY_PROPERTY(name)
|
||||
#define USER_PROPERTY(name)\
|
||||
USER_READONLY_PROPERTY(name)\
|
||||
refmodel->setData(refmodel->index(0, name),user.get##name());
|
||||
USER_PROPERTIES_MACRO()
|
||||
#undef USER_READONLY_PROPERTY
|
||||
#undef USER_PROPERTY
|
||||
#undef USER_READONLY_PROPERTY
|
||||
#undef USER_PROPERTY
|
||||
|
||||
if (refmodel->submit()) {
|
||||
hideWarn();
|
||||
|
||||
@@ -21,16 +21,19 @@ bool User::submitChange() {
|
||||
static QString updateSQL = "update Account %1 %2";
|
||||
QString setString = "";
|
||||
QMap<QString,QVariant> params;
|
||||
bool needUpdate = false;
|
||||
#define USER_READONLY_PROPERTY(name)
|
||||
#define USER_PROPERTY(name)\
|
||||
USER_READONLY_PROPERTY(name)\
|
||||
if (mf_##name){\
|
||||
setString += QString((!setString.isEmpty())?", ":"") + QString(QString("set %1=%2").arg(#name, ":" #name));\
|
||||
params[":" #name] = m_##name;\
|
||||
needUpdate = true;\
|
||||
}
|
||||
USER_PROPERTIES_MACRO()
|
||||
#undef USER_PROPERTY
|
||||
#undef USER_READONLY_PROPERTY
|
||||
if (!needUpdate) return true;
|
||||
QString whereString = " where "+getIndexName()+" = '"+getIndexValue()+"'";
|
||||
bool result = 1 == SQLHelper::ExecuteNoQuery(updateSQL.arg(setString,whereString),¶ms);
|
||||
if (result)
|
||||
@@ -170,6 +173,12 @@ bool User::insertUser(QString UserCode, User &user) {
|
||||
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 isAdmin();
|
||||
bool resetPassword();
|
||||
static QString getRoleName(QString RoleID);
|
||||
static QString getRoleID(QString RoleName);
|
||||
static QStringList getAllRoleName();
|
||||
|
||||
Reference in New Issue
Block a user