public IActionResult Login(LoginViewModel model, string returnUrl = null) { if (ModelState.IsValid) { SystemAdminDbContext adminDbContext = new SystemAdminDbContext(connStringAdmin); RbacUser validUser = RBAC.GetUser(model.UserName, model.Password); LoginInformationModel LoginInfo = new LoginInformationModel(); //seting session for current valid user if (validUser != null) { //Check user status is Active or not, If user is InActive then return to login page if (validUser.IsActive == false) { ViewData["status"] = "user-inactive"; return(View(model)); } validUser.Password = ""; LoginInfo.EmployeeId = validUser.EmployeeId; LoginInfo.ActionName = "login"; LoginInfo.CreatedOn = System.DateTime.Now; LoginInfo.UserName = validUser.UserName; adminDbContext.LoginInformation.Add(LoginInfo); adminDbContext.SaveChanges(); SetSessionVariable(validUser); if (model.RememberMe) { DateTime centuryBegin = new DateTime(2001, 1, 1); DateTime currentDate = DateTime.Now; //Generate unique tick to make it a selector long ticksElapsed = currentDate.Ticks - centuryBegin.Ticks; SetRememberMeCookieVariable(ticksElapsed, validUser.UserId); } return(RedirectToAction("Index", "Home")); } else { LoginInfo.ActionName = "invalid-login-attempt"; LoginInfo.EmployeeId = null; LoginInfo.CreatedOn = System.DateTime.Now; LoginInfo.UserName = model.UserName; adminDbContext.LoginInformation.Add(LoginInfo); adminDbContext.SaveChanges(); } ViewData["status"] = "login-failed"; return(View(model)); } //If we got this far, something failed, redisplay form return(View(model)); }
public IActionResult Logout(string returnUrl = null) { //HttpContext.Session.Set<RbacUser>("currentuser", null); //Remove all sessin variable values SystemAdminDbContext adminDbContext = new SystemAdminDbContext(connStringAdmin); RbacUser currentUser = HttpContext.Session.Get <RbacUser>("currentuser"); LoginInformationModel LoginInfo = new LoginInformationModel(); //once logged out currentuser gets null, so don't go inside if it's null.. if (currentUser != null) { LoginInfo.EmployeeId = currentUser.EmployeeId; LoginInfo.UserName = currentUser.UserName; LoginInfo.ActionName = "logout"; LoginInfo.CreatedOn = System.DateTime.Now; adminDbContext.LoginInformation.Add(LoginInfo); adminDbContext.SaveChanges(); } RemoveRememberMeCookie(); RemoveSessionValues(); //HttpContext.Session.Remove("currentuser"); LoginViewModel newLogin = new LoginViewModel(); ViewData["status"] = "logout-success"; return(View("Login", newLogin)); }
public IActionResult DisplayForm(LoginInformationModel model) { return(View(model)); }
public void Save(LoginInformationModel LoginInformation, string StorageID) { throw new System.NotImplementedException(); }