/
index.aspx.cs
146 lines (140 loc) · 5.23 KB
/
index.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CAPRES.ValueObjects;
using CAPRES.BusinessLogicObjects;
using System.Data;
using System.Diagnostics;
namespace CAPRES
{
public partial class index : System.Web.UI.Page
{
private CandidateVO candidateVO = new CandidateVO();
private CandidateBLO candidateBLO = new CandidateBLO();
private HRVO hrVO = new HRVO();
private HRBLO hrBLO = new HRBLO();
protected void Page_PreInit(object sender, EventArgs e)
{
if (Session["Candidate"] != null || Request.Cookies["Candidate"] != null)
{
CheckCandidateLogin();
}
else if (Session["HR"] != null || Request.Cookies["HR"] != null)
{
CheckHRLogin();
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
private void CheckCandidateLogin()
{
List<string> list = (List<string>)Session["Candidate"];
string status = list == null
? Request.Cookies["Candidate"]["Status"] : list[1];
if (status.Equals("applicant") || status.Equals("pending"))
{
Response.Redirect("ApplicantHome.aspx");
}
else if (status.Equals("preboarding"))
{
Response.Redirect("PreboardingHome.aspx");
}
else if (status.Equals("hiring"))
{
Response.Redirect("HiringHome.aspx");
}
}
private void CheckHRLogin()
{
List<string> list = (List<string>)Session["HR"];
string type = list == null
? Request.Cookies["HR"]["Type"] : list[1];
if (type.Equals("recruiter"))
{
Response.Redirect("RecruiterHome.aspx");
}
else if (type.Equals("preboarder"))
{
Response.Redirect("PreboarderHome.aspx");
}
else if (type.Equals("datamanager"))
{
Response.Redirect("DataManagerHome.aspx");
}
else if (type.Equals("admin"))
{
Response.Redirect("AdminHome.aspx");
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
try
{
string username = txtUsername.Text.Trim();
string password = txtPassword.Text.Trim();
int candidateId;
if (int.TryParse(username, out candidateId) == true)
{
candidateVO = candidateBLO.AuthenticateCandidate(candidateId, password);
if (candidateVO != null)
{
if (chkRemember.Checked)
{
HttpCookie cookie = new HttpCookie("Candidate");
cookie.Values["ID"] = candidateVO.CandidateId.ToString();
cookie.Values["Status"] = candidateVO.Status.ToString();
cookie.Expires = DateTime.Now.AddYears(1);
//cookie.Secure = true;
Response.Cookies.Add(cookie);
}
List<string> list = new List<string>();
list.Add(candidateVO.CandidateId.ToString());
list.Add(candidateVO.Status.ToString());
Session.Add("Candidate", list);
CheckCandidateLogin();
}
else
{
lblError.Text = "Candidate login failed.";
}
}
else
{
hrVO = hrBLO.AuthenticateHR(username, password);
if (hrVO != null)
{
if (chkRemember.Checked)
{
HttpCookie cookie = new HttpCookie("HR");
cookie.Values["Email"] = hrVO.Email.ToString();
cookie.Values["Type"] = hrVO.Type.ToString();
cookie.Expires = DateTime.Now.AddYears(1);
//cookie.Secure = true;
Response.Cookies.Add(cookie);
}
List<string> list = new List<string>();
list.Add(hrVO.Email.ToString());
list.Add(hrVO.Type.ToString());
Session.Add("HR", list);
CheckHRLogin();
}
else
{
lblError.Text = "HR login failed.";
}
}
}
catch(Exception e1)
{
lblError.Text = "Login failed. Please try again";
Debug.WriteLine("Login Exception Type: " + e1.GetType() +
"\nMessage: " + e1.Message +
"\nStack Trace: " + e1.StackTrace);
}
}
}
}