This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForgotPassword.vb
364 lines (331 loc) · 17.9 KB
/
ForgotPassword.vb
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
Imports System.IO
Imports System.Net
Imports System.Resources
Imports System.Text.RegularExpressions
Imports Svg
Public Class ForgotPassword
Inherits BaseForm
Private FormPanel As New Transparent.FlowLayoutPanel
Private MainFormPanel As New Transparent.FlowLayoutPanel
Protected Sub ForgotPassword_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Name = "Forgot Password"
Me.FormPanel.MinimumSize = New Size(
Me.Width * 0.375,
0
)
Me.FormPanel.MaximumSize = New Size(
Me.Width * 0.375,
0
)
Me.FormPanel.AutoSize = True
Me.FormPanel.Location = New Point(
CInt(Me.Width * 0.5 - Me.FormPanel.Width * 0.5),
CInt(Me.Height * 0.5 - Me.FormPanel.Height * 0.5)
)
Me.Contents.Controls.Add(Me.FormPanel)
Dim Logo As New PictureBox With {
.SizeMode = PictureBoxSizeMode.Zoom,
.Name = "Logo"
}
Dim resourcesManager As ResourceManager = My.Resources.ResourceManager
Dim LogoImage As Image = resourcesManager.GetObject("CdMSMS-ICS Logo")
Logo.Image = LogoImage
Logo.Size = New Size(Me.FormPanel.Width, CInt(LogoImage.Size.Height * (Me.FormPanel.Width / LogoImage.Size.Width)))
Me.FormPanel.Controls.Add(Logo)
Dim ResetPasswordLabel As New Label With {
.Text = "Reset Password",
.AutoSize = True,
.MinimumSize = New Size(Me.FormPanel.Width, 0),
.MaximumSize = New Size(Me.FormPanel.Width, 0),
.Name = "ResetPassword",
.TextAlign = ContentAlignment.MiddleCenter,
.Font = Globals.GetFont("Raleway", Globals.Unit(1), FontStyle.Bold),
.ForeColor = Globals.Palette("Plain Dark")
}
Me.FormPanel.Controls.Add(ResetPasswordLabel)
Me.MainFormPanel = New Transparent.FlowLayoutPanel With {
.AutoSize = True,
.MinimumSize = New Size(Me.FormPanel.Width - Globals.Unit(2), 0),
.MaximumSize = New Size(Me.FormPanel.Width - Globals.Unit(2), 0)
}
Me.FormPanel.Controls.Add(Me.MainFormPanel)
Dim EmailInput As New BaseTextInput With {
.Name = "Email",
.Size = New Size(Me.MainFormPanel.Width, Globals.Unit(1))
}
Me.MainFormPanel.Controls.Add(EmailInput)
Dim ForgotPasswordCodeInput As New BaseTextInput With {
.Name = "Forgot Password Code",
.Size = New Size(Me.MainFormPanel.Width, Globals.Unit(1)),
.Visible = False
}
Me.MainFormPanel.Controls.Add(ForgotPasswordCodeInput)
Dim NewPasswordInput As New BaseTextInput With {
.Name = "New Password",
.Size = New Size(Me.MainFormPanel.Width, Globals.Unit(1)),
.Visible = False,
.PasswordChar = "*"
}
Me.MainFormPanel.Controls.Add(NewPasswordInput)
Dim SubmitRequestButton As New BaseButton With {
.Text = "Submit Request",
.Size = New Size(Me.MainFormPanel.Width, Globals.Unit(1)),
.Name = "SubmitRequest"
}
Dim SubmitCodeButton As New BaseButton With {
.Text = "Submit Code",
.Size = New Size(Me.MainFormPanel.Width, Globals.Unit(1)),
.Name = "SubmitCode",
.Visible = False
}
Dim SubmitNewPasswordButton As New BaseButton With {
.Text = "Submit New Password",
.Size = New Size(Me.MainFormPanel.Width, Globals.Unit(1)),
.Name = "SubmitNewPassword",
.Visible = False
}
Me.MainFormPanel.Controls.Add(SubmitRequestButton)
Me.MainFormPanel.Controls.Add(SubmitCodeButton)
Me.MainFormPanel.Controls.Add(SubmitNewPasswordButton)
AddHandler SubmitRequestButton.Click, Sub()
Dim EmailValue As String = EmailInput.Text
If Not Regex.IsMatch(EmailValue, "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$") Then
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = "Invalid email address"
}
Modal.ShowDialog()
Return
End If
Dim data As New Dictionary(Of String, String) From {
{"email", EmailValue}
}
Try
Dim response = Globals.API("POST", "user/forgotPassword/", Globals.DictionaryToJSON(data))
Dim Modal As New BaseModal With {
.Title = "Success",
.Message = "Password reset request sent"
}
Modal.ShowDialog()
EmailInput.Visible = False
SubmitRequestButton.Visible = False
ForgotPasswordCodeInput.Visible = True
SubmitCodeButton.Visible = True
Catch ex As WebException
Dim rep As HttpWebResponse = ex.Response
Using rdr As New StreamReader(rep.GetResponseStream())
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = rep.StatusCode & ": " & rdr.ReadToEnd()
}
Modal.ShowDialog()
End Using
End Try
End Sub
AddHandler SubmitCodeButton.Click, Sub()
Dim EmailValue As String = EmailInput.Text
Dim CodeValue As String = ForgotPasswordCodeInput.Text
'Match text
'000-000-000
If Not Regex.IsMatch(CodeValue, "^\d{3}-\d{3}-\d{3}$") Then
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = "Invalid code format"
}
Modal.ShowDialog()
Return
End If
Dim data As New Dictionary(Of String, String) From {
{"email", EmailValue},
{"forgotPasswordCode", CodeValue}
}
Try
Dim response = Globals.API("POST", "user/resetPassword/", Globals.DictionaryToJSON(data))
Dim Modal As New BaseModal With {
.Title = "Success",
.Message = "Code verified"
}
Modal.ShowDialog()
ForgotPasswordCodeInput.Visible = False
SubmitCodeButton.Visible = False
NewPasswordInput.Visible = True
SubmitNewPasswordButton.Visible = True
Catch ex As WebException
Dim rep As HttpWebResponse = ex.Response
Using rdr As New StreamReader(rep.GetResponseStream())
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = rep.StatusCode & ": " & rdr.ReadToEnd()
}
Modal.ShowDialog()
End Using
End Try
End Sub
AddHandler SubmitNewPasswordButton.Click, Sub()
Dim EmailValue As String = EmailInput.Text
Dim CodeValue As String = ForgotPasswordCodeInput.Text
Dim NewPasswordValue As String = NewPasswordInput.Text
If NewPasswordValue = "" And NewPasswordValue.Length < 8 Then
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = "Password must be at least 8 characters."
}
Modal.ShowDialog()
Exit Sub
End If
Dim data As New Dictionary(Of String, String) From {
{"email", EmailValue},
{"forgotPasswordCode", CodeValue},
{"password", NewPasswordValue}
}
Try
Dim response = Globals.API("POST", "user/changePassword/", Globals.DictionaryToJSON(data))
Dim Modal As New BaseModal With {
.Title = "Success",
.Message = "Password reset"
}
Modal.ShowDialog()
Me.GoToForm(New Login)
Catch ex As WebException
Dim rep As HttpWebResponse = ex.Response
Using rdr As New StreamReader(rep.GetResponseStream())
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = rep.StatusCode & ": " & rdr.ReadToEnd()
}
Modal.ShowDialog()
End Using
End Try
End Sub
Dim i As Integer = 0
For Each Control As Control In Me.MainFormPanel.Controls
Control.Margin = New Padding(
(Me.MainFormPanel.Width - Control.Width) * 0.5,
0,
0,
Globals.Unit(0.5)
)
i = i + 1
Next
Me.MainFormPanel.Controls(Me.MainFormPanel.Controls.Count - 1).Margin = New Padding(0)
Dim ForgotPasswordLabel As New Transparent.Label With {
.Text = "ForgotPassword?",
.AutoSize = True,
.MinimumSize = New Size(Me.MainFormPanel.Width, 0),
.MaximumSize = New Size(Me.MainFormPanel.Width, 0),
.Name = "ForgotPassword",
.TextAlign = ContentAlignment.MiddleCenter,
.Font = Globals.GetFont("Open Sans", Globals.Unit(0.5), FontStyle.Regular),
.ForeColor = Globals.Palette("Plain Dark")
}
Me.FormPanel.Controls.Add(ForgotPasswordLabel)
Loaded = True
Me.Size = Globals.FormSize
'Check if the system is already set up
Try
Dim response = Globals.API("GET", "setup", Nothing)
Catch ex As WebException
Dim rep As HttpWebResponse = ex.Response
Using rdr As New StreamReader(rep.GetResponseStream())
Dim Modal As New BaseModal With {
.Title = "Error",
.Message = rep.StatusCode & ": " & rdr.ReadToEnd()
}
Modal.ShowDialog()
End Using
Me.GoToForm(New DeanSetup)
End Try
End Sub
Protected Sub ForgotPassword_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If Me.Loaded Then
Dim i As Integer = 0
For Each Control As Control In Me.FormPanel.Controls
If Control.Name = "Logo" Then
Dim Logo As PictureBox = Control
Dim resourcesManager As ResourceManager = My.Resources.ResourceManager
Dim LogoImage As Image = resourcesManager.GetObject("CdMSMS-ICS Logo")
Logo.Image = LogoImage
Logo.Size = New Size(Me.FormPanel.Width, CInt(LogoImage.Height * (Me.FormPanel.Width / LogoImage.Width)))
End If
Control.Margin = New Padding(
(Me.FormPanel.Width - Control.Width) * 0.5,
0,
0,
0
)
If i > 0 Then
Control.Margin = New Padding(
Control.Margin.Left,
Globals.Unit(1),
0,
0
)
End If
i = i + 1
Next
Dim j As Integer = 0
For Each Control As Control In Me.MainFormPanel.Controls
Control.Margin = New Padding(
(Me.MainFormPanel.Width - Control.Width) * 0.5,
0,
0,
Globals.Unit(1)
)
Control.Margin = New Padding(
Control.Margin.Left,
0,
0,
Globals.Unit(1)
)
j = j + 1
Next
Me.MainFormPanel.Controls(Me.MainFormPanel.Controls.Count - 1).Margin = New Padding(
Me.MainFormPanel.Controls(Me.MainFormPanel.Controls.Count - 1).Margin.Left,
0,
0,
0
)
Me.FormPanel.Location = New Point(
CInt(Me.Width * 0.5 - Me.FormPanel.Width * 0.5),
CInt(Me.Height * 0.5 - Me.FormPanel.Height * 0.5)
)
Dim Background As New Bitmap(Me.Width, Me.Height)
Dim HalfTrapezoid = Globals.LoadSvgFromResource("Half Trapezoid").Draw()
Dim BarCompliment_Top = Globals.LoadSvgFromResource("Bar Complement").Draw()
Dim Bar_Top = Globals.LoadSvgFromResource("Bar").Draw()
Dim BarCompliment_Bottom = Globals.LoadSvgFromResource("Bar Complement Bottom").Draw()
Dim Bar_Bottom = Globals.LoadSvgFromResource("Bar Bottom").Draw()
Using g As Graphics = Graphics.FromImage(Background)
g.DrawImage(
BarCompliment_Top,
-CInt(Me.Width * 0.25),
-CInt(Globals.Unit(12)),
CInt(Globals.Unit(13)),
CInt(Globals.Unit(15))
)
g.DrawImage(
Bar_Top,
CInt(Me.Width - Bar_Top.Width),
-CInt(Globals.Unit(12)),
CInt(Globals.Unit(13)),
CInt(Globals.Unit(15))
)
g.DrawImage(
BarCompliment_Bottom,
0,
CInt(Me.Height * 0.75),
CInt(Globals.Unit(13)),
CInt(Globals.Unit(15))
)
g.DrawImage(
Bar_Bottom,
CInt(Me.Width * 0.75),
CInt(Me.Height * 0.75),
CInt(Globals.Unit(13)),
CInt(Globals.Unit(15))
)
End Using
Me.BackgroundBitmap = Background
End If
End Sub
End Class