commit f72813655e62dce645728af283261b3653a185d1 Author: Joaquin Date: Sat May 31 02:53:41 2025 +0300 Add files diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1e571b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +a.out +cmake-build-debug +sc.sh diff --git a/Autoritate.cpp b/Autoritate.cpp new file mode 100644 index 0000000..838b826 --- /dev/null +++ b/Autoritate.cpp @@ -0,0 +1,87 @@ +// +// Created by ioachim on 18.05.2025. +// + +#include "Autoritate.h" + +Autoritate& Autoritate::operator=(const Autoritate& frate) { + if(this != &frate) { + autoritateID = frate.autoritateID; + nume = frate.nume; + passHash = frate.passHash; + } + return *this; +} + +std::ostream& operator <<(std::ostream& os, const Autoritate& user){ + os << "ID: " << user.autoritateID << "\nNume: " << user.nume << "\nDosar: "; + + os << "\n"; + return os; +} + +bool Autoritate::tryLogin(std::string _pass) { + if (hashString(_pass) == passHash) { + return true; + } + return false; +} + +bool Autoritate::changePassword(std::string _pass, std::string _newpass) { + if (hashString(_pass) == passHash) { + passHash = hashString(_pass); + return true; + } + return false; +} + +std::string Autoritate::getName() { + return nume; +} + +void Autoritate::emiteAnexa(Document* _doc, std::string _anex) { + + if (_doc->origineAnexa == nullptr) { + Document::Anexa* ax = new Document::Anexa(); + _doc->origineAnexa = ax; + ax->continut = _anex; + ax->doc = _doc; + ax->idAnexa = hashString(ax->exportAnexa()); + ax->urm = nullptr; + return; + } + Document::Anexa* ax = _doc->origineAnexa; + while (ax->urm != nullptr) { + ax = ax->urm; + } + ax->urm = new Document::Anexa(); + ax->urm->continut = _anex; + ax->urm->doc = _doc; + ax->urm->idAnexa = hashString(ax->urm->exportAnexa()); + ax->urm->urm = nullptr; + +} + +Autoritate::~Autoritate() { + +} + +Document* Autoritate::emiteDocument(std::string _nume, std::string _continut, User* _Titular, Zi* _data_emitere, Zi* _data_expirare) { + try { + Document* doc = new Document(); + doc->origineAnexa = nullptr; + doc->Continut = _continut; + if (_Titular == nullptr) { + throw 404; + } + doc->Titular = _Titular; + doc->Emitator = this; + doc->dataEmitere = _data_emitere; + doc->dataExpirare = _data_expirare; + doc->titlu = _nume; + return doc; + }catch (int errorCode) { + std::cout << "ERROR: " << errorCode << std::endl; + } +} + diff --git a/Autoritate.h b/Autoritate.h new file mode 100644 index 0000000..00cf8e6 --- /dev/null +++ b/Autoritate.h @@ -0,0 +1,36 @@ +// +// Created by ioachim on 18.05.2025. +// + +#ifndef AUTORITATE_H +#define AUTORITATE_H + +#include "common.h" +#include "Document.h" + +class Autoritate { +private: + std::string autoritateID; + std::string nume; + std::string passHash; + +public: + Autoritate(): autoritateID(""), nume(""), passHash("") {} + Autoritate(const std::string& id, const std::string& name, const std::string& password) : autoritateID(id), nume(name), passHash(hashString(password)) {} + Autoritate(const Autoritate& frate): + autoritateID(frate.autoritateID), + nume(frate.nume), + passHash(frate.passHash) {} + Autoritate& operator=(const Autoritate& frate); + ~Autoritate(); + friend std::ostream& operator <<(std::ostream& os, const Autoritate& user); + bool tryLogin(std::string _pass); + bool changePassword(std::string _pass, std::string _newpass); + std::string getName(); + void emiteAnexa(Document* _doc, std::string _anex); + Document* emiteDocument(std::string _nume, std::string _continut, User* _Titular, Zi* _data_emitere, Zi* _data_expirare); +}; + + + +#endif //AUTORITATE_H diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d269055 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.31) +project(proiect) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(proiect + main.cpp + User.cpp + User.h + common.h + Document.cpp + Document.h + Zi.cpp + Zi.h + Autoritate.cpp + Autoritate.h + common.cpp + Contract.cpp + Contract.h) diff --git a/Contract.cpp b/Contract.cpp new file mode 100644 index 0000000..26f23b2 --- /dev/null +++ b/Contract.cpp @@ -0,0 +1,21 @@ +// +// Created by ioachim on 26.05.2025. +// + +#include "Contract.h" +#include "User.h" +#include "Autoritate.h" +#include "Zi.h" +//Contract::Contract(std::string _titlu, User* _Titular, Autoritate* _Emitator, std::string _continut, Zi* _data_emitere, Zi* _data_expirare) : Document(_titlu, _Titular, _Emitator, _continut, _data_emitere, _data_expirare) { +// +//} + +std::string Contract::exportForSigning() { + std::string str = ""; + std::stringstream os; + std::string emitatorStr = (Emitator != nullptr) ? Emitator->getName() : "NULL"; + std::string titluarStr = (Titular != nullptr) ? Titular->getName() : "NULL"; + os << "Titlu: " << titlu << "\n-----------------------------------------------\nTitular: " << titluarStr << "\nEmitator: " << emitatorStr << "\n\nContinut: \n" << Continut << "\n\nData de emitere: " << dataEmitere->day << "/" << dataEmitere->month << "/" << dataEmitere->year << "\nData de expirare: " << dataExpirare->day << "/" << dataExpirare->month << "/" << dataExpirare->year; + + return os.str(); +} \ No newline at end of file diff --git a/Contract.h b/Contract.h new file mode 100644 index 0000000..02bfb66 --- /dev/null +++ b/Contract.h @@ -0,0 +1,22 @@ +// +// Created by ioachim on 26.05.2025. +// + +#ifndef CONTRACT_H +#define CONTRACT_H + +#include "Document.h" + + +class Contract : public Document { +private: + std::vector> semnatariPF; + std::vector> semnatariPJ; +public: + Contract(std::string _titlu, User* _Titular, Autoritate* _Emitator, std::string _continut, Zi* _data_emitere, Zi* _data_expirare); + std::string exportForSigning() override; +}; + + + +#endif //CONTRACT_H diff --git a/Document.cpp b/Document.cpp new file mode 100644 index 0000000..0f76216 --- /dev/null +++ b/Document.cpp @@ -0,0 +1,87 @@ +// +// Created by ioachim on 18.05.2025. +// + +#include "Document.h" +#include "User.h" +#include "Autoritate.h" +#include "Zi.h" + + + +//Document::Document() : idDocument(""), titlu(""), Titular(nullptr), Emitator(nullptr), Continut(""), dataEmitere(new Zi(0, 0, 0)), dataExpirare(new Zi(0, 0, 0)), origineAnexa(nullptr) {} + + +Document& Document::operator=(const Document& secundar) { + if(this != &secundar) { + idDocument = secundar.idDocument; + titlu = secundar.titlu; + Titular = secundar.Titular; + Emitator = secundar.Emitator; + Continut = secundar.Continut; + dataEmitere = secundar.dataEmitere; + dataExpirare = secundar.dataExpirare; + } + return *this; +} + +std::string Document::getID(){ + return idDocument; +} + +std::string Document::exportForSigning() { + std::string str = ""; + std::stringstream os; + std::string emitatorStr = (Emitator != nullptr) ? Emitator->getName() : "NULL"; + std::string titluarStr = (Titular != nullptr) ? Titular->getName() : "NULL"; + os << "Titlu: " << titlu << "\n-----------------------------------------------\nTitular: " << titluarStr << "\nEmitator: " << emitatorStr << "\n\nContinut: \n" << Continut << "\n\nData de emitere: " << dataEmitere->day << "/" << dataEmitere->month << "/" << dataEmitere->year << "\nData de expirare: " << dataExpirare->day << "/" << dataExpirare->month << "/" << dataExpirare->year; + return os.str(); +} + +std::string Document::exportAnexe() { + std::stringstream os; + Anexa *ax = origineAnexa; + while (ax != nullptr) { + os << ax->exportAnexa() << std::endl; + ax = ax->getUrm(); + } + return os.str(); +} + +std::ostream& operator<<(std::ostream& os, const Document& doc) { + Document ndoc = doc; + os << std::endl << "ID:" << ndoc.getID() << std::endl; + os << ndoc.exportForSigning(); + os << std::endl << ndoc.exportAnexe(); + return os; +} + +Document::Document(std::string _titlu, User* _Titular, Autoritate* _Emitator, std::string _continut, Zi* _data_emitere, Zi* _data_expirare) { + if (Emitator != nullptr) { + return; + } + titlu = _titlu; + Titular = _Titular; + Emitator = _Emitator; + Continut = _continut; + dataEmitere = _data_emitere; + dataExpirare = _data_expirare; + origineAnexa = nullptr; + + idDocument = hashString(exportForSigning()); +} + +Document::Document() { + titlu = ""; + Titular = nullptr; + Emitator = nullptr; + Continut = ""; + dataEmitere = nullptr; + dataExpirare = nullptr; + origineAnexa = nullptr; +} + + + + + diff --git a/Document.h b/Document.h new file mode 100644 index 0000000..cf0162a --- /dev/null +++ b/Document.h @@ -0,0 +1,58 @@ +// +// Created by ioachim on 18.05.2025. +// + +#ifndef DOCUMENT_H +#define DOCUMENT_H + +#include "common.h" +class Zi; +class User; +class Autoritate; + +class Document { + class Anexa { + private: + std::string idAnexa; + std::string continut; + Anexa* urm; + Document *doc; + public: + + Anexa(): idAnexa(""), continut(""), urm(nullptr) {} + + std::string exportAnexa() { + std::stringstream os; + os << "\nANEXA la doc(" << doc->getID() << ")\n--------\n" << "Continut (Anexa):\n" << continut; + return os.str(); + } + + Anexa* getUrm() { + return urm; + } + friend class Autoritate; + }; +protected: + Anexa* origineAnexa = nullptr; + std::string idDocument; + std::string titlu; + User* Titular; + Autoritate* Emitator; + std::string Continut; + Zi* dataEmitere; + Zi* dataExpirare; +public: + Document(std::string _titlu, User* _Titular, Autoritate* _Emitator, std::string _continut, Zi* _data_emitere, Zi* _data_expirare); + Document(); + Document& operator=(const Document& secundar); + friend std::ostream& operator<<(std::ostream& os, const Document& doc); + std::string getID(); + virtual std::string exportForSigning(); + //void populate(std::string _titlu, User* _Titular, Autoritate* _Emitator, std::string _continut, Zi* _dataEmitere, Zi* _dataExpirare); + std::string exportAnexe(); + friend class Autoritate; +}; + + + +#endif //DOCUMENT_H diff --git a/User.cpp b/User.cpp new file mode 100644 index 0000000..9d873ba --- /dev/null +++ b/User.cpp @@ -0,0 +1,62 @@ +// +// Created by ioachim on 17.05.2025. +// + +#include "User.h" +#include "Document.h" + +void User::addDocument(Document* doc) { + Dosar[doc->getID()] = doc; +} + +void User::removeDocument(std::string _id) { + Dosar.erase(_id); +} + +User::~User() { + +} + + +User::User(const std::string& id, const std::string& _name, const std::string& password) : userID(id), nume(_name), passHash(hashString(password)), Dosar() { + userID = id; + nume = _name; + passHash = hashString(password); + +} + +User& User::operator=(const User& frate) { + if(this != &frate) { + userID = frate.userID; + nume = frate.nume; + passHash = frate.passHash; + Dosar = frate.Dosar; + } + return *this; +} + +std::ostream& operator <<(std::ostream& os, const User& user){ + os << "ID: " << user.userID << "\nNume: " << user.nume << "\nDosar: "; + + os << "\n"; + return os; +} + +bool User::tryLogin(std::string _pass) { + if (hashString(_pass) == passHash) { + return true; + } + return false; +} + +bool User::changePassword(std::string _pass, std::string _newpass) { + if (hashString(_pass) == passHash) { + passHash = hashString(_pass); + return true; + } + return false; +} + +std::string User::getName() { + return ""; +} diff --git a/User.h b/User.h new file mode 100644 index 0000000..f5cecf5 --- /dev/null +++ b/User.h @@ -0,0 +1,48 @@ +#ifndef USER_H +#define USER_H + + +#include "common.h" + +class Document; + +class User { +private: + std::string userID; + std::string nume = ""; + std::string passHash; + std::unordered_map Dosar; + +public: + User(const std::string& id, const std::string& name, const std::string& password); + + //User(const std::string& id, const std::string& name, const std::string& password) : userID(id), nume(name), passHash(hashString(password)), Dosar() {} + + /*User(const User& frate): + userID(frate.userID), + nume(frate.nume), + passHash(frate.passHash), + Dosar(frate.Dosar) + {}*/ + + User& operator=(const User& frate); + + ~User(); + + void addDocument(Document* doc); + + void removeDocument(std::string _id); + + friend std::ostream& operator <<(std::ostream& os, const User& user); + + bool tryLogin(std::string _pass); + + bool changePassword(std::string _pass, std::string _newpass); + + std::string getName(); + +}; + + +#endif USER_H + diff --git a/Zi.cpp b/Zi.cpp new file mode 100644 index 0000000..91dfade --- /dev/null +++ b/Zi.cpp @@ -0,0 +1,36 @@ +// +// Created by ioachim on 18.05.2025. +// + +#include "Zi.h" +ZiuaDeAzi* ZiuaDeAzi::instance = nullptr; +ZiuaDeAzi* ZiuaDeAzi::getInstance() { + if (instance == nullptr) { + //std::lock_guard lock(mtx); + //if (instance == nullptr) { + instance = new ZiuaDeAzi(); + //} + } + return instance; +} + +bool Zi::verifExpirare() const { + ZiuaDeAzi* x = ZiuaDeAzi::getInstance(); + Zi currentDate = x->getZiuaDeAzi(); + return currentDate.year > year || (currentDate.year == year && currentDate.month > month) || (currentDate.year == year && currentDate.month == month && currentDate.day > day); +} + +Zi::Zi(int day, int month, int year) : day(day), month(month), year(year) {} + + + +void ZiuaDeAzi::setZiuaDeAzi(Zi _z) { + z = _z; +} + +Zi ZiuaDeAzi::getZiuaDeAzi() { + return z; +} + + + diff --git a/Zi.h b/Zi.h new file mode 100644 index 0000000..fea550d --- /dev/null +++ b/Zi.h @@ -0,0 +1,38 @@ +// +// Created by ioachim on 18.05.2025. +// + +#ifndef ZI_H +#define ZI_H +#include + +//#include "common.h" + +class Zi { +public: + Zi(int day, int month, int year); + int day; + int month; + int year; + bool verifExpirare() const; +}; + +class ZiuaDeAzi { +private: + Zi z; + static ZiuaDeAzi* instance; + + //static std::mutex mtx; + + ZiuaDeAzi() : z{12, 12, 12} {} +public: + ZiuaDeAzi(const ZiuaDeAzi& obj) = delete; + static ZiuaDeAzi* getInstance(); + Zi getZiuaDeAzi(); + void setZiuaDeAzi(Zi _z); + +}; + + + +#endif //ZI_H diff --git a/common.cpp b/common.cpp new file mode 100644 index 0000000..e521adc --- /dev/null +++ b/common.cpp @@ -0,0 +1,14 @@ +// +// Created by ioachim on 19.05.2025. +// + +#include "common.h" + +std::string hashString(std::string str) { + return std::to_string(std::hash{}(str)); +} + +template +data_type MAX(data_type x, data_type y) { + return (x > y) ? x : y; +} \ No newline at end of file diff --git a/common.h b/common.h new file mode 100644 index 0000000..2c5be07 --- /dev/null +++ b/common.h @@ -0,0 +1,20 @@ +// +// Created by ioachim on 17.05.2025. +// + +#ifndef COMMON_H +#define COMMON_H +#include +#include +#include +#include +#include +#include +#include +#include +#include + +std::string hashString(std::string str); + + +#endif //COMMON_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..9d8f381 --- /dev/null +++ b/main.cpp @@ -0,0 +1,25 @@ +#include "common.h" +#include "Zi.h" +#include "User.h" +#include "Document.h" +#include "Autoritate.h" + +int main(){ + Zi azi(20, 5, 2025); + Zi dExpir(30, 5, 2026); + ZiuaDeAzi* _azi = ZiuaDeAzi::getInstance(); + _azi->setZiuaDeAzi(azi); + + dExpir.verifExpirare(); + Autoritate xxx = Autoritate("DRPCIV", "DRPCIV", "pulapulapizdapizda"); + User ion = User("abc", "Popescu Ion", "pulanpizda"); + std::cout << ion; + + //Document doc("Permis de Conducere Digital", &ion, &xxx, "B: 20/01/2025\nB1: 20/01/2025\nAM: 20/01/2025", &azi, &dExpir); + Document* doc = xxx.emiteDocument("Permis de Conducere Digital", "B: 20/01/2025\nB1: 20/01/2025\nAM: 20/01/2025", &ion, &azi, &dExpir); + xxx.emiteAnexa(doc, "DOAR AUTOMATA | COD: 87"); + xxx.emiteAnexa(doc, "PERMIS RETINUT PENTRU CA E UN BETIV INFECT"); + std::cout << *doc; + std::cout << std::endl; + std::cout << hashString(doc->exportForSigning()); +} \ No newline at end of file