diff --git a/loginwin.cpp b/loginwin.cpp index 47b22ef..de928a7 100644 --- a/loginwin.cpp +++ b/loginwin.cpp @@ -85,8 +85,8 @@ loginwin::loginwin(QWidget* parent):ElaWidget(parent) loginWinArea->addLayout(srBtnArea,Qt::AlignCenter); area->setLayout(loginWinArea); - db = new DatabaseManager(this); // 创建数据库管理器实例 - db->initializeDatabase(); // 初始化数据库 + //db = new DatabaseManager(this); // 创建数据库管理器实例 + //db->initializeDatabase(); // 初始化数据库 connect(resetBtn,&ElaPushButton::clicked,this, &loginwin::on_resetBtn_clicked); connect(signinBtn,&ElaPushButton::clicked,this, &loginwin::on_signinBtn_clicked); @@ -129,7 +129,7 @@ void loginwin::on_loginBtn_clicked() if(loginuser.login()){ QMessageBox::information(this, "成功","登录成功"); emit on_login_complete(loginuser); - db->insertUser(accountLine->text(),passwordLine->text()); + //db->insertUser(accountLine->text(),passwordLine->text()); this->close(); } else diff --git a/mainwindow.cpp b/mainwindow.cpp index 3f5df79..d037924 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -21,6 +21,10 @@ MainWindow::MainWindow(QWidget *parent) : ElaWindow(parent) { + + db = new DatabaseManager(this); // 创建数据库管理器实例 + db->initializeDatabase(); // 初始化数据库 + // ElaApplication::getInstance()->setThemeMode(ElaApplicationType::Dark); // setIsNavigationBarEnable(false); // setNavigationBarDisplayMode(ElaNavigationType::Minimal); @@ -148,6 +152,7 @@ void MainWindow::onUserLoggedIn(User user) setUserInfoCardTitle(user.getUsername()); setUserInfoCardSubTitle(user.getEmail()); CurrentUser=new User(user); + db->insertUser(user.getEmail(),user.gethashedPassword()); } void MainWindow::onCloseButtonClicked() diff --git a/mainwindow.h b/mainwindow.h index d3b85ce..2172c56 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -27,6 +27,7 @@ class MainWindow : public ElaWindow loginwin* login=new loginwin(); Q_SLOT void onCloseButtonClicked(); User*CurrentUser=nullptr; + DatabaseManager*db; public slots: void onUserLoggedIn(User user); diff --git a/user.cpp b/user.cpp index f6dc856..0df96eb 100644 --- a/user.cpp +++ b/user.cpp @@ -98,6 +98,11 @@ QString User::getEmail() return account; } +QString User::gethashedPassword() +{ + return hashedPassword; +} + QString User::getUserHash() const { QByteArray hash = QCryptographicHash::hash(account.toUtf8(), QCryptographicHash::Sha1); diff --git a/user.h b/user.h index 701a6b0..381eb79 100644 --- a/user.h +++ b/user.h @@ -37,7 +37,7 @@ class User : public QObject QString getUsername();//获取用户名 QString getEmail();//获取用户邮箱 QString getUserHash() const; //返回用户账户的哈希 - + QString gethashedPassword(); bool getisLogin(); //返回用户登陆状态 signals: