-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsignup.cpp
More file actions
76 lines (66 loc) · 2.03 KB
/
signup.cpp
File metadata and controls
76 lines (66 loc) · 2.03 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 "signup.h"
#include "ui_signup.h"
#include "login.h"
#include <QMessageBox>
Signup::Signup(QWidget *parent) :
QDialog(parent),
ui(new Ui::Signup)
{
ui->setupUi(this);
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("C:/Users/lenovo/Documents/QT/DepartmentDB.db");
if(!db.open()){
qDebug()<<"Can't connect to the database !";
}
else{
qDebug()<<"Connected !";
}
}
Signup::~Signup()
{
delete ui;
}
void Signup::on_SignupButton_clicked()
{
QString Username,Email, Password,Verify_pass ;
Username = ui->Username->text();
Email = ui->Email->text();
Password = ui->Password->text();
Verify_pass = ui->Verify_pass->text();
if(Username=="" || Email=="" ||Password=="" || Verify_pass==""){
QMessageBox::warning(this,"Signup","Veuillez remplir tout les champs s'il vous plaît.");
}
else{
//cherche si le compte existe
auto qry = QSqlQuery(db);
QString searchAcc = {"SELECT Email FROM Utilisateur WHERE Email='"+Email+"'" };
if(!qry.exec(searchAcc))
qDebug() << "Cannot select";
int count = 0;
while(qry.next())
count++;
if(count>=1)
QMessageBox::warning(this, "Failed", "Compte déjà existant!");
else {
if (Password == Verify_pass){
QSqlQuery *qry = new QSqlQuery() ;
qry->prepare("INSERT INTO Utilisateur (Username,Email,Password)" "VALUES (?,?,?);");
qry->addBindValue(Username);
qry->addBindValue(Email);
qry->addBindValue(Password);
qry->exec();
QMessageBox::information(this,"valider","Votre compte a été créé avec succès");
this->hide();
Login Login;
Login.exec();
}
else
QMessageBox::warning(this,"Signup","Mot de passe de vérification n'est pas juste");
}
}}
void Signup::on_LoginReturn_clicked()
{
this->hide();
Login Login;
Login.exec();
}