Skip to content

Commit 7e0e06c

Browse files
committed
Enforced session-based authentication to restrict access to protected pages before user/admin login.
1 parent b861d02 commit 7e0e06c

25 files changed

+197
-23
lines changed

WebApplication2/Customer/Pages/CustomerComponent.aspx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,18 @@
736736
});
737737
738738
function logout() {
739-
// Clear the active section
740-
sessionStorage.removeItem('activeSection');
739+
// Clear the session variable
740+
sessionStorage.clear();
741+
// Send a POST request to the logout endpoint
742+
fetch('logout.aspx', { method: 'POST' })
743+
.then(response => {
744+
if (response.redirected) {
745+
window.location.href = response.url;
746+
}
747+
});
741748
}
742749
750+
743751
// Function to show the pop-up
744752
function showPopup() {
745753
document.getElementById('hintPopup').style.display = 'block';

WebApplication2/Customer/Pages/CustomerComponent.aspx.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ protected void Page_Load(object sender, EventArgs e)
1616
{
1717
string connStr = WebConfigurationManager.ConnectionStrings["Milestone2DB_24"].ToString();
1818
// Example input values, replace with actual inputs from user or session
19-
MobileNo = Session["accountmn"] as String;
20-
//int NationalID = 2; // Example NationalID
21-
string PlanName = "Splan1"; // Example PlanName
22-
23-
//// ShowConsoleMessage("Retrieving all active benefits...");
24-
ShowAllServicePlans(connStr);
19+
20+
if (Session["accountmn"] == null)
21+
{
22+
// Redirect to the login page if not authenticated
23+
Response.Redirect("/Customer/Pages/login.aspx");
24+
}
25+
else
26+
{
27+
MobileNo = Session["accountmn"] as String;
28+
}
29+
// ShowConsoleMessage("Retrieving all active benefits...");
30+
ShowAllServicePlans(connStr);
2531
ShowAllBenefits(connStr);
2632
ShowAllShops(connStr);
2733
ShowCompanyOfferedPlans(connStr, MobileNo);

WebApplication2/Customer/Pages/login.aspx.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ protected void loginm(object sender, EventArgs e)
3535
string accountmn = mnumber.Text.Trim();
3636
string pass = password.Text.Trim();
3737

38-
Session["accountmn"]= accountmn;
39-
4038
// Validate inputs
4139
if (string.IsNullOrEmpty(accountmn) || string.IsNullOrEmpty(pass))
4240
{
@@ -45,8 +43,6 @@ protected void loginm(object sender, EventArgs e)
4543
return;
4644
}
4745

48-
49-
5046
try
5147
{ // Open connection
5248
sqlConnection.Open();

WebApplication2/Pages/AverageTransactions/AverageTransactions.aspx.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ public partial class AverageTransactions : System.Web.UI.Page
1111
{
1212
protected void Page_Load(object sender, EventArgs e)
1313
{
14-
14+
if (Session["adminID"] == null)
15+
{
16+
// Redirect to the login page if not authenticated
17+
Response.Redirect("/Pages/Login/Login.aspx");
18+
}
1519
}
1620

1721
private void LoadData(string walletId, string startDate, string endDate)

WebApplication2/Pages/Cashbacks/Cashbacks.aspx.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ public partial class Cashbacks : System.Web.UI.Page
1414
{
1515
protected void Page_Load(object sender, EventArgs e)
1616
{
17+
if (Session["adminID"] == null)
18+
{
19+
// Redirect to the login page if not authenticated
20+
Response.Redirect("/Pages/Login/Login.aspx");
21+
}
22+
1723
if (!IsPostBack)
1824
{
1925
LoadData();

WebApplication2/Pages/Eshops/Eshops.aspx.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ public partial class Eshops : System.Web.UI.Page
1414
{
1515
protected void Page_Load(object sender, EventArgs e)
1616
{
17+
if (Session["adminID"] == null)
18+
{
19+
// Redirect to the login page if not authenticated
20+
Response.Redirect("/Pages/Login/Login.aspx");
21+
}
22+
1723
if (!IsPostBack)
1824
{
19-
LoadData();
25+
LoadData();
2026
}
2127
}
2228
private void LoadData()

WebApplication2/Pages/Home/Home.aspx.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ public partial class Home : System.Web.UI.Page
1111
{
1212
protected void Page_Load(object sender, EventArgs e)
1313
{
14+
if (Session["adminID"] == null)
15+
{
16+
// Redirect to the login page if not authenticated
17+
Response.Redirect("/Pages/Login/Login.aspx");
18+
}
1419

1520
}
1621
}

WebApplication2/Pages/Login/Login.aspx.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ protected void LoginButton(object sender, EventArgs e)
1919

2020
if ((username == "58-1034" && password == "1234") || (username == "58-25160" && password == "1234") || (username == "58-12345" && password == "admin"))
2121
{
22+
Session["adminID"] = username;
2223
Response.Redirect("/Pages/Home/Home.aspx");
2324
}
2425
else

WebApplication2/Pages/MobileSearch/MobileSearch.aspx.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ public partial class MobileSearch : System.Web.UI.Page
1212
{
1313
protected void Page_Load(object sender, EventArgs e)
1414
{
15-
15+
if (Session["adminID"] == null)
16+
{
17+
// Redirect to the login page if not authenticated
18+
Response.Redirect("/Pages/Login/Login.aspx");
19+
}
1620
}
1721

1822
private void LoadData(string mobileNumber) // Corrected parameter

WebApplication2/Pages/PaymentPoints/PaymentPoints.aspx.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ public partial class PaymentPoints : System.Web.UI.Page
1414
{
1515
protected void Page_Load(object sender, EventArgs e)
1616
{
17-
17+
if (Session["adminID"] == null)
18+
{
19+
// Redirect to the login page if not authenticated
20+
Response.Redirect("/Pages/Login/Login.aspx");
21+
}
1822
}
1923
private void LoadData(string mobileNum) // Accept mobile number as parameter
2024
{

0 commit comments

Comments
 (0)