Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions AccountManagement/AMCore/AMModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion AccountManagement/AMCore/AMModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions AccountManagement/AMCore/QUserDAO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
}

2 changes: 1 addition & 1 deletion AccountManagement/AMCore/QUserDAO.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 7 additions & 10 deletions AccountManagement/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "MainWindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
ui(new Ui::MainWindow)
Expand All @@ -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()
Expand All @@ -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;
}

3 changes: 1 addition & 2 deletions AccountManagement/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
66 changes: 54 additions & 12 deletions AccountManagement/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<widget class="QPushButton" name="loginButton">
<property name="geometry">
<rect>
<x>580</x>
<y>190</y>
<x>470</x>
<y>200</y>
<width>131</width>
<height>61</height>
</rect>
Expand All @@ -27,25 +27,67 @@
<string>Login</string>
</property>
</widget>
<widget class="QPlainTextEdit" name="Name">
<widget class="QPlainTextEdit" name="username">
<property name="geometry">
<rect>
<x>210</x>
<y>190</y>
<width>321</width>
<height>70</height>
<x>260</x>
<y>70</y>
<width>331</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QPlainTextEdit" name="something">
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>210</x>
<y>290</y>
<width>311</width>
<height>70</height>
<x>160</x>
<y>60</y>
<width>91</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;Username:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>160</x>
<y>120</y>
<width>91</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;Password:&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit">
<property name="geometry">
<rect>
<x>260</x>
<y>130</y>
<width>331</width>
<height>41</height>
</rect>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
<widget class="QPushButton" name="Createuser">
<property name="geometry">
<rect>
<x>320</x>
<y>200</y>
<width>131</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>Create</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
Expand Down