My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
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
/*
* Ra-Ajax - A Managed Ajax Library for ASP.NET and Mono
* Copyright 2008 - 2009 - Thomas Hansen thomas@ra-ajax.org
* This code is licensed under the GPL version 3 which
* can be found in the license.txt file on disc.
*
*/

using System;
using Entity;
using NHibernate.Expression;
using System.Collections.Generic;
using Ra.Widgets;
using System.Web;
using System.Text.RegularExpressions;
using Ra.Effects;

namespace RaWebsite
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Checking to see if this is a "confirm user" request
string newUserRegistration = Request.Params["idNewUser"];

if (newUserRegistration != null)
{
Operator oper = Operator.FindOne(
Expression.Eq("Username", newUserRegistration),
Expression.Eq("Confirmed", false));
if (oper != null)
{
oper.Confirmed = true;
oper.Save();
pnlConfirmRegistration.Visible = true;
newUserWelcome.InnerHtml = string.Format("Welcome as a new user {0}", oper.Username);
Operator.Login(oper.Username, oper.Pwd);
}
}

if (Request.Params["register"] != null)
Register();

if (Request.Params["editProfile"] != null && Operator.Current != null)
EditProfile();
}

// Checking to see if user is logged in
if (Request.Params["register"] == null && Request.Params["editProfile"] == null && Operator.Current == null)
{
pnlLogin.Visible = true;
if (!IsPostBack)
username.Focus();
}
}

protected void login_Click(object sender, EventArgs e)
{
if (Operator.Login(username.Text, pwd.Text))
{
pnlLogin.Visible = false;
if (remember.Checked)
{
HttpCookie rem = new HttpCookie("userId", username.Text);
rem.Expires = DateTime.Now.AddMonths(24);
Response.Cookies.Add(rem);
}
if (!string.IsNullOrEmpty(Request.Params["ReturnUrl"]))
Ra.AjaxManager.Instance.Redirect(Request.Params["ReturnUrl"]);
else
Ra.AjaxManager.Instance.Redirect("Default.aspx");
}
else
{
resultLabel.Text = "Couldn't log you in";
username.Focus();
username.Select();
new EffectFadeIn(resultLabel, 400).Render();
}
}

protected void register_Click(object sender, EventArgs e)
{
Register();
}

protected void finishRegister_Click(object sender, EventArgs e)
{
if (!ValidatePasswordMatch())
return;
else if (!ValidateEmailFormat())
return;
else if (!ValidateUsername())
return;
else
{
finishRegister.Enabled = false;
Operator oper = new Operator();
oper.Email = newEmail.Text;
oper.Pwd = newPassword.Text;
oper.Username = newUsername.Text;

oper.Save();
oper.SendEmail(
"Please confirm registration",
string.Format(
@"This message was automatically sent from the forums at http://ra-ajax.org due to registering a new user.
If you where not the one registering at Ra-Ajax then please just ignore this message or delete it.

To confirm your registration and activate your user account please go to:
{0}?idNewUser={1}

Your username is: {1}
Your password is: {2}

Have a nice day :)",
Request.Url.ToString().Remove(Request.Url.ToString().IndexOf(Request.Url.Query)),
oper.Username,
oper.Pwd));
new EffectFadeOut(pnlRegister, 400).Render();
resultLabel.Text = "Thanks for registering. A message has been sent to your email to comfirm registration. We hope you enjoy using Ra-Ajax.";
new EffectFadeIn(resultLabel, 400).Render();
}
}

private bool ValidateEmailFormat()
{
bool retVal = !(string.IsNullOrEmpty(newEmail.Text) ||
!Regex.IsMatch(newEmail.Text, @"^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25}$", RegexOptions.Compiled));

if (!retVal)
{
resultLabel.Text = "The Email is not in a correct format.";
new EffectFadeIn(resultLabel, 400).Render();
newEmail.Focus();
}
return retVal;
}

private bool ValidatePasswordMatch()
{
bool retVal = newPassword.Text == newPasswordRepeat.Text;
if (!retVal)
{
newPassword.Text = "";
newPasswordRepeat.Text = "";

resultLabel.Text = "Passwords didn't match.";
new EffectFadeIn(resultLabel, 400).Render();

new EffectHighlight(newPassword, 1000).ChainThese(
new EffectTimeout(200),
new EffectHighlight(newPassword, 1000)
).Render();

new EffectHighlight(newPasswordRepeat, 1000).ChainThese(
new EffectTimeout(200),
new EffectHighlight(newPasswordRepeat, 1000)
).Render();

newPassword.Style["background-color"] = "#f66";
newPasswordRepeat.Style["background-color"] = "#f66";
newPassword.Focus();
}
return retVal;
}

private bool ValidateUsername()
{
bool retVal = !string.IsNullOrEmpty(newUsername.Text) &&
Operator.FindOne(Expression.Eq("Username", newUsername.Text)) == null;

if (string.IsNullOrEmpty(newUsername.Text))
{
resultLabel.Text = "Please enter a Username.";
new EffectFadeIn(resultLabel, 400).Render();

new EffectHighlight(newUsername, 1000).ChainThese(
new EffectTimeout(200),
new EffectHighlight(newUsername, 1000)
).Render();

newUsername.Style["background-color"] = "#f66";
newUsername.Focus();
}
else if (Operator.FindOne(Expression.Eq("Username", newUsername.Text)) != null)
{
resultLabel.Text = "This Username already exists, please choose a different Username.";
new EffectFadeIn(resultLabel, 400).Render();
newUsername.Focus();
}
return retVal;
}

protected void btnChangeProfile_Click(object sender, EventArgs e)
{
if (changePassword.Text != changePasswordConfirm.Text)
{
changePassword.Text = "";
changePasswordConfirm.Text = "";
resultLabel.Text = "Passwords didn't match.";
new EffectFadeIn(resultLabel, 400).Render();
changePassword.Focus();
return;
}
else if (string.IsNullOrEmpty(changeEmail.Text) ||
!Regex.IsMatch(changeEmail.Text, @"^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25}$", RegexOptions.Compiled))
{
resultLabel.Text = "The Email is not in a correct format.";
new EffectFadeIn(resultLabel, 400).Render();
changeEmail.Focus();
return;
}
btnChangeProfile.Enabled = false;
Operator.Current.Pwd = changePassword.Text;
Operator.Current.Signature = changeSignature.Text;
Operator.Current.Email = changeEmail.Text;
Operator.Current.Save();

new EffectFadeOut(pnlProfile, 400).Render();
resultLabel.Text = "Your profile was updated successfully.";
new EffectFadeIn(resultLabel, 400).Render();
}

private void Register()
{
if (Operator.Login(username.Text, pwd.Text))
{
pnlLogin.Visible = false;
}
else
{
pnlRegister.Visible = true;
pnlRegister.Style["display"] = "";
newUsername.Focus();
newUsername.Select();

// Fading in/out panels...
Effect effect = new EffectFadeOut(pnlLogin, 600);
effect.Render();
effect = new EffectFadeIn(pnlRegister, 600);
effect.Render();

newUsername.Text = username.Text;
newUsername.Focus();
newUsername.Select();
newPassword.Text = pwd.Text;
newPasswordRepeat.Text = pwd.Text;
}
}

private void EditProfile()
{
pnlProfile.Visible = true;
pnlProfile.Style["display"] = "";
new EffectFadeIn(pnlProfile, 400).Render();

changePassword.Text = Operator.Current.Pwd;
changePassword.Focus();
changePassword.Select();
changePasswordConfirm.Text = Operator.Current.Pwd;
changeSignature.Text = Operator.Current.Signature;
changeEmail.Text = Operator.Current.Email;
}
}
}



























Change log

r1540 by polterguy on Jul 14, 2009   Diff
Carriage return fixing...
Go to: 
Project members, sign in to write a code review

Older revisions

r1532 by kariem.elkoush on Jun 24, 2009   Diff
[No log message]
r1527 by kariem.elkoush on Jun 22, 2009   Diff
[No log message]
r1525 by kariem.elkoush on Jun 19, 2009   Diff
[No log message]
All revisions of this file

File info

Size: 10240 bytes, 296 lines
Powered by Google Project Hosting