-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSignUp.cs
282 lines (275 loc) · 10.5 KB
/
SignUp.cs
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
using System;
using System.Windows.Forms;
using System.Drawing;
namespace Instagram
{
public partial class SignUp : Form
{
DBHandlingUtilities dbHandler;
UIUtilities UI;
bool lightModeOn;
Main main;
string userID = null;
public SignUp(Main main)
{
InitializeComponent();
this.main = main;
this.lightModeOn = main.lightModeOn;
dbHandler = new DBHandlingUtilities();
UI = new UIUtilities(lightModeOn);
Configure_Theme();
}
public SignUp(Main main, string userId, string userName, string realUserName, string tagLine, string imageLocation)
{
InitializeComponent();
this.main = main;
this.lightModeOn = main.lightModeOn;
dbHandler = new DBHandlingUtilities();
UI = new UIUtilities(lightModeOn);
Configure_Theme();
Console.WriteLine(userId + userName);
this.userID = userId;
this.loginBtn.Dispose();
this.signUpBtn.Text = "Update";
this.userName_Box.Text = userName;
this.realUserName_Box.Text = realUserName;
this.tagLine_Box.Text = tagLine;
this.profileBox.Text = imageLocation;
}
private void Configure_Theme()
{
Color backColor, textColor;
if (lightModeOn)
{
backColor = Color.FromArgb(209, 209, 209);
textColor = Color.FromArgb(0, 0, 0);
}
else
{
backColor = Color.FromArgb(31, 31, 31);
textColor = Color.FromArgb(255, 255, 255);
}
this.BackColor = backColor;
userNameLabel.BackColor = backColor;
userNameLabel.ForeColor = textColor;
passwordLabel.ForeColor = textColor;
tagLineLabel.ForeColor = textColor;
confirmPasswordLabel.ForeColor = textColor;
realUserNameLabel.ForeColor = textColor;
userName_Box.ForeColor = textColor;
realUserName_Box.ForeColor = textColor;
userName_Box.BackColor = backColor;
realUserName_Box.BackColor = backColor;
confirmPassword_Box.ForeColor = textColor;
password_Box.ForeColor = textColor;
tagLineLabel.ForeColor = textColor;
instagramLogo.BackColor = backColor;
statusPassword.BackColor = backColor;
statusSymbolPassword.BackColor = backColor;
statusSymbolID.BackColor = backColor;
statusID.BackColor = backColor;
statusPassword.ForeColor = textColor;
statusID.ForeColor = textColor;
realUserNameLabel.BackColor = backColor;
confirmPassword_Box.BackColor = backColor;
password_Box.BackColor = backColor;
tagLineLabel.BackColor = backColor;
tagLine_Box.BackColor = backColor;
tagLine_Box.ForeColor = textColor;
instagramLogo.Image = Image.FromFile(UI.Return_UI_Location() + "logo.png");
}
private void signUp()
{
string userName = userName_Box.Text;
string realUserName = realUserName_Box.Text;
string pass = password_Box.Text;
string confirmPass = confirmPassword_Box.Text;
string tagLine = tagLine_Box.Text;
if (checkUserName(userName))
setStatus(0, true, "");
else
return;
if (checkPassword(pass))
setStatus(1, true, "");
else
return;
if (pass == confirmPass)
{
setStatus(2, true, "");
if(userID != null)
{
dbHandler.Update_User(userID, userName, realUserName, pass, profileBox.ImageLocation, tagLine);
Console.WriteLine("User updated Successfully!");
setStatus(0, true, "");
main.form.Dispose();
main.form = new Profile(main) { TopLevel = false, TopMost = true};
}
else if (dbHandler.Add_User(userName, realUserName, pass, profileBox.ImageLocation, tagLine))
{
dbHandler.Create_User_Entities(dbHandler.Return_User_ID(userName).ToString(), userName);
Console.WriteLine("User added Successfully!");
setStatus(0, true, "");
main.form.Dispose();
main.form = new Login(main) { TopLevel = false, TopMost = true};
}
else
setStatus(0, false, "Account Already Present!");
}
else
setStatus(2, false, "Password Doesnt Match!");
}
private void resetEntries()
{
userName_Box.Text = "";
confirmPassword_Box.Text = "";
realUserName_Box.Text = "";
password_Box.Text = "";
tagLine_Box.Text = "";
profileBox.Image = Image.FromFile(Environment.CurrentDirectory + @"\Assets\Avatar.png");
}
private void logIn_Click(object sender, EventArgs e)
{
main.form.Dispose();
main.form = new Login(main) { TopLevel = false, TopMost = true };
}
private void setStatus(int statusNumber, bool setStatus, string message)
{
string imageLocation = Environment.CurrentDirectory + @"\Assets\Generic Icons\";
switch (statusNumber)
{
case 0:
if (setStatus)
{
statusID.Text = "";
statusSymbolID.ImageLocation = imageLocation + "Right" + ".png";
}
else
{
statusID.ForeColor = Color.Red;
statusSymbolID.ImageLocation = imageLocation + "Wrong" + ".png";
statusID.Text = message;
}
break;
case 1:
if (setStatus)
{
statusPassword.Text = "";
statusSymbolPassword.ImageLocation = imageLocation + "Right" + ".png";
}
else
{
statusPassword.ForeColor = Color.Red;
statusSymbolPassword.ImageLocation = imageLocation + "Wrong" + ".png";
statusPassword.Text = message;
}
break;
case 2:
if (setStatus)
{
statusConfirmPassword.Text = "";
statusSymbolConfirmPassword.ImageLocation = imageLocation + "Right" + ".png";
}
else
{
statusConfirmPassword.ForeColor = Color.Red;
statusSymbolConfirmPassword.ImageLocation = imageLocation + "Wrong" + ".png";
statusConfirmPassword.Text = message;
}
break;
}
}
private bool checkUserName(string ID)
{
int countNumberOfCharacters = 0, countNumberOfIntegers = 0;
if ((ID[0] < 65 || ID[0] > 90) && (ID[0] < 97 || ID[0] > 122))
{
setStatus(0, false, "1st character should be an alphabet!");
return false;
}
for (int i = 0; i < ID.Length; i++)
{
if (ID[i] == ' ')
{
setStatus(0, false, "Space Detected!");
return false;
}
if ((ID[i] >= 65 && ID[i] <= 90) || (ID[i] >= 97 && ID[i] <= 122))
countNumberOfCharacters++;
if ((ID[i] >= 48 && ID[i] <= 57))
countNumberOfIntegers++;
}
if (ID.Length <= 6)
{
setStatus(0, false, "Length Too Small!");
return false;
}
if (countNumberOfCharacters <= 3)
{
setStatus(0, false, "Low Number Of Characters");
return false;
}
if (countNumberOfIntegers <= 2)
{
setStatus(0, false, "Low Number Of Integers");
return false;
}
return true;
}
private bool checkPassword(string pass)
{
bool checkCapitalLetters, checkSmallLetters, checkSpecialSymbol, checkNumberOfIntegers;
checkCapitalLetters = checkSmallLetters = checkSpecialSymbol = checkNumberOfIntegers = false;
for (int i = 0; i < pass.Length; i++)
{
if (pass[i] == ' ')
{
setStatus(1, false, "Space Detected!");
return false;
}
if (pass[i] >= 65 && pass[i] <= 90)
checkCapitalLetters = true;
if (pass[i] >= 97 && pass[i] <= 122)
checkSmallLetters = true;
if ((pass[i] >= 33 && pass[i] <= 47) || (pass[i] >= 58 && pass[i] <= 64))
checkSpecialSymbol = true;
if ((pass[i] >= 48 && pass[i] <= 57))
checkNumberOfIntegers = true;
}
if (pass.Length <= 6)
{
setStatus(1, false, "Length Too Small!");
return false;
}
if (!checkCapitalLetters)
{
setStatus(1, false, "No Capital Character!");
return false;
}
if (!checkSmallLetters)
{
setStatus(1, false, "No Small Letters!");
return false;
}
if (!checkSpecialSymbol)
{
setStatus(1, false, "No Special Symbols!");
return false;
}
if (!checkNumberOfIntegers)
{
setStatus(1, false, "No Integers!");
return false;
}
return true;
}
private void signUp_Click(object sender, EventArgs e)
{
signUp();
}
private void circularButton1_Click(object sender, EventArgs e)
{
dbHandler.Get_Picture();
profileBox.ImageLocation = dbHandler.fileDirectory;
}
}
}