forked from MoustafaMagdy10/Online-wallet-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogs.cpp
210 lines (170 loc) · 5.76 KB
/
Logs.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
#include "Logs.h"
Logs::Logs()
{
ImVec2 windowSize = ImGui::GetWindowSize();
float centerX = windowSize.x * 0.5f;
float centerY = windowSize.y * 0.5f;
ImGui::SetCursorPosX(centerX - ImGui::CalcTextSize("Log In").x * 0.5f - ImGui::GetStyle().FramePadding.x * 2);
ImGui::SetCursorPosY(centerY - ImGui::CalcTextSize("Log In").y * 0.5f - ImGui::GetStyle().FramePadding.y * 2);
if (ImGui::Button("Log In", ImVec2(170, 70)))
{
logIn();
}
centerY -= 130;
ImGui::SetCursorPosX(centerX - ImGui::CalcTextSize("Register").x * 0.5f - ImGui::GetStyle().FramePadding.x * 2 + 15);
ImGui::SetCursorPosY(centerY - ImGui::CalcTextSize("Register").y * 0.5f - ImGui::GetStyle().FramePadding.y * 2);
if (ImGui::Button("Register", ImVec2(170, 70)))
{
register_();
}
return;
}
void Logs::register_()
{
vector<char> userName(15), password(20), password1(20), password2(20);
bool done = false;
bool wrongUser = false;
bool duplicatedUserName = false;
bool wrongPassword = true;
string _userName, _password, _password2;
int step = 0;
Person *it = nullptr;
while (!done)
{
Menu::EndFrame();
Menu::RenderFrame();
switch (step)
{
case 0:
ImGui::NewLine();
ImGui::InputTextWithHint("Name", "Enter Your User Name", userName.data(), userName.size()); // Remove the undefined identifier
_userName = userName.data();
if (_userName.size() < 5)
{
ImGui::Text("Username should be more than 5 characters long");
wrongUser = true;
}
else
wrongUser = false;
ImGui::NewLine();
if ((ImGui::Button("Next") or ImGui::IsKeyPressed(ImGuiKey_Enter)) and !wrongUser)
{
_userName = userName.data();
it = Person::getUserByName(_userName);
if (it == nullptr)
{
step++;
}
else
{
duplicatedUserName = true;
}
}
if (duplicatedUserName)
ImGui::Text("User name already exists");
break;
case 1:
ImGui::NewLine();
ImGui::NewLine();
ImGui::InputTextWithHint("password", "password", password1.data(), password1.size(), ImGuiInputTextFlags_Password);
ImGui::NewLine();
ImGui::InputTextWithHint("password again", "password", password2.data(), password2.size(), ImGuiInputTextFlags_Password);
_password = password1.data();
_password2 = password2.data();
if (_password2 != _password and !_password2.empty())
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "passwords don't matches");
ImGui::NewLine();
if (Person::checkValidPassword(_password) and (ImGui::Button("Next") or ImGui::IsKeyPressed(ImGuiKey_Enter)) and _password2 == _password)
{
Person::addPerson(_userName, _password, false);
Person::currentPerson = Person::getUserByName(_userName);
Person::initializeUser();
done = true;
Menu::SleepForSec("You Have Registered successfully");
}
break;
}
ImGui::NewLine();
if (ImGui::Button("Back"))
{
done = true;
}
if (WindowShouldClose())
Menu::safeEnd();
}
return;
}
void Logs::logIn()
{
vector<char> userName(15), password(20);
string _userName, _password;
bool done = false;
bool wrongUser = false;
int steps = 0;
bool wrongPassword = false;
Person *it = nullptr;
while (!done)
{
Menu::EndFrame();
Menu::RenderFrame();
switch (steps)
{
case 0:
ImGui::NewLine();
ImGui::InputTextWithHint("Name", "Enter Your User Name", userName.data(), userName.size());
_userName = userName.data();
ImGui::NewLine();
if (ImGui::Button("Next") or ImGui::IsKeyPressed(ImGuiKey_Enter))
{
_userName = userName.data();
it = Person::getUserByName(_userName);
if (it == nullptr)
{
wrongUser = true;
}
else
{
steps++;
}
}
if (wrongUser)
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "No such user exists");
break;
case 1:
ImGui::NewLine();
ImGui::InputTextWithHint( "password","enter your password", password.data(), password.size(), ImGuiInputTextFlags_Password);
ImGui::NewLine();
if (ImGui::Button("Next") or ImGui::IsKeyPressed(ImGuiKey_Enter))
{
_password = password.data();
if (!it->checkPassword(_password, it))
{
wrongPassword = true;
}
else
{
Person::currentPerson = Person::getUserByName(_userName);
Person::initializeUser();
done = true;
}
}
if (wrongPassword)
{
ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Wrong Password");
}
}
ImGui::NewLine();
if (ImGui::Button("Back"))
{
done = true;
}
if (WindowShouldClose())
Menu::safeEnd();
}
}
void Logs::logOut()
{
Person::currentPerson = nullptr;
User::currentUser = nullptr;
Admin::currentAdmin = nullptr;
}