Beispiel #1
0
        public Rock.CMS.DTO.SiteDomain ApiGet(string id, string apiKey)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.SiteDomainService SiteDomainService = new Rock.CMS.SiteDomainService();
                    Rock.CMS.SiteDomain        SiteDomain        = SiteDomainService.Get(int.Parse(id));
                    if (SiteDomain.Authorized("View", user))
                    {
                        return(SiteDomain.DataTransferObject);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to View this SiteDomain", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #2
0
        public void UpdateSiteDomain(string id, Rock.CMS.DTO.SiteDomain SiteDomain)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.SiteDomainService SiteDomainService  = new Rock.CMS.SiteDomainService();
                Rock.CMS.SiteDomain        existingSiteDomain = SiteDomainService.Get(int.Parse(id));
                if (existingSiteDomain.Authorized("Edit", currentUser))
                {
                    uow.objectContext.Entry(existingSiteDomain).CurrentValues.SetValues(SiteDomain);

                    if (existingSiteDomain.IsValid)
                    {
                        SiteDomainService.Save(existingSiteDomain, currentUser.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingSiteDomain.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this SiteDomain", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #3
0
        public void ApiDeleteSiteDomain(string id, string apiKey)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.SiteDomainService SiteDomainService = new Rock.CMS.SiteDomainService();
                    Rock.CMS.SiteDomain        SiteDomain        = SiteDomainService.Get(int.Parse(id));
                    if (SiteDomain.Authorized("Edit", user))
                    {
                        SiteDomainService.Delete(SiteDomain, user.PersonId);
                        SiteDomainService.Save(SiteDomain, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>("Not Authorized to Edit this SiteDomain", System.Net.HttpStatusCode.Forbidden);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #4
0
        public void DeleteSiteDomain(string id)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.SiteDomainService SiteDomainService = new Rock.CMS.SiteDomainService();
                Rock.CMS.SiteDomain        SiteDomain        = SiteDomainService.Get(int.Parse(id));
                if (SiteDomain.Authorized("Edit", currentUser))
                {
                    SiteDomainService.Delete(SiteDomain, currentUser.PersonId);
                    SiteDomainService.Save(SiteDomain, currentUser.PersonId);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to Edit this SiteDomain", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #5
0
        public void ApiCreateSiteDomain(string apiKey, Rock.CMS.DTO.SiteDomain SiteDomain)
        {
            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                Rock.CMS.UserService userService = new Rock.CMS.UserService();
                Rock.CMS.User        user        = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault();

                if (user != null)
                {
                    uow.objectContext.Configuration.ProxyCreationEnabled = false;
                    Rock.CMS.SiteDomainService SiteDomainService  = new Rock.CMS.SiteDomainService();
                    Rock.CMS.SiteDomain        existingSiteDomain = new Rock.CMS.SiteDomain();
                    SiteDomainService.Add(existingSiteDomain, user.PersonId);
                    uow.objectContext.Entry(existingSiteDomain).CurrentValues.SetValues(SiteDomain);

                    if (existingSiteDomain.IsValid)
                    {
                        SiteDomainService.Save(existingSiteDomain, user.PersonId);
                    }
                    else
                    {
                        throw new WebFaultException <string>(existingSiteDomain.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest);
                    }
                }
                else
                {
                    throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #6
0
        protected void btnSave_Click( object sender, EventArgs e )
        {
            Rock.CMS.Site site;
            Rock.CMS.SiteDomain sd;
            bool newSite = false;

            using ( new Rock.Data.UnitOfWorkScope() )
            {
                siteService = new Rock.CMS.SiteService();
                siteDomainService = new Rock.CMS.SiteDomainService();

                int siteId = 0;
                if ( !Int32.TryParse( hfSiteId.Value, out siteId ) )
                    siteId = 0;

                if ( siteId == 0 )
                {
                    newSite = true;
                    site = new Rock.CMS.Site();
                    siteService.Add( site, CurrentPersonId );
                }
                else
                {
                    site = siteService.Get( siteId );
                    foreach ( var domain in site.SiteDomains.ToList() )
                        siteDomainService.Delete( domain, CurrentPersonId );
                    site.SiteDomains.Clear();
                }

                site.Name = tbSiteName.Text;
                site.Description = tbDescription.Text;
                site.Theme = ddlTheme.Text;
                site.DefaultPageId = Convert.ToInt32( ddlDefaultPage.SelectedValue );

                foreach ( string domain in tbSiteDomains.Text.SplitDelimitedValues() )
                {
                    sd = new Rock.CMS.SiteDomain();
                    sd.Domain = domain;
                    sd.Guid = Guid.NewGuid();
                    site.SiteDomains.Add( sd );
                }

                site.FaviconUrl = tbFaviconUrl.Text;
                site.AppleTouchIconUrl = tbAppleTouchIconUrl.Text;
                site.FacebookAppId = tbFacebookAppId.Text;
                site.FacebookAppSecret = tbFacebookAppSecret.Text;

                siteService.Save( site, CurrentPersonId );

                if ( newSite )
                    Rock.Security.Authorization.CopyAuthorization( PageInstance.Site, site, CurrentPersonId );

                Rock.Web.Cache.Site.Flush( site.Id );

                BindGrid();

                pnlDetails.Visible = false;
                pnlList.Visible = true;
            }
        }
Beispiel #7
0
        public Rock.CMS.DTO.SiteDomain Get(string id)
        {
            var currentUser = Rock.CMS.UserService.GetCurrentUser();

            if (currentUser == null)
            {
                throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden);
            }

            using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
            {
                uow.objectContext.Configuration.ProxyCreationEnabled = false;
                Rock.CMS.SiteDomainService SiteDomainService = new Rock.CMS.SiteDomainService();
                Rock.CMS.SiteDomain        SiteDomain        = SiteDomainService.Get(int.Parse(id));
                if (SiteDomain.Authorized("View", currentUser))
                {
                    return(SiteDomain.DataTransferObject);
                }
                else
                {
                    throw new WebFaultException <string>("Not Authorized to View this SiteDomain", System.Net.HttpStatusCode.Forbidden);
                }
            }
        }
Beispiel #8
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Rock.CMS.Site       site;
            Rock.CMS.SiteDomain sd;
            bool newSite = false;

            using (new Rock.Data.UnitOfWorkScope())
            {
                siteService       = new Rock.CMS.SiteService();
                siteDomainService = new Rock.CMS.SiteDomainService();

                int siteId = 0;
                if (!Int32.TryParse(hfSiteId.Value, out siteId))
                {
                    siteId = 0;
                }

                if (siteId == 0)
                {
                    newSite = true;
                    site    = new Rock.CMS.Site();
                    siteService.Add(site, CurrentPersonId);
                }
                else
                {
                    site = siteService.Get(siteId);
                    foreach (var domain in site.SiteDomains.ToList())
                    {
                        siteDomainService.Delete(domain, CurrentPersonId);
                    }
                    site.SiteDomains.Clear();
                }

                site.Name          = tbSiteName.Text;
                site.Description   = tbDescription.Text;
                site.Theme         = ddlTheme.Text;
                site.DefaultPageId = Convert.ToInt32(ddlDefaultPage.SelectedValue);

                foreach (string domain in tbSiteDomains.Text.SplitDelimitedValues())
                {
                    sd        = new Rock.CMS.SiteDomain();
                    sd.Domain = domain;
                    sd.Guid   = Guid.NewGuid();
                    site.SiteDomains.Add(sd);
                }

                site.FaviconUrl        = tbFaviconUrl.Text;
                site.AppleTouchIconUrl = tbAppleTouchIconUrl.Text;
                site.FacebookAppId     = tbFacebookAppId.Text;
                site.FacebookAppSecret = tbFacebookAppSecret.Text;

                siteService.Save(site, CurrentPersonId);

                if (newSite)
                {
                    Rock.Security.Authorization.CopyAuthorization(PageInstance.Site, site, CurrentPersonId);
                }

                Rock.Web.Cache.Site.Flush(site.Id);

                BindGrid();

                pnlDetails.Visible = false;
                pnlList.Visible    = true;
            }
        }
        /// <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.Site site = null;
                if (sites.ContainsKey(host))
                {
                    site = Rock.Web.Cache.Site.Read(sites[host]);
                }
                else
                {
                    Rock.CMS.SiteDomainService siteDomainService = new Rock.CMS.SiteDomainService();
                    Rock.CMS.SiteDomain        siteDomain        = siteDomainService.GetByDomainContained(requestContext.HttpContext.Request.Url.Host);
                    if (siteDomain != null)
                    {
                        sites.Add(host, siteDomain.SiteId);
                        site = Rock.Web.Cache.Site.Read(siteDomain.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.Page page = null;

            if (!string.IsNullOrEmpty(pageId))
            {
                page = Rock.Web.Cache.Page.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.Page cmsPage = (Rock.Web.UI.Page)BuildManager.CreateInstanceFromVirtualPath(page.LayoutPath, typeof(Rock.Web.UI.Page));
                cmsPage.PageInstance = page;
                return(cmsPage);
            }
            else
            {
                string theme      = "RockCMS";
                string layout     = "Default";
                string layoutPath = Rock.Web.Cache.Page.FormatPath(theme, layout);

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

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

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

                try
                {
                    // Return the page for the selected theme and layout
                    Rock.Web.UI.Page cmsPage = (Rock.Web.UI.Page)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.Page));
                    cmsPage.PageInstance = 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.Page.FormatPath(theme, layout);

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

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