-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_account.cpp
118 lines (100 loc) · 3.56 KB
/
create_account.cpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include "create_account.h"
#include "ui_create_account.h"
#include "mainwindow.h"
create_account::create_account(QWidget *parent) :
QDialog(parent),
ui(new Ui::create_account)
{
setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint);
setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint);
ui->setupUi(this);
}
create_account::~create_account()
{
delete ui;
}
void create_account::on_register_2_clicked()
{
QSqlDatabase db=QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("C:/Users/user/OneDrive/Documents/Final/Databases/final.db");
if(db.open())
{
QString name=ui->name->text();
QString age=ui->age->text();
QString blood_group=ui->blood_group->text();
QString gender=ui->gender->text();
QString location=ui->location->text();
QString email=ui->email->text();
QString phone_number=ui->phone_number->text();
QString password=ui->password->text();
QString disease=ui->disease->text();
if(name != "" && age != "" && blood_group != "" && gender != "" && location != "" && email != "" && phone_number != "" && password != ""){
int em=0,ph_no=0,p=0;
QRegularExpression re("(\\w+)(\\w*)@(\\w+)(\\.(\\w+))+");
if(re.match(email).hasMatch()) em = 1;
if(phone_number.length()>=10) ph_no=1;
if(password.length()>=8) p=1;
if(p){
if(em){
if(ph_no){
QSqlQuery qry,check;
int user_id=0;
if(check.exec("select * from user_details where email='"+email+"' "))
{
while(check.next())
{
user_id++;
}
}
if(user_id==1)
{
QMessageBox::information(this,"Error","Your account is already registered with this email.");
}
else
{
qry.prepare("INSERT INTO user_details(name,age,blood_group,gender,location,email,phone_number,password,disease) "
"VALUES('"+name+"', '"+age+"', '"+blood_group+"', '"+gender+"', '"+location+"', '"+email+"', '"+phone_number+"', '"+password+"', '"+disease+"')");
qry.bindValue(":name", name);
qry.bindValue(":age", age);
qry.bindValue(":blood_group", blood_group);
qry.bindValue(":gender", gender);
qry.bindValue(":location", location);
qry.bindValue(":email", email);
qry.bindValue(":phone_number", phone_number);
qry.bindValue(":password", password);
qry.bindValue(":disease", disease);
if(qry.exec())
{
QMessageBox::information(this,"Information","Your account is created");
}
}
}
else
{
ui->phone_number->setStyleSheet("border: 1px solid rgb(144, 10, 18) ");
QMessageBox::information(this, "Error", "Please Enter valid Phone number.");
}
}
else
{
ui->email->setStyleSheet("border: 1px solid rgb(144, 10, 18) ");
QMessageBox::critical(this, "Error", "Please Enter valid Email.");
}
}
else
{
ui->password->setStyleSheet("border: 1px solid rgb(144, 10, 18)");
QMessageBox::critical(this, "Error", "Password must be at least 8 character long.");
}
}
else {
QMessageBox::critical(this, "Error", "Fill in all the input fields to create account.");
}
}
}
void create_account::on_back_clicked()
{
this->close();
MainWindow *mainWindow = new MainWindow();
mainWindow->show();
}