Exemplo n.º 1
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            GAHEContext data  = new GAHEContext();
            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));
            }
        }
Exemplo n.º 2
0
        private bool Access(RouteData routeData, string userName)
        {
            var controllerName = routeData.Values["controller"].ToString();
            var actionName     = routeData.Values["action"].ToString();

            GAHEContext data     = new GAHEContext();
            var         items    = data.Navbar;
            var         rolesNav = data.Roles;
            var         usersNav = data.Users;

            var getAccess = (from nav in items
                             join rol in rolesNav on nav.id equals rol.id
                             join Users  in usersNav on rol.id equals Users.Id
                             where Users.user == userName && nav.controller == controllerName && nav.action == actionName
                             select Users.Id).Single();

            var context = new ActionExecutingContext();

            if (getAccess != 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }