-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuUsuarios.cpp
194 lines (153 loc) · 3.81 KB
/
MenuUsuarios.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
// Created by hugo
#include "MenuUsuarios.h"
using namespace std;
MenuUsuarios::MenuUsuarios()
{
//leer lista de usuarios
read();
}
void MenuUsuarios::addUser()
{
string name,type;
string password1("uno");
string password2("dos");
int tipo;
Usuario nuevoUser;
cout << "Agregar nuevo usuario:" << endl;
cout << "Escribe el nombre del nuevo usuario" << endl;
fflush(stdin);
getline(cin, name);
getline(cin, name);
nuevoUser.setNombre(name);
cout << "Escribe el numero del tipo de usuario:\n1) Administrador\n2) Usuario normal" << endl;
fflush(stdin);
cin >> tipo;
if ( tipo == 1)
{
type = "admin";
}
else
{
type = "base";
}
nuevoUser.setTipoUsuario(type);
while (password1 != password2)
{
cout << "Escribe tu contraseña:\t";
fflush(stdin);
getline(cin, password1);
getline(cin, password1);
cout << "Escribe tu contraseña de nuevo:\t";
fflush(stdin);
getline(cin, password2);
}
nuevoUser.setPassword(password2);
listaRam.insertData(listaRam.getLastPos(), nuevoUser);
cout << "Usuario creado con exito" << endl << listaRam.toString() << endl;
}
void MenuUsuarios::deleteUser()
{
string name;
Usuario userDelete;
char opc('X');
cout << "Escribe el nombre del usuario que deseas eliminar:\t";
fflush(stdin);
getline(cin, name);
getline(cin, name);
userDelete.setNombre(name);
NodoUsuario* auxNode;
auxNode = listaRam.findData(userDelete);
if (!listaRam.isValidPos(auxNode))
{
cout << "El usuario con nombre:\t" << name << " no existe" << endl;
//getline(cin, name);
return;
}
cout << "\n\n Continuar eliminando el usuario " << auxNode->getData().toString() << " ? (1->si / 2-> no)" << endl;
fflush(stdin);
cin >> opc;
if (opc != '1')
{
return;
}
listaRam.deleteData(auxNode);
cout << "\nUsuario eliminado" << endl;
cout << listaRam.toString() << endl;
}
void MenuUsuarios::write()
{
cout << "escribiendo lista de usuarios" << endl;
listaRam.write();
}
void MenuUsuarios::read()
{
cout << "Leyendo lista de usuarios" << endl;
listaRam.read();
}
void MenuUsuarios::showAllUsers()
{
cout << "Lista de usuarios" << endl<< endl<< endl;
cout << listaRam.toString() << endl;
}
std::string MenuUsuarios::findUser(std::string name, std::string pass)
{
Usuario auxUser;
auxUser.setNombre(name);
auxUser.setPassword(pass);
NodoUsuario* auxNodo;
auxNodo = listaRam.validateUser(auxUser);
if (auxNodo != nullptr)
{
string tipoUsuario;
tipoUsuario = auxNodo->getData().getTipoUsuario();
return tipoUsuario;
} else
{
return "invalido";
}
}
void MenuUsuarios::mainMenu()
{
char opc('X');
while (opc != 's')
{
cout << "Menu de usuarios" << endl;
cout << "\n1) Agregar nuevo usuario\n2) Eliminar usuario\n3) Mostrar usuarios\n4) Leer del disco\n5) Escribir nueva lista en el disco\n\ns) salir." << endl;
cout << "Elige la opcion que deseas:\t";
fflush(stdin);
cin >> opc;
switch (opc)
{
case '1':
{
addUser();
break;
}
case '2':
{
deleteUser();
break;
}
case '3':
{
showAllUsers();
break;
}
case '4':
{
read();
break;
}
case '5':
{
write();
break;
}
default:
{
cout << "opcion invalida" << endl;
break;
}
}
}
}