// GET: LogOut public ActionResult Index() { Session.Abandon(); //Response.Cookies["LMSLogin"].Expires = DateTime.Now.AddDays(-1); //HttpCookie cookie = new HttpCookie("LMSLogin"); //cookie.Values.Add("UserName", LoggedInUser.UserName); //cookie.Values.Add("Password", string.Empty); //cookie.Expires = DateTime.Now.AddDays(15); //Response.Cookies.Add(cookie); LMSAudit lmsAudit = new LMSAudit(); UnitOfWork unitofwork = new UnitOfWork(); lmsAudit.TransactionDate = DateTime.Now; //lmsAudit.UserName = currentUser.UserName; //lmsAudit.FullName = currentUser.FullName; lmsAudit.UserName = LoggedInUser.UserName; lmsAudit.FullName = LoggedInUser.FullName; // make an entry in Audit table for user logging out lmsAudit.Section = "Logout"; lmsAudit.Action = "Logging Out"; lmsAudit.Description = String.Format(" User Name : {0}, Name: {1} Logged Out", LoggedInUser.UserName, LoggedInUser.FullName); unitofwork.LMSAuditRepository.Insert(lmsAudit); unitofwork.Save(); return(RedirectToAction("Index", "Login")); }
public ActionResult Index(LMSLogin model) { ///<summary> ///Perform Login checks ///</summary> LMSLogin dbUser = new LMSLogin(); if (ModelState.IsValid) { // Checks the Current user login and password matches and check the Permission level bool userExists = unitofwork.LMSLoginRepository.CheckIfUserExists(model.UserName); if (userExists) { dbUser = unitofwork.LMSLoginRepository.CheckPassword(model); if (dbUser != null) { CurrentUser currentUser = new CurrentUser { UserId = dbUser.UserId, UserName = dbUser.UserName, FullName = dbUser.FirstName + " " + dbUser.LastName, PermissionLevel = dbUser.PermissionLevel, IsSecurityApplied = dbUser.IsSecurityApplied, }; this.HttpContext.Session["CurrentUser"] = currentUser; // add a record of User logging In. LMSAudit lmsAudit = new LMSAudit(); lmsAudit.TransactionDate = DateTime.Now; lmsAudit.UserName = currentUser.UserName; lmsAudit.FullName = currentUser.FullName; lmsAudit.Section = "Login"; lmsAudit.Action = "Logging In"; lmsAudit.Description = String.Format(" User Name : {0}, Name: {1} Logged In. Permission = {2}", currentUser.UserName, currentUser.FullName, currentUser.PermissionLevel); unitofwork.LMSAuditRepository.Insert(lmsAudit); unitofwork.Save(); //saves the user login name in cookies - for Remember Me option - for 15 days if (model.IsRememberMe) { HttpCookie cookie = new HttpCookie("LMSLogin"); cookie.Values.Add("UserName", currentUser.UserName); //cookie.Values.Add("Password", model.Password); cookie.Expires = DateTime.Now.AddDays(15); Response.Cookies.Add(cookie); } else { Response.Cookies["LMSLogin"].Expires = DateTime.Now.AddDays(-1); //HttpCookie cookie = new HttpCookie("LMSLogin"); //cookie.Values.Add("UserName", currentUser.UserName); //cookie.Expires = DateTime.Now.AddDays(15); //Response.Cookies.Add(cookie); } return(RedirectToAction("EmployeeList", "Employee")); } else { dbUser = new LMSLogin { UserName = model.UserName, Message = "Wrong Password." }; } } else { dbUser.Message = "User does not exists."; } } return(View(dbUser)); }