From b4698142dc6988d96361b17cec0548139bd07403 Mon Sep 17 00:00:00 2001 From: trungvm Date: Wed, 27 Apr 2022 19:15:57 +0700 Subject: [PATCH 1/2] ui-login --- AccountManagement/AMCore/AMModel.cpp | 17 +++++-- AccountManagement/AMCore/AMModel.h | 2 +- AccountManagement/AMCore/QUserDAO.cpp | 23 ++++++++++ AccountManagement/AMCore/QUserDAO.h | 2 +- AccountManagement/CMakeLists.txt | 6 +-- AccountManagement/MainWindow.cpp | 18 ++++---- AccountManagement/MainWindow.h | 3 +- AccountManagement/create.ui | 19 ++++++++ AccountManagement/createusr.cpp | 7 +++ AccountManagement/createusr.h | 19 ++++++++ AccountManagement/mainwindow.ui | 66 ++++++++++++++++++++++----- 11 files changed, 148 insertions(+), 34 deletions(-) create mode 100644 AccountManagement/create.ui create mode 100644 AccountManagement/createusr.cpp create mode 100644 AccountManagement/createusr.h diff --git a/AccountManagement/AMCore/AMModel.cpp b/AccountManagement/AMCore/AMModel.cpp index 85c1f07..6dd8a03 100644 --- a/AccountManagement/AMCore/AMModel.cpp +++ b/AccountManagement/AMCore/AMModel.cpp @@ -11,12 +11,19 @@ AMModel::AMModel(QObject *parent) qDebug() << "AMModel Init"; } -void AMModel::login(const QUser &user) +void AMModel::login( QUser &user) { - // TODO: Check user in database - m_currentUser->setName(user.name()); - m_currentUser->setPass(user.pass()); - m_currentUser->setFullName(user.fullName()); + bool checkdone = m_dbManager.userDao.isloginUserExits(user); + + if(checkdone){ + qDebug()<< "check done"; +// m_currentUser->setName(user.name()); +// m_currentUser->setPass(user.pass()); +// m_currentUser->setFullName(user.fullName()); + } + else { + qDebug()<<"fail"; + } } void AMModel::signOut() diff --git a/AccountManagement/AMCore/AMModel.h b/AccountManagement/AMCore/AMModel.h index b0c1927..3065fcd 100644 --- a/AccountManagement/AMCore/AMModel.h +++ b/AccountManagement/AMCore/AMModel.h @@ -13,7 +13,7 @@ class AMModel : public QObject public: explicit AMModel(QObject *parent = nullptr); - void login(const QUser& user); + void login(QUser& user); void signOut(); void addUser(QUser& user); diff --git a/AccountManagement/AMCore/QUserDAO.cpp b/AccountManagement/AMCore/QUserDAO.cpp index 02f92ec..dbf97e2 100644 --- a/AccountManagement/AMCore/QUserDAO.cpp +++ b/AccountManagement/AMCore/QUserDAO.cpp @@ -75,3 +75,26 @@ bool QUserDAO::isUserExits(QUser &user) const } return false; } + +bool QUserDAO::isloginUserExits(QUser &user) const +{ + QSqlQuery query(m_database); + query.prepare("SELECT * FROM users WHERE name = :name"); + + query.bindValue(":name", user.name()); + + query.exec(); + + QDatabaseManager::debugQuery(query); + + if(query.first()){ + if(query.value("pass").toString()==user.pass()){ + return true; + } + else{ + return false; + } + + } +} + diff --git a/AccountManagement/AMCore/QUserDAO.h b/AccountManagement/AMCore/QUserDAO.h index 9734986..3706e7f 100644 --- a/AccountManagement/AMCore/QUserDAO.h +++ b/AccountManagement/AMCore/QUserDAO.h @@ -15,7 +15,7 @@ class QUserDAO bool addUser(QUser& user) const; bool isUserExits(QUser& user) const; - + bool isloginUserExits(QUser& user) const; //TODO: Add CRUD function void updateUser(const QUser& user) const; void removeUser(int id) const; diff --git a/AccountManagement/CMakeLists.txt b/AccountManagement/CMakeLists.txt index 23b8a21..04339ec 100644 --- a/AccountManagement/CMakeLists.txt +++ b/AccountManagement/CMakeLists.txt @@ -18,9 +18,9 @@ add_subdirectory(AMCore) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/AMCore) -set(project_sources MainWindow.cpp main.cpp) -set(project_headers MainWindow.h) -set(project_ui mainwindow.ui) +set(project_sources MainWindow.cpp main.cpp ) +set(project_headers MainWindow.h ) +set(project_ui mainwindow.ui ) # wrap the ui file to a c++ header qt5_wrap_ui(ui_wrap ${project_ui}) diff --git a/AccountManagement/MainWindow.cpp b/AccountManagement/MainWindow.cpp index 7fbad0a..90f970c 100644 --- a/AccountManagement/MainWindow.cpp +++ b/AccountManagement/MainWindow.cpp @@ -1,7 +1,6 @@ #include "MainWindow.h" #include "ui_mainwindow.h" #include - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -11,7 +10,7 @@ MainWindow::MainWindow(QWidget *parent) ui->setupUi(this); connect(ui->loginButton, &QPushButton::clicked, this, &MainWindow::getLogindata); - connect(this, &MainWindow::something, this, &MainWindow::printSomething); + } MainWindow::~MainWindow() @@ -20,14 +19,13 @@ MainWindow::~MainWindow() void MainWindow::getLogindata() { - QString name = ui->Name->toPlainText(); - qDebug() << name; - - emit something(name); + QString usrname = ui->username->toPlainText(); + QString usrpass = ui->lineEdit->text(); + QUser usrlogin; + usrlogin.setName(usrname); + usrlogin.setPass(usrpass); + m_model->login(usrlogin); + qDebug()<< usrlogin.name(); } -void MainWindow::printSomething(QString name) -{ - qDebug() << name; -} diff --git a/AccountManagement/MainWindow.h b/AccountManagement/MainWindow.h index df29b21..be7e6cf 100644 --- a/AccountManagement/MainWindow.h +++ b/AccountManagement/MainWindow.h @@ -18,11 +18,10 @@ class MainWindow : public QMainWindow ~MainWindow(); signals: - void something(QString name); + void loginsignals(QUser userlogin); public slots: void getLogindata(); - void printSomething(QString name); public: diff --git a/AccountManagement/create.ui b/AccountManagement/create.ui new file mode 100644 index 0000000..5a9d7b6 --- /dev/null +++ b/AccountManagement/create.ui @@ -0,0 +1,19 @@ + + + create + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/AccountManagement/createusr.cpp b/AccountManagement/createusr.cpp new file mode 100644 index 0000000..b42081a --- /dev/null +++ b/AccountManagement/createusr.cpp @@ -0,0 +1,7 @@ +#include "createusr.h" +#include "ui_create.h" + +Createusr::~Createusr() +{ + +} diff --git a/AccountManagement/createusr.h b/AccountManagement/createusr.h new file mode 100644 index 0000000..ede18e3 --- /dev/null +++ b/AccountManagement/createusr.h @@ -0,0 +1,19 @@ +#ifndef CREATEUSR_H +#define CREATEUSR_H + + +#include +#include +namespace Ui { +class Createusr; +} +class Createusr : public QWidget +{ +Q_OBJECT +public: +explicit Createusr(const QString& name, QWidget *parent = 0); +~Createusr(); +private: +Ui::Createusr *ui; +}; +#endif //CREATEUSR_H diff --git a/AccountManagement/mainwindow.ui b/AccountManagement/mainwindow.ui index 27a1049..9f5853e 100644 --- a/AccountManagement/mainwindow.ui +++ b/AccountManagement/mainwindow.ui @@ -17,8 +17,8 @@ - 580 - 190 + 470 + 200 131 61 @@ -27,25 +27,67 @@ Login - + - 210 - 190 - 321 - 70 + 260 + 70 + 331 + 41 - + - 210 - 290 - 311 - 70 + 160 + 60 + 91 + 51 + + <html><head/><body><p><span style=" font-size:14pt;">Username:</span></p></body></html> + + + + + + 160 + 120 + 91 + 51 + + + + <html><head/><body><p><span style=" font-size:14pt;">Password:</span></p></body></html> + + + + + + 260 + 130 + 331 + 41 + + + + QLineEdit::Password + + + + + + 320 + 200 + 131 + 61 + + + + Create + From 9a904969155d6cdc3b688175a2eb797d08954f8b Mon Sep 17 00:00:00 2001 From: trungvm Date: Wed, 27 Apr 2022 19:38:48 +0700 Subject: [PATCH 2/2] login-ui --- AccountManagement/AMCore/AMModel.cpp | 6 +++--- AccountManagement/CMakeLists.txt | 6 +++--- AccountManagement/MainWindow.cpp | 1 - AccountManagement/create.ui | 19 ------------------- AccountManagement/createusr.cpp | 7 ------- AccountManagement/createusr.h | 19 ------------------- 6 files changed, 6 insertions(+), 52 deletions(-) delete mode 100644 AccountManagement/create.ui delete mode 100644 AccountManagement/createusr.cpp delete mode 100644 AccountManagement/createusr.h diff --git a/AccountManagement/AMCore/AMModel.cpp b/AccountManagement/AMCore/AMModel.cpp index 6dd8a03..3ff0a0c 100644 --- a/AccountManagement/AMCore/AMModel.cpp +++ b/AccountManagement/AMCore/AMModel.cpp @@ -17,9 +17,9 @@ void AMModel::login( QUser &user) if(checkdone){ qDebug()<< "check done"; -// m_currentUser->setName(user.name()); -// m_currentUser->setPass(user.pass()); -// m_currentUser->setFullName(user.fullName()); + m_currentUser->setName(user.name()); + m_currentUser->setPass(user.pass()); + m_currentUser->setFullName(user.fullName()); } else { qDebug()<<"fail"; diff --git a/AccountManagement/CMakeLists.txt b/AccountManagement/CMakeLists.txt index 04339ec..23b8a21 100644 --- a/AccountManagement/CMakeLists.txt +++ b/AccountManagement/CMakeLists.txt @@ -18,9 +18,9 @@ add_subdirectory(AMCore) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/AMCore) -set(project_sources MainWindow.cpp main.cpp ) -set(project_headers MainWindow.h ) -set(project_ui mainwindow.ui ) +set(project_sources MainWindow.cpp main.cpp) +set(project_headers MainWindow.h) +set(project_ui mainwindow.ui) # wrap the ui file to a c++ header qt5_wrap_ui(ui_wrap ${project_ui}) diff --git a/AccountManagement/MainWindow.cpp b/AccountManagement/MainWindow.cpp index 90f970c..b9a844a 100644 --- a/AccountManagement/MainWindow.cpp +++ b/AccountManagement/MainWindow.cpp @@ -10,7 +10,6 @@ MainWindow::MainWindow(QWidget *parent) ui->setupUi(this); connect(ui->loginButton, &QPushButton::clicked, this, &MainWindow::getLogindata); - } MainWindow::~MainWindow() diff --git a/AccountManagement/create.ui b/AccountManagement/create.ui deleted file mode 100644 index 5a9d7b6..0000000 --- a/AccountManagement/create.ui +++ /dev/null @@ -1,19 +0,0 @@ - - - create - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - diff --git a/AccountManagement/createusr.cpp b/AccountManagement/createusr.cpp deleted file mode 100644 index b42081a..0000000 --- a/AccountManagement/createusr.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "createusr.h" -#include "ui_create.h" - -Createusr::~Createusr() -{ - -} diff --git a/AccountManagement/createusr.h b/AccountManagement/createusr.h deleted file mode 100644 index ede18e3..0000000 --- a/AccountManagement/createusr.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef CREATEUSR_H -#define CREATEUSR_H - - -#include -#include -namespace Ui { -class Createusr; -} -class Createusr : public QWidget -{ -Q_OBJECT -public: -explicit Createusr(const QString& name, QWidget *parent = 0); -~Createusr(); -private: -Ui::Createusr *ui; -}; -#endif //CREATEUSR_H