-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.cpp
More file actions
134 lines (113 loc) · 4.2 KB
/
User.cpp
File metadata and controls
134 lines (113 loc) · 4.2 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// Created by Elestrias on 07.03.2021.
//
#include "User.h"
#include "dependencies.h"
User::User(const pair<string, string> &initials, const string &LovedJoke, const string log, const string pass) :
initials(initials),
lovedJoke(LovedJoke),
login(log),password(pass){
access = NO_LEVEL;
}
AccessType User::getAccess(){
return access;
}
User::User(){
access = NO_LEVEL;
}
pair<string, string> User::getInitials(){
return initials;
}
pair<AccessType, bool> User::changeGlobalAccess(AccessType acc, AccessType newacc) {
if (acc == RED) {
access = newacc;
return {access, true};
}
return {access, false};
}
bool User::comeIn(Room &room) {
bool opened = room.getAccess(access);
if(!opened) {
for (int i = 0; i < adminGarants.size(); ++i) {
if(adminGarants[i].second == room.getNumber()){
opened = true;
}
}
}
return opened;
}
string User::getCabinet(){
return personalCabinet;
}
bool User::changeRoomAccess(AccessType acc, Room *room){
bool flag = false;
if(acc == RED){
for(int i = 0; i < adminGarants.size(); ++i) {
if (room->getNumber() == adminGarants[i].second){
flag = true;
}
}
if(!flag){
adminGarants.push_back({RED, room->getNumber()});
return true;
}else{
return false;
}
}
else{
return false;
}
}
pair<string, string> User::getAccount(){
return make_pair(login, password);
}
string User::getJoke(){
return lovedJoke;
}
string User::toString(AccessType AT){
switch(AT){
case(NO_LEVEL): return "NO LEVEL";
case(GREEN): return "GREEN";
case(YELLOW): return "YELLOW";
case(RED): return "RED";
}
}
string User::getUserType(){
return UserType;
}
Student::Student(const pair<string, string> &initials, const string &lovedJoke, const string log, const string pass) : User(initials, lovedJoke, log, pass){
access = NO_LEVEL;
UserType = "Student";
}
Professor::Professor(const pair<string, string> &initials,const string personalRoom, const string &LovedJoke, const string log, const string pass): User(initials, LovedJoke, log, pass), PersonalRoom(personalRoom){
access = GREEN;
UserType = "Professor";
}
string Professor::getCabinet(){
return PersonalRoom;
}
void Professor::setCabinet(Room &room){
PersonalRoom = room.getNumber();
}
LabStuff::LabStuff(const pair<string, string> &initials, const string &personalRoom, const string log, const string pass): User(initials, personalRoom, log, pass) {
access = GREEN;
UserType = "LabStuff";
}
Director::Director(const pair<string, string> &initials, const string &personalRoom,const string &LovedJoke, const string log, const string pass): Professor(initials,
personalRoom,
LovedJoke, log, pass){
access = YELLOW;
UserType = "Director";
}
Admin::Admin(const pair<string, string> &initials, const string &PersonalRoom, const string &LovedJoke, const string log, const string pass):Professor(initials,
PersonalRoom,
LovedJoke, log, pass){
access = RED;
UserType = "Admin";
}
void Admin::updateAccessRoots(User user, AccessType newacc) {
user.changeGlobalAccess(this->access, newacc);
}
void Admin::giveGarant(User user, Room *room) {
user.changeRoomAccess(this->access, room);
}