diff --git a/AccountManagement/AMCore/AMModel.cpp b/AccountManagement/AMCore/AMModel.cpp index 85c1f07..3ff0a0c 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/MainWindow.cpp b/AccountManagement/MainWindow.cpp index 7fbad0a..b9a844a 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,6 @@ 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 +18,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/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 +