Ejemplo n.º 1
0
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            var username = UserHelper.CreateUsernameWithoutDomain2(HttpContext.Current.User as ClaimsPrincipal);

            if (string.IsNullOrEmpty(username))
            {
                username = HttpContext.Current.Session.SessionID;
            }

            var usernameWithoutDomain = UserHelper.CreateUsernameWithoutDomain(username);

            if (_administratorDAO.UserIsAdmin(usernameWithoutDomain) == false)
            {
                //filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "action", "AccessDenied" }, { "controller", "Error" } });
                filterContext.Result = new HttpUnauthorizedResult();
            }
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            ViewBag.UserName = UserHelper.CreateUsernameWithoutDomain2(User as ClaimsPrincipal);
            var user = UserHelper.CreateUsernameWithoutDomain2(User as ClaimsPrincipal);

            var viewModel = new TaskIndexViewModel
            {
                IsAdmin    = _administratorDAO.UserIsAdmin(UserHelper.CreateUsernameWithoutDomain(string.IsNullOrEmpty(user) ? Session.SessionID : user)),
                IsLoggedIn = !string.IsNullOrEmpty(user)
            };

            foreach (var selectedTask in _selectedTaskDAO.GetAllChronologically(string.IsNullOrEmpty(User.Identity.Name) ? Session.SessionID : User.Identity.Name, DateTime.Now))
            {
                viewModel.SelectedTasks.Add(new SelectedTaskViewModel(selectedTask));
            }

            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            return(View(viewModel));
        }