public override void OnAuthorization(AuthorizationContext filterContext)
 {
     if (string.IsNullOrEmpty(SessionPersister.Email))
         filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary
             (new { controller = "Account", action = "Login" }));
     else
     {
         UsersService userService = new UsersService();
         CustomPrincipal mp = new CustomPrincipal(userService.GetUserForLogin
             (SessionPersister.Email));
         if (!mp.IsInRole(Roles))
             filterContext.Result = new RedirectToRouteResult(new
                 RouteValueDictionary(new { controller = "User", action = "Information" }));
     }
 }
Esempio n. 2
0
        public void ActionNotFoundShoudReturnPageNotFoundView()
        {
            var mockHttpContext = new Mock<HttpContextBase>();
            var response = new Mock<HttpResponseBase>();
            mockHttpContext.SetupGet(x => x.Response).Returns(response.Object);

            var db = new PetCareDbContext();
            var repo = new Repository<User>(db);
            var users = new UsersService(repo);
            var controller = new ErrorController(users)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = mockHttpContext.Object
                }
            };

            controller.WithCallTo(x => x.NotFound())
                .ShouldRenderView("NotFound");
        }
 public AccountController()
 {
     currentUserService = new UsersService();
 }
Esempio n. 4
0
 public UserController()
 {
     currentUserService = new UsersService();
     logger = LogManager.GetLogger(typeof(UserController));
 }