-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlglogin.cpp
67 lines (59 loc) · 1.94 KB
/
dlglogin.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
#include "dlglogin.h"
#include "ui_dlglogin.h"
#include <QMessageBox>
#include <QCryptographicHash>
#include <QSqlError>
#include <QStatusBar>
#include <QDebug>
#include <mainwindow.h>
#include <QSqlTableModel>
#include <QSqlRecord>
#include <QLabel>
DlgLogin::DlgLogin(QWidget *parent) :
QDialog(parent),
ui(new Ui::DlgLogin)
{
ui->setupUi(this);
}
DlgLogin::~DlgLogin()
{
delete ui;
}
void DlgLogin::on_buttonBox_accepted()
{
try {
QByteArray byteArray = ui->txtPassword->text().toUtf8();
const char* cString = byteArray.constData();
QString pwd=QString(QCryptographicHash::hash(cString, QCryptographicHash::Md5).toHex());
QSqlTableModel personal;
personal.setTable("personal");
QString filter=QString("login='%1' and pwd='%2'").arg(ui->txtUsuario->text().trimmed()).arg(pwd);
personal.setFilter(filter);
personal.select();
if(personal.rowCount()>0){
MainWindow* w=(MainWindow *) this->parent();
w->statusBar()->showMessage(tr("Ready"));
QSqlRecord record=personal.record(0);
QString userName= QString("%1 %2").arg(record.value("nombre").toString()).arg(record.value("paterno").toString());
w->setUserName(userName.toUpper());
qApp->setProperty("user",record.value("id"));
qApp->setProperty("profile",record.value("perfil_id"));
// qDebug()<< qApp->property("profile");
}else{
ui->lblStateLogin->setText("Usuario o Contraseña errada");
this->setVisible(true);
}
} catch (...) {
QMessageBox::information(this, "info", "We are in throwExcept()",
QMessageBox::Ok);
}
}
void DlgLogin::on_buttonBox_rejected()
{
qDebug() << "Quit app";
qApp->quit();
}
void DlgLogin::on_DlgLogin_rejected()
{
qApp->quit();
}