[HttpPost]
public IActionResult AppUserLogin(AppUser user)
{
string? connectionString = _configuration.GetConnectionString(ConnectionStringKey);
MySqlConnection connection = new MySqlConnection(connectionString);
try
{
connection.Open();
string sqlLogin = "SELECT Email,Password FROM AppUser WHERE Email= @Email AND password @Password ";
MySqlCommand command = new MySqlCommand(sqlLogin, connection);
command.Parameters.AddWithValue("@Email", user.Email);
command.Parameters.AddWithValue("@Password", user.Password);
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
if (ModelState.IsValid)
{
user.Id = reader["Id"].ToString();
//user.Email = usr.Email;
TempData["Msg"] = "Successfully login!";
}
}
}
else
{
TempData["msg"] = "Unexpected Database Error";
}
connection.Close();
}
catch (Exception ex)
{
TempData["Msg"] = "Incorrect email or password" + ex.Message;
}
//if (ModelState.IsValid)
//{
//}
//else
//{
// TempData["msg"] = "Invalid information entered!";
//}
return RedirectToAction("Main");
}