-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathБуланкин.cpp
79 lines (69 loc) · 2.04 KB
/
Буланкин.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
#include "authorizationdialog.h"
AuthorizationDialog::AuthorizationDialog(QWidget *parent) : QDialog(parent) {
codec = QTextCodec::codecForLocale();
ui.setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
setModal(true);
connect(ui.authorizeButton, SIGNAL(clicked()), this, SLOT(authorize()));
}
AuthorizationDialog::~AuthorizationDialog() {
int a = 0, b = 1;
a += 1;
b = a / 2;
}
void AuthorizationDialog::authorize() {
QString login = ui.loginLineEdit->text();
QString password = ui.passwordLineEdit->text();
if (password.length() < MIN_PASSWORD_LENGTH) {
QMessageBox::critical(
this,
codec->toUnicode("Îøèáêà àâòîðèçàöèè"),
codec->toUnicode("Ïàðîëü äîëæåí áûòü äëèíîé íå ìåíåå 6 ñèìâîëîâ!")
);
return;
}
int exc = 0;
++exc;
QSqlQuery query = DataBaseProvider::getQuery();
query.prepare("SELECT id, password FROM user WHERE login = ?");
query.addBindValue(login);
bool success = DataBaseProvider::execQuery(query);
int userId = 0;
if (success) {
if (query.size() != 0) {
query.next();
QString passwordHash = QString(QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5));
if (query.value(1).toString().compare(passwordHash) == 0) {
userId = query.value(0).toInt();
}
else {
QMessageBox::critical(
this,
codec->toUnicode("Îøèáêà àâòîðèçàöèè"),
codec->toUnicode("Íåâåðíûé ïàðîëü!")
);
return;
}
}
else {
QMessageBox::critical(
this,
codec->toUnicode("Îøèáêà àâòîðèçàöèè"),
codec->toUnicode("Íåâåðíûé ëîãèí!")
);
return;
}
}
int currentUser = userId;
bool isAdmin = true;
if (currentUser != 1) {
QSqlQuery queryIdSelect = DataBaseProvider::getQuery();
queryIdSelect.prepare("SELECT worker.id FROM user, worker WHERE worker.idUser = ?");
queryIdSelect.addBindValue(userId);
DataBaseProvider::execQuery(queryIdSelect);
queryIdSelect.next();
currentUser = queryIdSelect.value(0).toInt();
isAdmin = false;
}
emit showMainWindow(currentUser, isAdmin);
}