-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.cpp
248 lines (189 loc) · 4.71 KB
/
user.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "user.h"
#include "DlinkedList.h"
#include "DlinkedList.cpp"
#include "wall.h"
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <sstream>
using namespace std;
UserNetwork::UserNetwork(){
DoublyLinkedList<User> userList;
}
UserNetwork::UserNetwork(User user){
DoublyLinkedList<User> userList(user);
}
UserNetwork::~UserNetwork(){
//userList.~DoublyLinkedList();
}
void UserNetwork::add(User user){
userList.add(user);
}
void UserNetwork::remove(int _id){
userList.remove(_id);
}
string UserNetwork::getUserList(){
string result = "";
Node<User> *temp = userList.getRoot();
if(temp == NULL){
return "no user root \n";
}
while (temp != NULL){
result = result + (temp->data.getUsername()) + "\n" ;
temp = temp->next;
}
return result;
}
User::User (string _username, string _password, string _name, string _phoneNumber){
name = _name;
username = _username;
password = _password;
phoneNumber = _phoneNumber;
}
User::User(string _username, string _password){
name = "";
username = _username;
password = _password;
phoneNumber = "";
}
User::User(){
name = "";
username = "";
password = "";
phoneNumber = "";
}
User::User(string _username,string _password,string _name){
name = _name;
username = _username;
password = _password;
phoneNumber = "";
}
void User::editName(string _name){
name = _name;
}
void User::editUserName(string _username){
username = _username;
}
void User::editPassword(string _password){
password = _password;
}
void User::editPhoneNumber(string _phoneNumber){
phoneNumber = _phoneNumber;
}
void User::setId(int _id){
id = _id;
}
void User::createWallPost(string _post){
WallPost newPost(_post, username);
wall.add(newPost);
}
// void User::removeWallPost(Wall _wallPost){
// delete _wallPost;
// }
string User::getUsername(){
return username;
}
string User::getName(){
return name;
}
string User::getPassword(){
return password;
}
string User::getPhoneNumber(){
return phoneNumber;
}
string User::getWall(){
return wall.getWallList();
}
string User::displayInfo(){
string info = "Username: " + username +"\n" + "Name: " + name + "\n" + "Password: " + password + "\n" + "Phonenumber: "+ phoneNumber;
return info;
}
// id
void UserNetwork::writeNetwork(const char* file){
ofstream myfile;
myfile.open(file);
Node<User> *temp = userList.getRoot();
if(myfile.is_open()){
while(temp != NULL){
myfile << temp->data.displayInfo();
cout << temp->data.displayInfo();
temp = temp->next;
}
myfile.close();
}
else{
cout << "Unable to open the file" << endl;
}
}
<<<<<<< HEAD
void UserNetwork::readNetwork(const char* user_file){
=======
void UserNetwork::readNetwork(const char* user_file){
>>>>>>> de3fc3e3a48de67685e198316bcda09c92f5c1c5
ifstream myfile(user_file);
string read, inData, line, s;
string username, name, password, phoneNumber;
int count = 0;
while (getline(myfile, line).good()){
stringstream iss;
iss << line;
while ( getline(iss, s, '|') ){
switch (count){
case 0:
username = s;
break;
case 1:
password = s;
break;
case 2:
name = s;
break;
case 3:
phoneNumber = s;
break;
}
count++;
if (count > 3){
count = 0;
User new_user (username, password, name, phoneNumber);
add(new_user);
}
}
}
}
int User::getId(){
return id;
}
User* UserNetwork::login(string _username, string _password){
Node <User> *temp = userList.getRoot();
while (temp != NULL){
if ((temp->data.getUsername() == _username ) && (temp->data.getPassword() == _password)){
return &(temp->data);
}
else{
temp = temp ->next;
}
}
cout << "User does not exist or you have entered your username/password incorrectly \n";
return NULL;
}
int UserNetwork::validateUser(string _username){
Node <User> *temp = userList.getRoot();
while (temp != NULL){
if ((temp->data.getUsername() == _username )){
return 0;
}
else {
temp = temp -> next;
}
}
return 1;
}
/*
void UserNetwork::readNetwork(char *file){
>>>>>>> b8947be49cb462fe0c968d67957c4ae4e08b2f38
}
*/