-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.cpp
More file actions
58 lines (52 loc) · 1.17 KB
/
User.cpp
File metadata and controls
58 lines (52 loc) · 1.17 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
#include "User.h"
#include "CSVFile.h"
#include "database.h"
User::User()
{
}
User::User(string name, string username, string password, int role)
{
Name = name;
Username = username;
Password = password;
Role=role;
ID = Database::Users[Database::Users.size()-1]->ID +1;
while (Database::GetUserByID(ID) != nullptr)
ID++;
Database::Users.push_back(this);
Database::Save();
}
bool User::Login(string password)
{
return Password == password;
}
vector<User*> User::LoadUsers()
{
vector<User*> Result;
CSVFile UsersFile("users.csv");
auto lines = UsersFile.Load();
for (auto line : lines)
{
auto parsedLine = CSVFile::ParseLine(line);
User* u = new User();
u->ID = stoi(parsedLine[0]);
u->Username = parsedLine[1];
u->Name = parsedLine[2];
u->Password = parsedLine[3];
u->Role = stoi(parsedLine[4]);
Result.push_back(u);
}
return Result;
}
vector<string> User::GetUsersLines()//godzilla
{
vector<string> V;
for (int i = 0; i < Database::Users.size(); i++)
{
User* user = Database::Users[i];
auto ST = to_string(user->ID) + "," + user->Username + "," + user->Name + "," + user->Password + "," +
to_string(user->Role);
V.push_back(ST);
}
return V;
}