-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthwindow.cpp
113 lines (98 loc) · 3.02 KB
/
authwindow.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
#include "authwindow.h"
#include "ui_authwindow.h"
#include <QtDebug>
#include <QMessageBox>
#include <QValidator>
#include "list.h"
authwindow::authwindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::authwindow)
{
ui->setupUi(this);
setFixedSize(510, 180);
setWindowTitle("Вход");
QRegularExpression st("[a-zA-Z0-9-]{0,30}");
QRegularExpressionValidator* check = new QRegularExpressionValidator(st, this);
ui->lineLogin->setValidator(check);
ui->linePassword->setValidator(check);
}
authwindow::~authwindow()
{
delete ui;
}
//функции
void authwindow::cleanLineEdit()
{
ui->lineLogin->clear();
ui->linePassword->clear();
}
bool authwindow::authUser(bool& window, user& thisUser)
{
if(checkLineEdit() == true)
{
QMessageBox::warning(this, "Внимание","Вы не заполнили поле");
cleanLineEdit();
return false;
}
else
{
List<user> users;
List<admin> admins;
db.connectToDataBase();
users = db.getUserFromTable();
admins = db.getAdminFromTable();
db.closeDataBase();
Iterator<user> userIt(users);
Iterator<admin> adminIt(admins);
int countOfAdmins = admins.Count() - 1;
int countOfUsers = users.Count() - 1;
if(users.isEmpty() == true)
{
QMessageBox::warning(this, "Внимание","Ни один пользователь не зарегистрирован");
cleanLineEdit();
return false;
}
while(adminIt.hasNext())
{
if(ui->lineLogin->text() == admins[countOfAdmins].getLogin() && ui->linePassword->text() == admins[countOfAdmins].getPassword())
{
window = true;
return true;
}
adminIt.next();
countOfAdmins--;
}
while(userIt.hasNext())
{
if(ui->lineLogin->text() == users[countOfUsers].getLogin() && ui->linePassword->text() == users[countOfUsers].getPassword())
{
thisUser = users[countOfUsers];
window = false;
return true;
}
userIt.next();
countOfUsers--;
}
QMessageBox::warning(this, "Внимание","Неправильно введены\nлогин или пароль");
cleanLineEdit();
admins.Clear();
users.Clear();
return false;
}
}
bool authwindow::checkLineEdit()
{
if(ui->lineLogin->text().isEmpty() == true || ui->linePassword->text().isEmpty() == true)
return true;
else
return false;
}
//cлоты
void authwindow::on_buttonSignIn_clicked()
{
emit login_button_clicked();
}
void authwindow::on_buttonRegistration_clicked()
{
emit register_button_clicked();
}