/*
  * This method enforces page level security
  */
 public void OnAuthorization(AuthorizationContext filterContext)
 {
     // if the user is not signed in
     if (Cache.AccessCache().Get("activeAccount") == null)
     {
         // redirect to login
         filterContext.Result = new RedirectResult("/account/showloginform");
     }
 }
        /*
         * this method signs the user out of the application
         * @return the login view after logout
         */
        public ActionResult HandleLogout()
        {
            try
            {
                // clear cache to forget signed-in user
                Cache.AccessCache().Clear();

                // send the client to the login form after sign out
                return(View("ShowLoginForm"));
            }

            catch (Exception e)
            {
                // log error
                Logger.Error("Failed loading difficulty screen view: " + e.Message);

                // return the generic error page
                return(View("Exception"));
            }
        }
        // authenticate the user
        public ActionResult Authenticate(CredentialModel credentialSet)
        {
            try
            {
                //log entry into method
                Logger.Info("Entering AccountController.Authenticate()");

                // instantiate the business service
                UserBusinessService BusinessService = new UserBusinessService();

                // use business service to authenticate user
                bool loginSuccess = BusinessService.Authenticate(credentialSet);

                // if login was successful return the success view
                if (loginSuccess)
                {
                    Cache.AccessCache().Put("activeAccount", credentialSet.Email);

                    //log success
                    Logger.Info("Exiting AccountController.Authenticate() with login success");

                    return(View("loginSuccess"));
                }

                // otherwise return the login fail view
                else
                {
                    //log failure
                    Logger.Info("Exiting AccountController.Authenticate() with login failure");

                    return(View("loginFail"));
                }
            }

            catch (Exception e)
            {
                Logger.Error("Exiting AccountController.Authenticate() with an exception: " + e.Message);
                // return the generic error page
                return(View("Exception"));
            }
        }
示例#4
0
        public ActionResult StartGame(string difficulty)
        {
            // use try/catch block to handle exceptions
            try
            {
                // the difficulty the player selected on the previous form
                int chosenDifficulty = Int32.Parse(difficulty);

                // instaniate game bundle. The bundle model includes all models and primitives related to the game.
                Bundle = new GameBundle(chosenDifficulty);

                Bundle.User = Cache.AccessCache().Get("activeAccount");

                // instantiate game service
                // the game service is a Business Logic Layer class that enforces rules & logic
                GameService gameService = new GameService();

                // deploy mines
                gameService.SetupLiveNeighbors(Bundle);

                // calculate neighbor counts for each cell
                gameService.CalculateLiveNeighbors(Bundle);

                // return the game board view
                return(View("gameBoard", Bundle));
            }

            // handle exceptions
            catch (Exception e)
            {
                // log error
                Logger.Error("Failed to start game: " + e.Message);
                // return generic error page
                return(View("Exception"));
            }
        }