Hi this is my Login Controller for the Login page and I have done everything to check and login however I have not made the Login Session so my website does not know whoever login using the IDs and Password from the database. So the website only recognizes one user even after the login has been made.
I also need to know how to retrieve the login session if I am to make a selection using a button. For example; "User Z selected WorkSchedule
A *after logging in with User Z's username and password"
A login wouldn't be complete if there is no saved session for the website, I have troubles making the save session and would appreciate if someone could guide me towards making it.
Controller code:
[HttpGet]
public ActionResult Login()
{
return View();
}
void connectionString()
{
con.ConnectionString = " ";
}
[HttpPost]
public ActionResult SaveData(Account acc)
{
connectionString();
con.Open();
com.Connection = con;
com.CommandText = "insert into Staff (StaffNRIC,StaffEmail,StaffContact,StaffName,StaffAddress,BranchID,StaffRole,StaffPositionID,StaffAccountStatus)" +
"values ('" + acc.StaffNRIC + "','" + acc.StaffEmail + "','" + acc.StaffContact + "','" + acc.StaffName + "','" + acc.StaffAddress + "','" + acc.BranchID + "',' NULL ','" + acc.StaffPositionID + "', 'Pending' )";
dr = com.ExecuteReader();
if (dr.Read())
{
con.Close();
return View("Register");
}
else
{
con.Close();
return View("Login");
}
}
[HttpPost]
public ActionResult Verify(Account acc)
{
connectionString();
con.Open();
com.Connection = con;
com.CommandText = "select * from Staff where StaffNRIC='" + acc.StaffNRIC + "' and StaffContact='" + acc.StaffContact + "' and StaffAccountStatus = 'Approved'";
dr = com.ExecuteReader();
if (dr.Read())
{
con.Close();
return View("Home");
}
else
{
con.Close();
return View("Login");
}
}
View Page:
<form action="Verify" method="post">
<div class=" w3l-form-group">
<label>NRIC:</label>
<div class="group">
<i class="fas fa-user"></i>
<input type="text" name="StaffNRIC" class="form-control" placeholder="StaffNRIC" required="required">
</div>
</div>
<div class=" w3l-form-group">
<label>Password:</label>
<div class="group">
<i class="fas fa-unlock"></i>
<input type="password" name="StaffContact" class="form-control" placeholder="StaffContact" required="required">
</div>
</div>
<button type="submit">Login</button>
</form>
</div>