public System.Web.Mvc.ActionResult Home(string LanguageToken) { SetLanguage(LanguageToken); ViewData["ShowHead"] = true; if (User.Identity.IsAuthenticated && Session["UserAccountInfo"] == null) { return RedirectToAction("SignOut"); } if (User.Identity.IsAuthenticated) { if (User.IsInRole(AccountRoles.Carer.ToString())) { return RedirectToAction("List", "Users"); } else if (User.IsInRole(AccountRoles.User.ToString())) { return RedirectToAction("New", "Documents"); } else { LogInModel logInModel = new LogInModel(); return View("LogIn", logInModel); } } else { LogInModel logInModel = new LogInModel(); return View("LogIn", logInModel); } }
public System.Web.Mvc.ActionResult LogIn(LogInModel loginModel) { if (ModelState.IsValid) { if (Membership.ValidateUser(loginModel.UserName, loginModel.Password)) { ResourcesUtility ru = new ResourcesUtility(Server); ru.GenerateJSResources(); //AccountInfo user = HttpContext.Session["UserAccountInfo"] == null ? null : HttpContext.Session["UserAccountInfo"] as AccountInfo; AccountInfo user = CurrentUser.Details(); bool isLogged = false; isLogged = HttpContext.Session["UserLogged"] != null && (bool)HttpContext.Session["UserLogged"]; if (isLogged) { Session.Add("logged", true); FormsAuthentication.SetAuthCookie(user.AccountId.ToString(), loginModel.RememberMe); Session["UserAccountInfo"] = user; //if (loginModel.RememberMe) //{ // HttpContext.Cache.Insert(user.AccountId.ToString(), user, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(365)); //} //else if (HttpContext.Cache[user.AccountId.ToString()] != null) //{ // HttpContext.Cache.Remove(user.AccountId.ToString()); //} HttpContext.Session.Remove("UserLogged"); } if (user.Role == AccountRoles.Carer) { return RedirectToAction("List", "Users"); } else if (user.Role == AccountRoles.User) { return RedirectToAction("New", "Documents"); } } else { ViewData["ShowHead"] = true; ModelState.AddModelError("", ClientDefault.LogIn_Log_In_Failed); } } return View("LogIn", loginModel); }
public System.Web.Mvc.ActionResult SignOut() { FormsAuthentication.SignOut(); OBSDataSource.Logout(); LogInModel loginModel = new LogInModel(); return RedirectToAction("Home"); }