protected override void OnActionExecuting(ActionExecutingContext filterContext) { // var user = TUser.FindByUsername(User.Identity.Name); // var enabledAccess = TParameter.FindByEnum(Parameter.BlockAccessAdmin) == null; // if (User.Identity.IsAuthenticated && user != null && (enabledAccess || user.Username == "admin")) // { // ViewBag.Usuario = user; // ViewBag.Permissoes = user.ListPermissions(); // } // else // FormsAuthentication.SignOut(); // if (user != null && filterContext.HttpContext.Session != null) // { // if (filterContext.HttpContext.Session["MenuLateral"] != null) // user.ActiveSideBarMenu = filterContext.HttpContext.Session["MenuLateral"].ToString() == "aberto"; // else // user.ActiveSideBarMenu = true; // } var cliente = TClient.FindByUsername(User.Identity.Name); if (User.Identity.IsAuthenticated && cliente != null) { ViewBag.Cliente = cliente; } else { FormsAuthentication.SignOut(); } ViewBag.Alerta = TempData["Alerta"]; }
public virtual ActionResult Login(Login model) { model.NeedsToBeActive = false; var membro = TClient.Authenticate(model); if (membro != null) { FormsAuthentication.SetAuthCookie(membro.Login, false); HttpContext.User = new GenericPrincipal(new GenericIdentity(membro.Login), new string[] { }); if (!string.IsNullOrWhiteSpace(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } TempData["Alerta"] = new Alert("success", "Bem-vindo" + " " + model.Username); return(RedirectToAction(MVC.Clientes.cliente_filmes())); } else { membro = TClient.FindByUsername(model.Username); if (membro != null) { TempData["Alerta"] = new Alert("error", "Senha incorreta"); } TempData["Alerta"] = new Alert("error", "Usuário não existe"); return(View(model)); } }
public SecurityContext Init(Func <IIdentity> identityGetter) { _identityGetter = identityGetter; _isAuthenticated = TryGet(x => x.IsAuthenticated, false); var username = TryCast(x => x.Name, string.Empty); if (_isAuthenticated && !string.IsNullOrEmpty(username)) { var model = TClient.FindByUsername(username); if (model != null) { _user = new UserSecurity(model); } } else { _user = null; } if (_user == null) { _isAuthenticated = false; } return(this); }