-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow_cancelmembership.cpp
More file actions
82 lines (66 loc) · 2.41 KB
/
window_cancelmembership.cpp
File metadata and controls
82 lines (66 loc) · 2.41 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
#include "window_cancelmembership.h"
#include "ui_window_cancelmembership.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <bits/stdc++.h>
#include <QDate>
#include <QString>
#include <QPair>
#include<QMessageBox>
#include<QCryptographicHash>
#include<QDir>
//==============================================================================================
Window_CancelMembership::Window_CancelMembership(QWidget *parent) :
QDialog(parent),
ui(new Ui::Window_CancelMembership)
{
ui->setupUi(this);
ui->lineEdit_MemberId->setFocus();
}
Window_CancelMembership::~Window_CancelMembership()
{
delete ui;
}
void Window_CancelMembership::on_pushButton_CacnelMembership_clicked()
{
QDir account;
account.cd("..");
account.cd("Login_MY_FINAL");
account.cd("RowData");
QFile AccountsFile (account.path()+"/accounts.json");
AccountsFile.open(QIODevice::ReadWrite);
QJsonDocument jsonDocAcc = QJsonDocument::fromJson( AccountsFile.readAll() );
QJsonObject Accounts_Obj=jsonDocAcc.object();
AccountsFile.close();
QString MemberId = ui->lineEdit_MemberId->text();
QString EnteredPassword = ui->lineEdit_Password->text();
QByteArray ref = EnteredPassword.toUtf8();;
QString EnteredPassword_Hashed = QString(QCryptographicHash::hash((ref),QCryptographicHash::Keccak_512).toHex());
QJsonValueRef Account_ref = Accounts_Obj.find(MemberId).value();
QJsonObject Account_Obj= Account_ref.toObject();
QString MemberName= Account_Obj["Name"].toString();
QString Password= Account_Obj["Password"].toString();
QJsonObject RentedBooks= Account_Obj["RentedBooks"].toObject();
if(RentedBooks.size()>0){
QMessageBox::warning(this,"Can't cancel membership","This member has some rented books yet.");
//notification that it is not permitted
return;
}
if(Password!=EnteredPassword_Hashed){
QMessageBox::warning(this,"Can't cancel membership","Entered ID and password did not match.");
return;
}
Accounts_Obj.remove(MemberId);
QJsonDocument final_acc_doc(Accounts_Obj);
if( !AccountsFile.open( QIODevice::WriteOnly ) ) //write json content to file.
{
qDebug()<<"error opening file for write.\n";
}
AccountsFile.write(final_acc_doc.toJson());
QMessageBox::information(this,"","Membership canceled sucessfully.");
AccountsFile.close();
}