-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserManager.cpp
More file actions
106 lines (94 loc) · 3.05 KB
/
UserManager.cpp
File metadata and controls
106 lines (94 loc) · 3.05 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
#include "UserManager.h"
User UserManager::setNewUserData() {
User user;
user.setUserId(getNewUserId());
do {
cout << "Podaj login: ";
user.setLogin(AuxiliaryMethods::inputLine());
} while (isLoginExist(user.getLogin()) == true);
cout << "Podaj haslo: ";
user.setPassword(AuxiliaryMethods::inputLine());
cout << "Podaj imie: ";
user.setName(AuxiliaryMethods::inputLine());
cout << "Podaj nazwisko: ";
user.setSurname(AuxiliaryMethods::inputLine());
return user;
}
bool UserManager::isLoginExist(string login) {
for (vector <User>::iterator itr = users.begin(); itr != users.end(); itr++) {
if (itr -> getLogin() == login) {
cout << endl << "Istnieje uzytkownik o takim loginie." << endl;
return true;
}
}
return false;
}
int UserManager::getNewUserId() {
if (users.empty() == true)
return 1;
else
return users.back().getUserId() + 1;
}
void UserManager::userRegistration() {
User user = setNewUserData();
users.push_back(user);
usersFile.writeUserDataToXmlFile(user);
cout << endl << "Konto zalozono pomyslnie" << endl << endl;
system("pause");
}
void UserManager::userLogging() {
string login = "", password = "";
cout << endl << "Podaj login: ";
login = AuxiliaryMethods::inputLine();
vector <User>::iterator itr = users.begin();
while (itr != users.end()) {
if (itr -> getLogin() == login) {
for (int trials = 3; trials > 0; trials--) {
cout << "Podaj haslo. Pozostalo prob: " << trials << ": ";
password = AuxiliaryMethods::inputLine();
if (itr -> getPassword() == password) {
loggedInUserId = itr -> getUserId();
cout << endl << "Zalogowales sie." << endl << endl;
system("pause");
return;
}
}
cout << "Wprowadzono 3 razy bledne haslo." << endl;
system("pause");
return;
}
itr++;
}
cout << "Nie ma uzytkownika z takim loginem" << endl << endl;
system("pause");
return;
}
void UserManager::changeLoggedInUserPassword() {
User user;
string newPassword = "";
cout << "Podaj nowe haslo: ";
newPassword = AuxiliaryMethods::inputLine();
for (vector <User>::iterator itr = users.begin(); itr != users.end(); itr++) {
if (itr -> getUserId() == loggedInUserId) {
itr -> setPassword(newPassword);
cout << "Haslo zostalo zmienione." << endl << endl;
user.setUserId(itr ->getUserId());
user.setPassword(itr -> getPassword());
system("pause");
}
}
usersFile.changePasswordInXmlFile(user);
}
int UserManager::getLoggedInUserId() {
return loggedInUserId;
}
int UserManager::userLogout() {
loggedInUserId = 0;
return loggedInUserId;
};
bool UserManager::isUserLoggedIn() {
if (loggedInUserId > 0)
return true;
else
return false;
}