-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMasterPage.master.cs
199 lines (187 loc) · 6.8 KB
/
MasterPage.master.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
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TQO_Classes;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
//resetting captcha validation
if (!Page.IsPostBack)
{
Session["CaptchaKey"] = null;
}
if (Session["UserID"] == null)
MultiView1.ActiveViewIndex = 0;
else
MultiView1.ActiveViewIndex = 1;
if (Session["UserName"] != null)
{
lblUsername.Text = Session["UserName"].ToString();
}
}
protected void btnLogin_Click(object sender, ImageClickEventArgs e)
{
int LoginAttempts = 0;
if (Session["LoginAttempts"] == null)
{
LoginAttempts = 1;
Session["LoginAttempts"] = LoginAttempts;
}
else
{
//Increment the Login attempts
LoginAttempts = int.Parse(Session["LoginAttempts"].ToString()) + 1;
Session["LoginAttempts"] = LoginAttempts;
}
try
{
UserBase userBase = new UserBase();
userBase.Email = txtEmail.Text;
userBase.Password = txtPassword.Text;
IUser user = userBase.Login(LoginAttempts);
if (user != null)
{
Session["UserID"] = user.UserID;
Session["UserName"] = user.FirstName;
Session["LoginAttempts"] = null;
if (user.RoleTypeID == 2)
{
//Create Unique Nonce for security when landing back from email box
Nonce nonce = new Nonce();
nonce.UserID = user.UserID;
nonce.NonceID = Guid.NewGuid();
nonce.IsUsed = false;
nonce.Add();
Session.Clear();
Session.Abandon();
Response.Redirect(TQO_Classes.Utility.DomainList.ClientSiteURL() +
"/Secured/Default.aspx?UID=" + nonce.UserID.ToString() + "&NID=" + nonce.NonceID.ToString(), false);
}
else if (user.RoleTypeID == 3)
{
Response.Redirect("~/Secured/AdminManager.aspx", false);
}
else if (user.RoleTypeID == 4)
{
Response.Redirect("~/Secured/SuperAdminManager.aspx", false);
}
else if (user.RoleTypeID == 5)
{
Response.Redirect("~/GenericPages/AccessDenied.aspx?ErrorType=IncompleteRegistration", false);
}
else
{
Response.Redirect("~/Login.aspx?Error=Login+failed", false);
}
}
else
{
Response.Redirect("~/Login.aspx?Error=Login+failed", false);
}
}
catch(Exception ex)
{
if (ex.Message == "Login attempts exceeded.")
{
//captcha time
Random ran = new Random();
imgCaptcha.ImageUrl = "customcontrols/captchagenerator.aspx?Id=" + ran.Next(1, 9).ToString();
txtCaptcha.Text = "...repeat text";
pnlCaptcha.Visible = true;
}
else if (ex.Message == "Applicant cannot Login at this time")
{
//account verification incomplete
Notification.Message = "Login Failed, please Login to your email box and click on the TheQOffice Link";
Notification.Show();
}
else
{
Notification.Message = "Could not log you in, please try again!";
Notification.Show();
}
}
}
protected void btnLogout_Click(object sender, EventArgs e)
{
Session.Clear();
Session.Abandon();
Response.Redirect("~/Default.aspx");
}
protected void btnAccount_Click(object sender, EventArgs e)
{
if(Session["UserID"] != null)
{
UserBase user = new UserBase();
user.UserID = new Guid(Session["UserID"].ToString());
user.Load();
user = user.LoadedItem;
if (user.RoleTypeID == 2)
{
//Create Unique Nonce for security when landing back from email box
Nonce nonce = new Nonce();
nonce.UserID = user.UserID;
nonce.NonceID = Guid.NewGuid();
nonce.IsUsed = false;
nonce.Add();
Session.Clear();
Session.Abandon();
Response.Redirect(TQO_Classes.Utility.DomainList.ClientSiteURL() +
"/Secured/Default.aspx?UID=" + nonce.UserID.ToString() + "&NID=" + nonce.NonceID.ToString(), false);
}
else if (user.RoleTypeID == 3)
{
Response.Redirect("~/Secured/AdminManager.aspx", false);
}
else if (user.RoleTypeID == 4)
{
Response.Redirect("~/Secured/SuperAdminManager.aspx", false);
}
else if (user.RoleTypeID == 5)
{
Response.Redirect("~/GenericPages/AccessDenied.aspx?ErrorType=IncompleteRegistration&UID=" + user.UserID.ToString(), false);
}
else if (user.RoleTypeID == 6)
{
Response.Redirect("~/Secured/AdminManager.aspx", false);
}
else if (user.RoleTypeID == 7)
{
Response.Redirect("~/Secured/AdminManager.aspx", false);
}
else
{
Response.Redirect("~/Login.aspx?Error=Login+failed", false);
}
}
}
protected void btnCaptcha_Click(object sender, EventArgs e)
{
if (Session["CaptchaKey"] != null)
{
if (Session["CaptchaKey"].ToString().ToLower() == txtCaptcha.Text.ToLower())
{
Session["LoginAttempts"] = 2;
pnlCaptcha.Visible = false;
Notification.Message = "Having login problems? try password recovery";
Notification.Show();
}
else
{
lblCaptcha.Text = "VERIFICATION FAILED, PLEASE TRY AGAIN!";
txtCaptcha.Text = "...repeat text";
Random ran = new Random();
imgCaptcha.ImageUrl = "customcontrols/captchagenerator.aspx?Id=" + ran.Next(1, 9).ToString();
}
}
}
}