Ejemplo n.º 1
0
        void TestBox_OnAdminRequest(AdminInterface admin, string sprocketPath, string[] pathSections, HandleFlag handled)
        {
            //admin.AddMainMenuLink(new AdminMenuLink("Test Box", WebUtility.MakePath("admin/testbox"), 1000));
            if (sprocketPath != "admin/testbox")
            {
                return;
            }
            handled.Set();
            admin.AddInterfaceScript(new RankedString(ResourceLoader.LoadTextResource(typeof(AjaxForm).Assembly, "Sprocket.Web.Controls.AjaxForm.js"), 0));
            admin.AddHeadSection(new RankedString(CSS, 0));
            admin.ContentHeading = "Test Box";
            admin.AddContentSection(new RankedString("blah", -1000));

            AjaxFormFieldBlock b = new AjaxFormFieldBlock("UserDetails", "Main User Details");

            b.Add(new AjaxFormStandardField(
                      "Username",
                      "Username",
                      "<input type=\"text\" id=\"Username\" />",
                      null,
                      "function(value) { return value.length == 0 ? 'Please enter a username' : false }",
                      true, 1));
            b.Add(new AjaxFormStandardField("First Name", "FirstName", "<input type=\"text\" />", null, "", true, 0));

            AjaxFormFieldBlock b2 = new AjaxFormFieldBlock("RandomCrap", "Random Crap");

            b2.Add(new AjaxFormField("stuff", null, null, -1));

            AjaxFormFieldBlockList bl = new AjaxFormFieldBlockList();

            bl.Add(b);
            bl.Add(b2);

            admin.AddContentSection(new RankedString(bl, 1001));
        }
Ejemplo n.º 2
0
 void WebsiteAdmin_OnAdminRequest(AdminInterface admin, string sprocketPath, string[] pathSections, HandleFlag handled)
 {
     if (sprocketPath != "admin")
     {
         return;
     }
     admin.ContentHeading = "Current Overview";
     admin.AddContentSection(new RankedString("<div class=\"standalone-message\">Overview information under construction.</div>", 0));
     handled.Set();
 }
Ejemplo n.º 3
0
        void OnLoadRequestedPath(HttpApplication app, string path, string[] pathSections, HandleFlag handled)
        {
            if (pathSections.Length == 0)
            {
                return;
            }
            if (pathSections[0] != "admin")
            {
                return;
            }
            bool   processed = false;
            string lastchunk = pathSections[pathSections.Length - 1];

            switch (lastchunk)
            {
            case "admin.css":
                HttpContext.Current.Response.TransmitFile("~/resources/admin/admin.css");
                HttpContext.Current.Response.ContentType = "text/css";
                processed = true;
                break;

            default:
                WebAuthentication auth     = (WebAuthentication)SystemCore.Instance["WebAuthentication"];
                HttpResponse      Response = HttpContext.Current.Response;
                HttpServerUtility Server   = HttpContext.Current.Server;
                switch (path)
                {
                case "admin/login":
                    ShowLoginScreen();
                    processed = true;
                    break;

                case "admin/logout":
                    auth.ClearAuthenticationCookie();
                    Response.Redirect(WebUtility.MakeFullPath("admin/login"));
                    processed = true;
                    break;

                case "admin/login/process":
                    if (auth.ProcessLoginForm("SprocketUsername", "SprocketPassword", "SprocketPreserveLogin"))
                    {
                        Response.Redirect(WebUtility.MakeFullPath("admin"));
                    }
                    else
                    {
                        ShowLoginScreen("Invalid Username and/or Password.");
                    }
                    processed = true;
                    break;

                default:
                    if (!auth.IsLoggedIn)
                    {
                        GotoLoginScreen();
                        processed = true;
                    }
                    else if (OnCMSAdminAuthenticationSuccess != null)
                    {
                        Result result = new Result();
                        OnCMSAdminAuthenticationSuccess(auth.CurrentUsername, result);
                        if (!result.Succeeded)
                        {
                            ShowLoginScreen(result.Message);
                            processed = true;
                        }
                    }
                    break;
                }
                break;
            }
            if (processed)
            {
                handled.Set();
                return;
            }

            if (OnAdminRequest != null)
            {
                AdminInterface admin = new AdminInterface();
                OnAdminRequest(admin, path, pathSections, handled);
                if (handled.Handled)
                {
                    WebClientScripts scripts = (WebClientScripts)SystemCore.Instance["WebClientScripts"];
                    admin.AddMainMenuLink(new AdminMenuLink("Current Overview", WebUtility.MakeFullPath("admin"), -100));
                    admin.AddMainMenuLink(new AdminMenuLink("Log Out", WebUtility.MakeFullPath("admin/logout"), 100));
                    admin.AddFooterLink(new AdminMenuLink("&copy; 2005-" + DateTime.Now.Year + " " + SprocketSettings.GetValue("WebsiteName"), "", 100));
                    string powered = SprocketSettings.GetValue("ShowPoweredBySprocket");
                    if (powered != null)
                    {
                        if (Utilities.MatchesAny(powered.ToLower(), "true", "yes"))
                        {
                            admin.AddFooterLink(new AdminMenuLink("Powered by Sprocket", "http://www.sprocketcms.com", 1000));
                        }
                    }
                    admin.AddHeadSection(new RankedString(scripts.BuildScriptTags(), 1));
                    HttpContext.Current.Response.Write(admin.Render(path));
                }
            }
        }