-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
75 lines (69 loc) Β· 2.26 KB
/
Copy pathmainwindow.cpp
File metadata and controls
75 lines (69 loc) Β· 2.26 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
#include "mainwindow.h"
#include "./ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowModality(Qt::ApplicationModal);
this->setWindowIcon(QIcon(":/images/d66739fb-8e53-4420-a742-7417652b0c2e.ico"));
this->setWindowTitle("SIGN UP");
QPixmap pix(":/rec/images/add-friend (1).png");
ui->image->setPixmap(pix.scaled(pix.width(), pix.height(), Qt::KeepAspectRatio));
dataBase = QSqlDatabase::addDatabase("QSQLITE");
dataBase.setDatabaseName("path_to_your_database/name_of_your_database.db");
dataBase.open();
query = new QSqlQuery(dataBase);
query->exec("CREATE TABLE IF NOT EXISTS User(Login TEXT PRIMARY KEY, Password TEXT);");
}
MainWindow::~MainWindow()
{
cleanupSignIn();
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QString login = ui->login->text();
QString password = ui->password->text();
if(login == ""){
ui->label_3->setText("<i><font size=2 color='red'>Enter login!</font></i>");
return;
}
if(password == ""){
ui->label_3->setText("<i><font size=2 color='red'>Enter password!</font></i>");
return;
}
query->prepare("SELECT EXISTS(SELECT 1 FROM User WHERE Login = :login);");
query->bindValue(":login", login);
query->exec();
query->next();
bool exists = query->value(0).toBool();
if(exists){
ui->label_3->setText("<i><font size=2 color='red'>User already exist!</font></i>");
}else{
query->prepare("INSERT INTO User (Login, Password) VALUES (:login, :password);");
query->bindValue(":login", login);
query->bindValue(":password", password);
query->exec();
ui->label_3->setText("<i><font size=2 color='green'>Authorization succesful complete!</font></i>");
}
}
void MainWindow::on_pushButton_2_clicked()
{
if(!signIn){
signIn = new AnotherWindow();
signIn->setFixedSize(signIn->size());
connect(signIn, &AnotherWindow::destroyed, this, [this]() {
signIn = nullptr;
});
}
signIn->show();
this->hide();
}
void MainWindow::cleanupSignIn(){
if(signIn){
signIn->disconnect();
signIn->deleteLater();
signIn = nullptr;
}
}