I need to create a login system, I have been able to do the registration part and the login part, but I am not able to create the part for the user to leave the session (exit the system).
Note: I have a repository with the SQL commands
Could someone help me with how to do this part?
I am using the Entity Framework and I do it by database first
Here is my controller
public class AccountUserController : Controller
{
private clsContext cnn = new clsContext();
public ActionResult Index()
{
clsUserRepository usu = new clsUserRepository(cnn);
return View(usu.AccountList());
}
public ActionResult Register()
{
return View();
}
[HttpPost]
public ActionResult Register(clsAccountUser userObj)
{
if (ModelState.IsValid)
{
clsUserRepository usu = new clsUserRepository(cnn);
usu.Register(userObj);
cnn.SaveChanges();
ModelState.Clear();
ViewBag.Message = userObj.usuNome + " " +"Successfully registered!";
}
return View();
}
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(clsAccountUser userObj)
{
cclsUserRepository usu = new clsUserRepository(cnn);
if (usu.Login(userObj) == 2)
{
Session["Logged"] = usu.Login(userObj);
return RedirectToAction("Logged");
}
else if(usu.Login(userObj) == 1)
{
ViewBag.Message = "Invalid username and password";
}
else
{
ViewBag.Message = "RE: " + userObj.usuRe + " Invalid" ;
}
return View();
}
public ActionResult Logged(clsAccountUser usuarioObj)
{
if(Convert.ToInt32(Session["Logged"]) != 0)
{
return View();
}
else
{
return RedirectToAction("Login");
}
}
}
}