public IActionResult Login(LoginModel model)
        {
            if (IsUserAuthenticated())
            {
                return(Redirect("/"));
            }

            if (ModelState.IsValid)
            {
                var user = model.AuthenticateUser();
                if (user != null)
                {
                    //auth ok, save to session
                    IAuthenticationHelper authHelper = new SessionAuthenticationHelper(HttpContext.Session);
                    authHelper.SaveState(user);
                    return(Redirect("/"));
                }
                else
                {
                    //add error
                    ModelState.AddModelError(string.Empty, "The username or password provided is incorrect.");
                }
            }
            return(View(model));
        }
        private bool IsAdminAndActive()
        {
            IAuthenticationHelper authHelper = new SessionAuthenticationHelper(HttpContext.Session);

            return(authHelper.IsAdminAndActive());
        }
        private bool IsUserAuthenticated()
        {
            IAuthenticationHelper authHelper = new SessionAuthenticationHelper(HttpContext.Session);

            return(authHelper.IsUserAuthenticated());
        }
        private void _logout()
        {
            IAuthenticationHelper authHelper = new SessionAuthenticationHelper(HttpContext.Session);

            authHelper.Logout();
        }