public ActionResult Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } var data = new Data(); var users = data.users(); if (users.Any(p => p.user == model.UserName && p.password == model.Password)) { var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, model.UserName),}, DefaultAuthenticationTypes.ApplicationCookie); Authentication.SignIn(new AuthenticationProperties { IsPersistent = model.RememberMe }, identity); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Invalid login attempt."); return View(model); } }
private bool Access(RouteData routeData, string userName) { var controllerName = routeData.Values["controller"].ToString(); var actionName = routeData.Values["action"].ToString(); var data = new Data(); var items = data.navbarItems(); var rolesNav = data.roles(); var usersNav = data.users(); var getAccess = (from nav in items join rol in rolesNav on nav.Id equals rol.idMenu join user in usersNav on rol.idUser equals user.Id where user.user == userName && nav.controller == controllerName && nav.action == actionName select user.Id).Single(); var context = new ActionExecutingContext(); if (getAccess != 0) return true; else return false; }