-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmLogin.pas
261 lines (227 loc) · 7.26 KB
/
frmLogin.pas
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
unit frmLogin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, uLoginFormManager, jpeg, uAutoDroneDeployment,
uHelp, uLibrary;
type
TLoginForm = class(TForm)
imgBackground: TImage;
pnlLogin: TPanel;
pnlRegister: TPanel;
ledEmail: TLabeledEdit;
ledPassword: TLabeledEdit;
btnLogin: TButton;
btnSignUp: TButton;
cbxStaff: TCheckBox;
btnShowHide: TButton;
ledFirstName: TLabeledEdit;
ledSurname: TLabeledEdit;
ledPasswordSignUp: TLabeledEdit;
cbxSuburbs: TComboBox;
ledPasswordConfirm: TLabeledEdit;
ledEmailSignUp: TLabeledEdit;
ledEmailConfirm: TLabeledEdit;
lblSuburbs: TLabel;
ledAddressLine1: TLabeledEdit;
btnRegister: TButton;
btnAlreadyRegistered: TButton;
lblRecommenedSuburb: TLabel;
tmrAuto: TTimer;
btnHelpLogin: TButton;
btnHelpRegister: TButton;
lblForgotPass: TLabel;
procedure btnShowHideClick(Sender: TObject);
procedure btnLoginClick(Sender: TObject);
procedure btnSignUpClick(Sender: TObject);
procedure btnAlreadyRegisteredClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnRegisterClick(Sender: TObject);
procedure lblRecommenedSuburbClick(Sender: TObject);
procedure ledPasswordKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure tmrAutoTimer(Sender: TObject);
procedure btnHelpLoginClick(Sender: TObject);
procedure btnHelpRegisterClick(Sender: TObject);
procedure lblForgotPassClick(Sender: TObject);
private
{ Private declarations }
procedure LoginUser;
procedure ClearForm;
public
{ Public declarations }
end;
var
LoginForm: TLoginForm;
implementation
{$R *.dfm}
procedure TLoginForm.btnHelpLoginClick(Sender: TObject);
begin
LoginHelp;
end;
procedure TLoginForm.btnHelpRegisterClick(Sender: TObject);
begin
SignUpHelp;
end;
procedure TLoginForm.btnLoginClick(Sender: TObject);
begin
LoginUser;
end;
procedure TLoginForm.btnRegisterClick(Sender: TObject);
var
sName, sSurname, sEmail, sPassword, sAddressLine1, sSuburbAndCode,
sSuburb, sPostCode, sRetypedPass, sRetypedEmail : string;
iPos : byte;
begin
sPassword := Trim(ledPasswordSignUp.Text);
sName := Trim(ledFirstName.Text);
sSurname := Trim(ledSurname.Text);
sEmail := Trim(ledEmailSignUp.Text);
sAddressLine1 := Trim(ledAddressLine1.Text);
sSuburbAndCode := Trim(cbxSuburbs.Items[cbxSuburbs.ItemIndex]);
sRetypedPass := Trim(ledPasswordConfirm.Text);
sRetypedEmail := Trim(ledEmailConfirm.Text);
iPos := POS(',', sSuburbAndCode);
sSuburb := Copy(sSuburbAndCode, 1, iPos - 1);
Delete(sSuburbAndCode, 1, iPos + 1);
sPostCode := sSuburbAndCode;
if RequiredFieldsFilled(sName, sSurname, sEmail, sRetypedEmail,
sPassword, sRetypedPass, sAddressLine1, sSuburb, sPostCode) =
true then
if PasswordCriteriaMet(sPassword) = true then
if FieldsConfirmed(sPassword, sRetypedPass, sEmail, sRetypedEmail) =
true then
if EmailVerified(sEmail) = true then
RegisterNewUser(sName, sSurname, sEmail, sPassword, sAddressLine1,
sSuburb, sPostCode, Self);
end;
procedure TLoginForm.btnShowHideClick(Sender: TObject);
begin
if ledPassword.PasswordChar = '*' then
begin
ledPassword.PasswordChar := #0;
btnShowHide.Caption := 'Hide';
end
else
begin
ledPassword.PasswordChar := '*';
btnShowHide.Caption := 'Show';
end;
end;
procedure TLoginForm.btnSignUpClick(Sender: TObject);
begin
pnlRegister.Visible := true;
pnlLogin.Visible := false;
ClearForm;
ledFirstName.SetFocus;
end;
//-------------------------------------CLEARS THE FORM AS IF IT WAS NEW
procedure TLoginForm.ClearForm;
begin
ledEmail.Clear;
ledPassword.Clear;
cbxStaff.Checked := false;
ledFirstName.Clear;
ledSurname.Clear;
ledEmailSignUp.Clear;
ledEmailConfirm.Clear;
ledPasswordSignUp.Clear;
ledPasswordConfirm.Clear;
ledAddressLine1.Clear;
cbxSuburbs.ItemIndex := 0;
end;
procedure TLoginForm.FormCreate(Sender: TObject);
begin
CreateObjs;
cbxSuburbs.Items.Text := PopulateSuburbDropDown;
cbxSuburbs.ItemIndex := 0;
CompleteFlights;
DeployDrones;
end;
procedure TLoginForm.FormShow(Sender: TObject);
begin
pnlLogin.Visible := true;
pnlRegister.Visible := false;
ClearForm;
ledEmail.SetFocus;
end;
procedure TLoginForm.lblForgotPassClick(Sender: TObject);
var
sEmail, sStaff : string;
bStaff : boolean;
begin
if MessageDlg('Have you forgot your password?', mtInformation, mbYesNo,
0) = mrYes then
begin
sEmail := InputBox('Birds Eye Security Surveillance', 'Please ' +
'enter the email your account is linked to.', '');
repeat
sStaff := InputBox('Birds Eye Security Surveillance', 'Are you part ' +
'of our staff? (Yes/No)', 'No');
until (UPPERCASE(sStaff) = 'YES') OR (UPPERCASE(sStaff) = 'NO');
bStaff := UPPERCASE(sStaff) = 'YES';
ForgotPass(sEmail, bStaff);
end;
end;
procedure TLoginForm.lblRecommenedSuburbClick(Sender: TObject);
var
sSuburb, sPostCode, sEmail : string;
begin
if MessageDlg('Is the suburb you wish to register for not listed?',
mtConfirmation, mbYesNo, 0) = mrYes then
begin
sSuburb := InputBox('Birds Eye Security Surveillance',
'Which suburb do you wish to signup for?', '');
sPostCode := InputBox('Birds Eye Security Surveillance', 'What is ' +
'the postal code of the suburb?', '');
while ValidatePostal(sPostCode) = false do
sPostCode := InputBox('Birds Eye Security Surveillance',
'You entered an invalid postal code, please enter your suburbs' +
' postal code.', '');
if AlreadyInSuburbs(sPostCode) = false then
begin
sEmail := InputBox('Birds Eye Security Surveillance', 'Please enter ' +
'your email', '');
while EmailVerified(sEmail) = false do
sEmail := InputBox('Birds Eye Security Surveillance', 'You ' +
'entered an invalid email, please enter a valid email.', '');
MessageDlg('Thank you for your interest in our service in your area.' +
' We shall contact you as soon as we are operational in your suburb.',
mtInformation, mbOKCancel, 0);
RecommendSuburb(sSuburb, sPostCode, sEmail);
end
else
MessageDlg('The area you wish to register for is already on the list' +
' of suburbs we operate in.', mtInformation, mbOKCancel, 0);
end;
end;
procedure TLoginForm.ledPasswordKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = 13 then
LoginUser;
end;
procedure TLoginForm.LoginUser;
var
sEmail, sPassword : string;
bStaff : boolean;
begin
sEmail := Trim(ledEmail.Text);
sPassword := Trim(ledPassword.Text);
bStaff := cbxStaff.Checked;
Login(sEmail, sPassword, bStaff, Self);
end;
procedure TLoginForm.tmrAutoTimer(Sender: TObject);
begin
DeployDrones;
CompleteFlights;
end;
procedure TLoginForm.btnAlreadyRegisteredClick(Sender: TObject);
begin
pnlLogin.Visible := true;
pnlRegister.Visible := false;
ClearForm;
ledEmail.SetFocus;
end;
end.