This repository has been archived by the owner on Jun 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Registration.aspx.cs
282 lines (249 loc) · 9.7 KB
/
Registration.aspx.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.Net.Mail;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLayer;
using Common;
using CommonLogging;
using SecurityLayer;
/// <summary>
/// Changelog:
/// 09-09-16 19:01 AskewR04 created page
/// </summary>
public partial class Registration : Page
{
/// <summary>
/// Load the page
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
(Application[GeneralConstants.LoggerApplicationStateKey] as Logger).Log(LoggingLevel.Info,
"Loaded Page " + Page.Title + ", " + Request.RawUrl);
lblErrorMessages.Text = string.Empty;
if (!IsPostBack)
{
txtEmail.MaxLength = GeneralConstants.EmailMaxLength;
txtLogin.MaxLength = GeneralConstants.LoginMaxLength;
txtPassword.MaxLength = GeneralConstants.PasswordMaxLength;
txtHomeNumber.MaxLength = GeneralConstants.HomeNumberMaxLength;
txtWorkNumber.MaxLength = GeneralConstants.WorkNumberMaxLength;
txtMobileNumber.MaxLength = GeneralConstants.MobileNumberMaxLength;
txtFirstName.MaxLength = GeneralConstants.FirstNameMaxLength;
txtLastName.MaxLength = GeneralConstants.LastNameMaxLength;
txtStreetAddress.MaxLength = GeneralConstants.StreetAddressMaxLength;
txtSuburb.MaxLength = GeneralConstants.SuburbMaxLength;
txtCity.MaxLength = GeneralConstants.CityMaxLength;
}
}
/// <summary>
/// Validate the first or last name, and post warnings if not valid
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void FirstLastNameValidation(object sender, ServerValidateEventArgs args)
{
Validation.ValidateAlphabeticInput(ref args);
if (!args.IsValid)
{
if (!lblErrorMessages.Text.Contains("First and Last Name should only have letters."))
lblErrorMessages.Text += "First and Last Name should only have letters. ";
}
}
/// <summary>
/// Validate the email, and post warnings if not valid
/// Email must be unique
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void EmailValidation(object sender, ServerValidateEventArgs args)
{
Validation.ValidateEmailInput(ref args);
if (!args.IsValid)
{
lblErrorMessages.Text += "Email should be a valid email address. ";
return;
}
var controller = new PublicController();
if (controller.EmailIsAlreadyInUse(args.Value))
{
args.IsValid = false;
lblErrorMessages.Text += "This Email is already in use. ";
}
}
/// <summary>
/// Validate the login, and post warnings if not valid
/// Login must be unique
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void LoginValidation(object sender, ServerValidateEventArgs args)
{
Validation.ValidateAlphaNumericInput(ref args);
if (!args.IsValid)
{
lblErrorMessages.Text += "Login should only be letters and numbers. ";
return;
}
var controller = new PublicController();
if (controller.LoginIsAlreadyInUse(args.Value))
{
args.IsValid = false;
lblErrorMessages.Text += "This Login is already in use. ";
}
}
/// <summary>
/// Validate the password, and post warnings if not valid
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void PasswordValidation(object sender, ServerValidateEventArgs args)
{
Validation.ValidatePasswordLength(ref args, 10);
if (!args.IsValid)
{
lblErrorMessages.Text += "Password minimum length is 10 characters. ";
}
}
/// <summary>
/// Check that at least one phone number field is filled out, and post warnings if not valid
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void ContactNumberRequired(object sender, ServerValidateEventArgs args)
{
if (txtHomeNumber.Text == string.Empty &&
txtWorkNumber.Text == string.Empty &&
txtMobileNumber.Text == string.Empty)
{
args.IsValid = false;
lblErrorMessages.Text += "At least one contact number is required. ";
lblErrorHomeNumberRequired.Text = "*";
lblErrorWorkNumberRequired.Text = "*";
lblErrorMobileNumberRequired.Text = "*";
}
else
{
lblErrorHomeNumberRequired.Text = "";
lblErrorWorkNumberRequired.Text = "";
lblErrorMobileNumberRequired.Text = "";
}
}
/// <summary>
/// Validate a land line number, and post warnings if not valid
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void LandlineNumberValidation(object sender, ServerValidateEventArgs args)
{
Validation.ValidateLandlineNumber(ref args);
if (!args.IsValid)
{
lblErrorMessages.Text +=
"Home and work numbers should be in a valid local landline format. Examples include 09555444, 0733337777. ";
}
}
/// <summary>
/// Validate a mobile number, and post warnings if not valid
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void MobileNumberValidation(object sender, ServerValidateEventArgs args)
{
Validation.ValidateMobileNumber(ref args);
if (!args.IsValid)
{
lblErrorMessages.Text +=
"Mobile Numbers should be in a valid mobile number format, in international or local form. ";
}
}
/// <summary>
/// Validate a street address, and post warnings if not valid
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void StreetAddressValidation(object sender, ServerValidateEventArgs args)
{
Validation.ValidateStreetAddress(ref args);
if (!args.IsValid)
{
lblErrorMessages.Text +=
"Street address is not valid. Valid examples are 123a Simpson St, or 5545 Carolina Ave.";
}
}
/// <summary>
/// Validate a suburb or city as a generic name, and post warnings if not valid
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void SuburbCityValidation(object sender, ServerValidateEventArgs args)
{
Validation.ValidateGenericName(ref args);
if (!args.IsValid)
{
lblErrorMessages.Text += "Suburb and City should only contain letters, commas, full stops and apostrophes. ";
}
}
/// <summary>
/// Complete the registration, by creating the new customer.
/// Email the customer upon completion.
/// And redirect to login page.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Register_Click(object sender, EventArgs e)
{
if (!Page.IsValid)
{
if (lblErrorMessages.Text == string.Empty)
{
lblErrorMessages.Text = "Please fill in the required fields. ";
}
}
else
{
var controller = new PublicController();
// email the Customer their new registration details.
try
{
var replyToEmail = controller.GetAvailableAdminEmail();
if (replyToEmail.Equals(string.Empty))
{
replyToEmail = GeneralConstants.AdminReplyToEmailDefault;
}
// add the registered user to the db.
controller.RegisterCustomer(txtFirstName.Text, txtLastName.Text, txtLogin.Text,
txtPassword.Text, txtEmail.Text, txtHomeNumber.Text, txtWorkNumber.Text,
txtMobileNumber.Text, txtStreetAddress.Text, txtSuburb.Text, txtCity.Text);
GeneralFunctions.SendEmail(txtEmail.Text,
GeneralConstants.EmailRegisteredCustomerSubject,
string.Format(
GeneralConstants.EmailRegisteredCustomerBody, txtFirstName.Text, txtLastName.Text,
txtLogin.Text, txtPassword.Text, txtHomeNumber.Text, txtWorkNumber.Text, txtMobileNumber.Text,
txtStreetAddress.Text, txtSuburb.Text, txtCity.Text),
replyToEmail);
}
catch (SmtpException smtpEx)
{
throw new Exception("Unable to send email in response to change in Customer password.", smtpEx);
}
var builder = new StringBuilder("~/Login.aspx");
builder.Append("?").Append(GeneralConstants.QueryStringGeneralMessageKey);
builder.Append("=").Append(GeneralConstants.QueryStringGeneralMessageSuccessfulRegistration);
Response.Redirect(builder.ToString());
}
}
/// <summary>
/// Manage errors, failure to register or send email.
/// </summary>
/// <param name="e"></param>
protected override void OnError(EventArgs e)
{
Session["lastError"] = Server.GetLastError();
(Application[GeneralConstants.LoggerApplicationStateKey] as Logger).Log(LoggingLevel.Error,
Server.GetLastError().Message + "; " + Request.RawUrl);
Response.Redirect("~/Error/Default");
}
}