-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloguser.cpp
More file actions
103 lines (68 loc) · 1.94 KB
/
loguser.cpp
File metadata and controls
103 lines (68 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "loguser.h"
#include "ui_loguser.h"
#include "recipewindow.h"
#include "mainwindow.h"
logUser::logUser(QWidget *parent)
: QDialog(parent)
, ui(new Ui::logUser)
{
ui->setupUi(this);
ui->label_3->setText("");
mydb=QSqlDatabase::addDatabase ("QSQLITE") ;
mydb. setDatabaseName ("C:/Users/Raghav Singla/OneDrive/Desktop/SQLITE/sqlite-tools-win-x64-3450200/myrecipe.db") ;
if(!mydb.open()){
ui->label_3->setText("Failed to connect to Database");
}
else{
ui->label_3->setText("Connected...");
}
}
logUser::~logUser()
{
delete ui;
}
void logUser::on_pushButton_clicked()
{
QString username , password;
username = ui->lineEdit->text();
password = ui->lineEdit_2->text();
if(!mydb.isOpen()){
qDebug()<<"Failed to open the databse";
return;
}
QSqlQuery qry;
QString queryStr = "SELECT * FROM user WHERE username = '" + username + "' AND password = '" + password + "'";
if (qry.exec(queryStr)){
int count = 0;
while (qry.next()){
count++;
}
if (count == 1){
ui->label_3->setText("User Logged in successfully");
this->close();
// Open the recipewindow window
recipewindow *recipeWindowobject = new recipewindow(nullptr, username);
recipeWindowobject->show();
}
// if (count > 1){
// ui->label_3->setText("Duplicate username and password");
// }
if (count < 1){
ui->label_3->setText("username or passwor is not correct");
}
}
else {
qDebug() << "Error executing query: " << qry.lastError().text();
ui->label_3->setText("Failed to add user");
}
}
void logUser::on_pushButton_2_clicked()
{
this->close();
MainWindow *mainwindowobject = new MainWindow();
mainwindowobject->show();
}
void logUser::on_pushButton_3_clicked()
{
this->close();
}