-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTDBAuthDialog.cpp
81 lines (65 loc) · 2.09 KB
/
TDBAuthDialog.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
#include "TDBAuthDialog.h"
TDBAuthDialog::TDBAuthDialog(QWidget* parent) :
QDialog(parent)
{
setWindowTitle("Authentification");
trigramme_label = new QLabel("Trigramme", this);
trigramme_edit = new QLineEdit(this); // hack sordide
trigramme_edit->setInputMask(">NNN");
passwd_label = new QLabel("Mot de passe", this);
passwd_edit = new QLineEdit(this);
passwd_edit->setEchoMode(QLineEdit::Password);
layout = new QGridLayout(this);
layout->addWidget(trigramme_label, 0, 0);
layout->addWidget(trigramme_edit, 0, 1);
layout->addWidget(passwd_label, 1, 0);
layout->addWidget(passwd_edit, 1, 1);
ok_button = new QPushButton("OK", this);
layout->addWidget(ok_button, 2, 0);
cancel_button = new QPushButton("Cancel", this);
layout->addWidget(cancel_button, 2, 1);
setLayout(layout);
connect(cancel_button, SIGNAL(pressed()), this, SLOT(cancel_pressed()));
connect(ok_button, SIGNAL(pressed()), this, SLOT(ok_pressed()));
trigramme_edit->setFocus(Qt::PopupFocusReason);
}
TDBAuthDialog::~TDBAuthDialog()
{
delete layout;
delete trigramme_label;
delete trigramme_edit;
delete passwd_label;
delete passwd_edit;
delete ok_button;
delete cancel_button;
}
void TDBAuthDialog::cancel_pressed()
{
reject();
}
void TDBAuthDialog::ok_pressed()
{
TDBDatabase::open();
QSqlQuery query;
query.prepare("SELECT accounts.id as admin_id, permissions FROM admins LEFT JOIN accounts ON accounts.id = admins.id WHERE accounts.trigramme = :trigramme AND passwd = :password");
query.bindValue(":trigramme", trigramme_edit->text());
query.bindValue(":password", QCryptographicHash::hash(QByteArray().append(passwd_edit->text()), QCryptographicHash::Md5).toHex());
query.exec();
TDBDatabase::close();
if (query.first())
{
admin = query.record().value("admin_id").toInt();
perm = query.record().value("permissions").toInt();
accept();
}
else
reject();
}
int TDBAuthDialog::get_admin()
{
return admin;
}
int TDBAuthDialog::get_perm()
{
return perm;
}