-
Notifications
You must be signed in to change notification settings - Fork 0
/
clsUser.cpp
126 lines (89 loc) · 2.34 KB
/
clsUser.cpp
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
#include "clsUser.h"
const string clsUser::UsersFileName = "users.txt";
clsUser::clsUser(enMode Mode, string FirstName, string LastName,
string Email, string Phone, string UserName, string Password,
int Permissions) :
clsPerson(FirstName, LastName, Email, Phone)
{
_Mode = Mode;
_Username = UserName;
_Password = Password;
_Permissions = Permissions;
}
string clsUser::GetUserName()
{
return _Username;
}
void clsUser::SetUserName(string Username)
{
_Username = Username;
}
string clsUser::GetPassword()
{
return _Password;
}
void clsUser::SetPassword(string Password)
{
_Password = Password;
}
int clsUser::GetPermissions() {
return _Permissions;
}
void clsUser::SetPermission(int Permission)
{
_Permissions = (enPermissions)Permission;
}
clsUser clsUser::_ConvertLinetoUserObject(string Line, string Seperator)
{
vector<string> vUserData;
vUserData = clsString::Split(Line, Seperator);
return clsUser(clsUser::enMode::enUpdateMode, vUserData[0], vUserData[1], vUserData[2],
vUserData[3], vUserData[4], vUserData[5], stoi(vUserData[6]));
}
string clsUser::_ConverUserObjectToLine(clsUser User, string Seperator)
{
string UserRecord = "";
UserRecord += User.firstname+ Seperator;
UserRecord += User.lastname + Seperator;
UserRecord += User.email + Seperator;
UserRecord += User.phone + Seperator;
UserRecord += User.username+ Seperator;
UserRecord += User.password + Seperator;
UserRecord += to_string(User.permissions);
return UserRecord;
}
vector<clsUser> clsUser::_LoadUsersDataFromFile()
{
vector <clsUser> vUsers;
fstream MyFile;
MyFile.open("Users.txt", ios::in);
if (MyFile.is_open())
{
string Line;
while (getline(MyFile, Line))
{
clsUser User = _ConvertLinetoUserObject(Line);
vUsers.push_back(User);
}
MyFile.close();
}
return vUsers;
}
void clsUser::_SaveUsersDataToFile(vector <clsUser> vUsers)
{
fstream MyFile;
MyFile.open("Users.txt", ios::out);
string DataLine;
if (MyFile.is_open())
{
for (clsUser U : vUsers)
{
if (U.markForDeletion == false)
{
DataLine = _ConverUserObjectToLine(U);
MyFile << DataLine << endl;
}
}
MyFile.close();
}
}