Example #1
0
        public override void Up()
        {
            // Page: OAuth Configuration
            RockMigrationHelper.AddPage("91CCB1C9-5F9F-44F5-8BE2-9EC3A3CFD46F", "D65F783D-87A9-4CC9-8110-E83466A0EADB", "OAuth Configuration", "", "C2B15044-B63C-43EB-BADC-9730890F4621", "fa fa-cloud"); // Site:Rock RMS
            RockMigrationHelper.UpdateBlockType("OAuth Configuration", "Configuration settings for OAuth.", "~/Plugins/org_secc/OAuth/Configuration.ascx", "SECC > Security", "34680C7A-84DF-413A-A474-3495C65372DA");
            RockMigrationHelper.AddBlock("C2B15044-B63C-43EB-BADC-9730890F4621", "", "34680C7A-84DF-413A-A474-3495C65372DA", "OAuth Configuration", "Main", "", "", 0, "3339F274-F61D-4CAA-AA8D-EC84E3290FC7");

            RockMigrationHelper.AddBlockTypeAttribute("34680C7A-84DF-413A-A474-3495C65372DA", "9C204CD0-1233-41C5-818A-C5DA439445AA", "OAuth Config Attribute Key", "OAuthConfigAttributeKey", "", "The OAuth Configuration Attribute\"s Key", 0, @"OAuthSettings", "3CE5DD1F-C69F-483D-B6BF-57FE0ED4C8AA");

            RockMigrationHelper.AddBlockTypeAttribute("34680C7A-84DF-413A-A474-3495C65372DA", "BB7AB90F-4DE9-4804-A852-F5593A35C8A0", "OAuth Site", "OAuthSite", "", "The OAuth Porta/Site", 0, @"1", "5ED9C998-F7D0-4057-93B6-F4B4FE0837DA");

            RockMigrationHelper.AddBlockAttributeValue("3339F274-F61D-4CAA-AA8D-EC84E3290FC7", "3CE5DD1F-C69F-483D-B6BF-57FE0ED4C8AA", @"OAuthSettings"); // OAuth Config Attribute Key

            // Get the site so we can get its ID
            Rock.Model.SiteService siteService = new Rock.Model.SiteService(new Rock.Data.RockContext());
            Rock.Model.Site        site        = siteService.Get("92A541DB-F88C-4EEA-B015-B67497C5B2A0".AsGuid());

            RockMigrationHelper.AddBlockAttributeValue("3339F274-F61D-4CAA-AA8D-EC84E3290FC7", "5ED9C998-F7D0-4057-93B6-F4B4FE0837DA", site.Id.ToString()); // OAuth Site
        }
Example #2
0
        /// <summary>
        /// Determine the logical page being requested by evaluating the routedata, or querystring and
        /// then loading the appropriate layout (ASPX) page
        /// </summary>
        /// <param name="requestContext"></param>
        /// <returns></returns>
        System.Web.IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }

            string pageId  = "";
            int    routeId = -1;

            // Pages using the default routing URL will have the page id in the RouteData.Values collection
            if (requestContext.RouteData.Values["PageId"] != null)
            {
                pageId = (string)requestContext.RouteData.Values["PageId"];
            }
            // Pages that use a custom URL route will have the page id in the RouteDate.DataTokens collection
            else if (requestContext.RouteData.DataTokens["PageId"] != null)
            {
                pageId  = (string)requestContext.RouteData.DataTokens["PageId"];
                routeId = Int32.Parse((string)requestContext.RouteData.DataTokens["RouteId"]);
            }
            // If page has not been specified get the site by the domain and use the site's default page
            else
            {
                string host     = requestContext.HttpContext.Request.Url.Host;
                string cacheKey = "Rock:DomainSites";

                ObjectCache cache = MemoryCache.Default;
                Dictionary <string, int> sites = cache[cacheKey] as Dictionary <string, int>;
                if (sites == null)
                {
                    sites = new Dictionary <string, int>();
                }

                Rock.Web.Cache.SiteCache site = null;
                if (sites.ContainsKey(host))
                {
                    site = Rock.Web.Cache.SiteCache.Read(sites[host]);
                }
                else
                {
                    int siteId = 1;

                    Rock.Model.SiteDomainService siteDomainService = new Rock.Model.SiteDomainService();
                    Rock.Model.SiteDomain        siteDomain        = siteDomainService.GetByDomainContained(requestContext.HttpContext.Request.Url.Host);
                    if (siteDomain != null)
                    {
                        siteId = siteDomain.SiteId;
                    }
                    else
                    {
                        var siteService = new Rock.Model.SiteService();
                        var rockSite    = siteService.Get(SystemGuid.Site.SITE_ROCK_CHMS);
                        if (rockSite != null)
                        {
                            siteId = rockSite.Id;
                        }
                    }

                    sites.Add(host, siteId);
                    site = Rock.Web.Cache.SiteCache.Read(siteId);
                }

                cache[cacheKey] = sites;

                if (site != null && site.DefaultPageId.HasValue)
                {
                    pageId = site.DefaultPageId.Value.ToString();
                }

                if (string.IsNullOrEmpty(pageId))
                {
                    throw new SystemException("Invalid Site Configuration");
                }
            }

            Rock.Web.Cache.PageCache page = null;

            if (!string.IsNullOrEmpty(pageId))
            {
                page = Rock.Web.Cache.PageCache.Read(Convert.ToInt32(pageId));
                if (page == null)
                {
                    return(new HttpHandlerError(404));
                }
            }

            if (page != null && !String.IsNullOrEmpty(page.LayoutPath))
            {
                // load the route id
                page.RouteId = routeId;

                // Return the page using the cached route
                Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(page.LayoutPath, typeof(Rock.Web.UI.RockPage));
                cmsPage.CurrentPage = page;
                return(cmsPage);
            }
            else
            {
                string theme      = "RockCms";
                string layout     = "Default";
                string layoutPath = Rock.Web.Cache.PageCache.FormatPath(theme, layout);

                if (page != null)
                {
                    // load the route id
                    page.RouteId = routeId;

                    theme      = page.Site.Theme;
                    layout     = page.Layout;
                    layoutPath = Rock.Web.Cache.PageCache.FormatPath(theme, layout);

                    page.LayoutPath = layoutPath;
                }
                else
                {
                    page = Cache.PageCache.Read(new Model.Page());
                }

                try
                {
                    // Return the page for the selected theme and layout
                    Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));
                    cmsPage.CurrentPage = page;
                    return(cmsPage);
                }
                catch (System.Web.HttpException)
                {
                    // The Selected theme and/or layout didn't exist, attempt first to use the default layout in the selected theme
                    layout = "Default";

                    // If not using the Rock theme, verify that default Layout exists in the selected theme directory
                    if (theme != "RockCms" &&
                        !File.Exists(requestContext.HttpContext.Server.MapPath(string.Format("~/Themes/{0}/Layouts/Default.aspx", theme))))
                    {
                        // If default layout doesn't exist in the selected theme, switch to the Default layout
                        theme  = "RockCms";
                        layout = "Default";
                    }

                    // Build the path to the aspx file to
                    layoutPath = Rock.Web.Cache.PageCache.FormatPath(theme, layout);

                    if (page != null)
                    {
                        page.LayoutPath = layoutPath;
                    }

                    // Return the default layout and/or theme
                    Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));
                    cmsPage.CurrentPage = page;
                    return(cmsPage);
                }
            }
        }