-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
104 lines (83 loc) · 3.06 KB
/
mainwindow.cpp
File metadata and controls
104 lines (83 loc) · 3.06 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include<QCryptographicHash>
#include<QByteArray>
#include "globalvaribals.h"
#include<QDir>
#include<QSystemTrayIcon>
//==============================================================================================
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setAutoFillBackground(true);
QPalette palatte;
QPixmap pixmap(":/img/img/back.jpg");
palatte.setBrush(backgroundRole(),QBrush(pixmap));
this->setPalette(palatte);
ui->lineEdit_Username->setFocus();
//background
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_Login_clicked()
{
QDir account;
account.cd("..");
account.cd("Login_MY_FINAL");
account.cd("RowData");
QFile UserAndPassFile (account.path()+"/accounts.json");
int loginflag;
loginflag=0;
UserAndPassFile.open(QIODevice::ReadOnly);
QByteArray UserAndPassByte=UserAndPassFile.readAll();
QJsonDocument UserAndPassDoc=QJsonDocument::fromJson(UserAndPassByte);
QJsonObject UserAndPassObj=UserAndPassDoc.object();
//QString UserName1
QString UserName1=(UserAndPassObj["admin"].toObject())["Username"].toString();
foreach(QJsonValue x,UserAndPassObj){
QString UserName=(x.toObject())["Username"].toString();
QString Password=(x.toObject())["Password"].toString();
QString CurrentAccountId=(x.toObject())["id"].toString();
QString UserName_lineEdit=ui->lineEdit_Username->text();
QString Password_lineEdit=ui->lineEdit_Password->text();
char* ch;
QByteArray ba = Password_lineEdit.toLatin1();
ch=ba.data ();
QString HashedPassword_lineEdit = QString(QCryptographicHash::hash((ch),QCryptographicHash::Keccak_512).toHex());
int UserLevel=(x.toObject())["AccountType"].toInt();
if(UserLevel==1&&UserName_lineEdit==UserName&&HashedPassword_lineEdit==Password){
loginflag=1;
QMessageBox::information(this," ","Login Succesful!");
GlobalVaribals::CurrentId=CurrentAccountId.toInt();
GlobalVaribals::CurrentAccType=1;;
hide();
Libaririan =new Window_Librarian(this);
Libaririan->show();
}
if(UserLevel==0&&UserName_lineEdit==UserName&&HashedPassword_lineEdit==Password){
loginflag=1;
QMessageBox::information(this," ","Login Succesful!");
GlobalVaribals::CurrentId=CurrentAccountId.toInt();
GlobalVaribals::CurrentAccType=0;
hide();
Member=new Window_Member(this);
Member->show();
}
}
if(loginflag==0){
loginflag=1;
QMessageBox::warning(this," ","Incorrect UserName or Password");
}
UserAndPassFile.close();
}