-
Notifications
You must be signed in to change notification settings - Fork 0
/
Profile.aspx.cs
167 lines (150 loc) · 4.74 KB
/
Profile.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SS.Service;
using SS.Model;
using log4net;
public partial class ProfileEdit : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request["reset"] != null)
{
lnkPassword_Click(null, null);
}
User user = UserService.GetUser(CurrentUser.Id);
txtEmail.Text = user.EMail;
txtFullName.Text = user.FullName;
txtPhone.Text = user.PhoneNumber;
}
}
protected void lnkPassword_Click(object sender, EventArgs e)
{
pnlProfie.Visible = false;
pnlPassword.Visible = true;
lnkProfile.Visible = true;
lnkPassword.Visible = false;
}
protected void lnkProfile_Click(object sender, EventArgs e)
{
pnlProfie.Visible = true;
pnlPassword.Visible = false;
lnkPassword.Visible = true;
lnkProfile.Visible = false;
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("~/Default.aspx");
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
SaveUser();
((BaseMaster)MasterPage).ShowInfoMessage("User Profile Updated");
}
}
protected void btnCancelPassword_Click(object sender, EventArgs e)
{
Response.Redirect("~/Default.aspx");
}
protected void btnSavePassword_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string message;
if (!UserService.ChangePassword(CurrentUser, txtCurrentPassword.Text, txtNewPassword.Text, out message))
{
NewPasswordValidator.ErrorMessage = "Your new Password is not strong enough - " + message;
NewPasswordValidator.IsValid = false;
}
else
{
bool redirect = (!CurrentUser.IsApproved);
CurrentUser.IsApproved = true;
UserService.UpdateUser(CurrentUser);
((BaseMaster)MasterPage).ShowInfoMessage("Your Password was changed");
if (redirect)
{
Response.Redirect("~/Default.aspx");
}
else
{
lnkProfile_Click(null, null);
}
}
}
}
private void SaveUser()
{
if (Page.IsValid)
{
CurrentUser.EMail = txtEmail.Text;
CurrentUser.FullName = txtFullName.Text;
CurrentUser.PhoneNumber = txtPhone.Text;
UserService.UpdateUser(CurrentUser);
}
}
protected void NewPasswordValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator sender = (CustomValidator)source;
args.IsValid = true;
if (String.IsNullOrEmpty(txtNewPassword.Text))
{
sender.ErrorMessage = "New password cannot be empty";
args.IsValid = false;
}
string msg = string.Empty;
if (!UserService.ValidatePassword(txtNewPassword.Text, out msg))
{
sender.ErrorMessage = msg;
args.IsValid = false;
}
}
protected void CurrentPasswordValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator sender = (CustomValidator)source;
string password = UserService.DecodePassword(CurrentUser.EMail);
if (password != txtCurrentPassword.Text)
{
sender.ErrorMessage = "The Current Password is not correct";
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
protected void ConfirmValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator sender = (CustomValidator)source;
if (txtNewPassword.Text != txtConfirm.Text)
{
sender.ErrorMessage = "New Passwords do not match";
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
protected void EmailValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
CustomValidator sender = (CustomValidator)source;
SS.Model.User u = UserService.GetUser(txtEmail.Text);
if (u.EMail != CurrentUser.EMail)
{
sender.ErrorMessage = "The email entered has been used, please enter a new email address";
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
}