main
Joaquin 9 months ago
commit f72813655e
Signed by: puly
GPG Key ID: 9E9299CD96C65EC6
  1. 3
      .gitignore
  2. 87
      Autoritate.cpp
  3. 36
      Autoritate.h
  4. 19
      CMakeLists.txt
  5. 21
      Contract.cpp
  6. 22
      Contract.h
  7. 87
      Document.cpp
  8. 58
      Document.h
  9. 62
      User.cpp
  10. 48
      User.h
  11. 36
      Zi.cpp
  12. 38
      Zi.h
  13. 14
      common.cpp
  14. 20
      common.h
  15. 25
      main.cpp

3
.gitignore vendored

@ -0,0 +1,3 @@
a.out
cmake-build-debug
sc.sh

@ -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;
}
}

@ -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

@ -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)

@ -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();
}

@ -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<std::tuple<User*, std::string>> semnatariPF;
std::vector<std::tuple<Autoritate*, std::string>> 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

@ -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;
}

@ -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

@ -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 "";
}

@ -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<std::string, Document*> 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

@ -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<std::mutex> 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;
}

38
Zi.h

@ -0,0 +1,38 @@
//
// Created by ioachim on 18.05.2025.
//
#ifndef ZI_H
#define ZI_H
#include <mutex>
//#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

@ -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<std::string>{}(str));
}
template<typename data_type>
data_type MAX(data_type x, data_type y) {
return (x > y) ? x : y;
}

@ -0,0 +1,20 @@
//
// Created by ioachim on 17.05.2025.
//
#ifndef COMMON_H
#define COMMON_H
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <memory>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
std::string hashString(std::string str);
#endif //COMMON_H

@ -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());
}
Loading…
Cancel
Save