/// <summary> /// The method that handles standard CMS page request. Subclass can choose to override to change its behavior. /// </summary> /// <param name="pageRequest"></param> /// <returns></returns> internal virtual ActionResult handleStandardCMSPageRequest(CMSPageRequest pageRequest) { //if the transform option is 4 or 5, return xml directly, also, bypass caching if (pageRequest.IsComponent || _AllowTfrm && (pageRequest.TransformOption == TransformOptions.ExpansionOnly || pageRequest.TransformOption == TransformOptions.Raw)) { return(new XmlResult(pageRequest.ContentDocument)); } else { if (!_IsDesignTime) { StructureUrlMap urlMap = _PageFactory.UrlMap; string triggerFile = System.IO.Path.Combine(urlMap.SitePath, urlMap.Settings.GetSetting <string>("RuntimeCache", "TriggerFile")); IGXPageLevelCache pageLevelCache = IGXPageLevelCache.Get(triggerFile); //add page level caching information, first request to the same page will always executing. 2nd request will set the cachability pageLevelCache.CheckPageCache(Request.Path.ToLowerInvariant(), pageRequest.Content, pageRequest.NavigationUsingCacheContent); } //locate the view based on root element name, and pass in the XElement of page as model return(viewOrXsltFallback(pageRequest)); } }
/// <summary> /// if login is required, and not logged in, return redirect url /// </summary> /// <param name="pgRequest"></param> /// <returns>redirect url or null</returns> private string checkUserAuth(CMSPageRequest pgRequest) { bool authSucc = (Session["auth.success"] == null) ? false : (bool)Session["auth.success"]; int authLevel = (int?)Session["auth.accessLevel"] ?? 0; var authSet = pgRequest.GetNavigationItems("AncestorNavigation").Where(item => item.GetAttributeValue("Authorization") != ""); if (authSet.Any()) { string auth = authSet.LastOrDefault().GetAttributeValue("Authorization"); int requiredAuthLevel = auth.Split('-')[0].ToInt() ?? 0; bool accessGranted = (requiredAuthLevel == 0) || (authSucc && authLevel > 0 && authLevel >= requiredAuthLevel); if (!accessGranted && !pgRequest.IsPreview && pgRequest.RootElementName != "LoginPage") { ICMSElement loginElt = pgRequest.GetLinkItem("Login", true); String loginUrl = (loginElt != null) ? loginElt.URL : ""; if (!loginUrl.StartsWith("http")) { loginUrl = Url.Content("~/" + loginUrl); } return(loginUrl + "?returnURL=" + Request.Url); } } return(null); }
public XsltTransformResult(CMSPageRequest pageRequest, string sitePath, bool useTempXsltLocation, string rtSitePath = "", bool legacyRenderingEngine = true) { PageRequest = pageRequest; SitePath = sitePath; RtSitePath = rtSitePath.ToNullHelper().Return(sitePath); LegacyRenderingEngine = legacyRenderingEngine; InContextEditMode = pageRequest.EditMode; UseTempXsltLocation = useTempXsltLocation; }
public ActionResult Login(string redir, string user, string pass) { if (Request.HttpMethod.ToLowerInvariant() == "post") { AuthenticationLib authLib = new AuthenticationLib(); UserInfo userInfo = authLib.Authenticate(user, pass); if (userInfo == null) { CMSPageRequest page = _PageFactory.GetPage(Request, "x7") as CMSPageRequest; page.Tag = new LoginModel { RedirectUrl = redir, UserName = user, Error = "Invalid User name or Password" }; return(View("Login", page)); } else if (!userInfo.Paid) { CMSPageRequest page = _PageFactory.GetPage(Request, "x7") as CMSPageRequest; page.Tag = new LoginModel { RedirectUrl = redir, UserName = user, Error = "Payment not processed yet. You will be able to login as soon as payment is received." }; return(View("Login", page)); } else { //save as session Session["user"] = userInfo; if (string.IsNullOrWhiteSpace(redir)) { return(Redirect("~/")); } else { //redirect to redir url return(Redirect(redir)); } } } else { CMSPageRequest page = _PageFactory.GetPage(Request, "x7") as CMSPageRequest; page.Tag = new LoginModel { RedirectUrl = redir }; return(View("Login", page)); } }
/// <summary> /// This is the only method that need to overriding. /// The goal of override is to set the search results object as .Tag of the pageRequest. /// </summary> /// <param name="pageRequest"></param> /// <returns></returns> internal override ActionResult handleStandardCMSPageRequest(CMSPageRequest pageRequest) { //var redir = checkUserAuth(pageRequest); //if (redir != null) //{ // Response.Redirect(redir); //} _GetSearchResults(pageRequest); return(base.handleStandardCMSPageRequest(pageRequest)); }
internal override System.Web.Mvc.ActionResult handleStandardCMSPageRequest(CMSPageRequest pageRequest) { var auth = new AuthenticationLib(); bool isTempUser = false; UserInfo user = Session["user"] as UserInfo; if (user == null) { string tempUserId = Session["tempIdForBirdList"] as string; if (!string.IsNullOrWhiteSpace(tempUserId)) { user = auth.User(tempUserId); isTempUser = true; } } if (user != null && pageRequest.Form["posting"] == "true") { var selectedBirdIds = pageRequest.Form.GetValues("bird"); user.Birds = selectedBirdIds .Select( b => new BirdInfo { XID = b }) .ToList(); user.OtherBirds = pageRequest.Form["otherBirds"]; lock (auth.SyncRoot) auth.Save(); } HashSet <string> birdIds = user != null?user.Birds .Select( b => b.XID) .ToHashSet() : new HashSet <string>(); pageRequest.Tag = new BirdsModel { Birds = birdIds, OtherBirds = user .ToNullHelper() .Propagate( u => u.OtherBirds) .Return(""), IsTempUser = isTempUser }; return(base.handleStandardCMSPageRequest(pageRequest)); }
/// <summary> /// Handle 404 exception and redirect it to the 404 error page, and fallback to NotFoundError view /// </summary> /// <param name="filterContext"></param> protected override void OnException(ExceptionContext filterContext) { //handle 404 exception if (filterContext.Exception is HttpException) { HttpException httpException = filterContext.Exception as HttpException; if (httpException.GetHttpCode() == 404) { filterContext.HttpContext.Response.StatusCode = 404; //add 404 page handling specified by url map string error404PageId = _PageFactory.UrlMap .ToNullHelper() .Propagate( urlMap => urlMap.Error404PageId) .Return(string.Empty); if (!string.IsNullOrEmpty(error404PageId)) { CMSPageRequest page404 = _PageFactory.GetPage(Request, error404PageId) as CMSPageRequest; if (page404 != null && page404.Exists) { filterContext.ExceptionHandled = true; ActionResult result404 = viewOrXsltFallback(page404); result404.ExecuteResult(ControllerContext); return; } } //go to provided Error view, structured url map 404 page is not used, only if the view exists //otherwise, use base procedure ViewResult viewResult = View("NotFoundError", new Error404() { Title = Ingeniux.Runtime.Properties.Resources.Error404Title, BodyCopy = Ingeniux.Runtime.Properties.Resources.Error404BodyCopy, Factory = _PageFactory }); ViewEngineResult viewEngineResult = viewResult.ViewEngineCollection.FindView(ControllerContext, viewResult.ViewName, viewResult.MasterName); if (viewEngineResult != null && viewEngineResult.View != null && viewEngineResult.ViewEngine != null) { filterContext.ExceptionHandled = true; viewResult.ExecuteResult(ControllerContext); return; } } } base.OnException(filterContext); }
public ActionResult ChangePassword(string OPassword, string Password, string PasswordC) { CMSPageRequest page = _PageFactory.GetPage(Request, "x7") as CMSPageRequest; if (Request.HttpMethod.ToLowerInvariant() == "post") { OPassword = Request.Form["OPassword"]; Password = Request.Form["Password"]; PasswordC = Request.Form["PasswordC"]; var user = Session["user"] as Ingeniux.Runtime.Models.UserInfo; if (user == null) { page.Tag = "Please login first in order to change password."; } else { if (user.Password != OPassword) { page.Tag = "Current password is incorrect."; } else if (Password != PasswordC) { page.Tag = "Password confirmation doesn't match."; } else { if (Password.Length < 6) { page.Tag = "Password must be at least 6 characters."; } user.Password = Password; AuthenticationLib auth = new AuthenticationLib(); auth.SignupOrUpdate(user, false); } } if (page.Tag != null) { return(View("ChangePassword", page)); } else { return(Redirect("~/")); } } return(View("ChangePassword", page)); }
/// <summary> /// The standard CMS page handling. If a view with the root element name exists, use it. Otherwise, try to transform /// the page xml content with XSLT, via traditional MSXML 4 DOM, like the old CMS Runtime engine. /// This ensures an existing site can start using the new MVC runtime without any work, and slowly convert to full MVC site page type by page type. /// /// </summary> /// <param name="pageRequest"></param> /// <remarks>This method generally doesn't need overriding at all. Only override it is additional data need to be passed down to view. (e.g Cartella data).e</remarks> /// <returns></returns> internal virtual ActionResult viewOrXsltFallback(CMSPageRequest pageRequest) { CMSPageRenderingEngine renderEngine = new CMSPageRenderingEngine( this, _SitePath, _DTSitePath, _UseTempStylesheetsLocation, _LegacyTransformation); HttpContext.Items["PageRequest"] = pageRequest; CMSPageRequest model = pageRequest; if (pageRequest is ContentUnitPreviewRequest) { model = (pageRequest as ContentUnitPreviewRequest).Root as CMSPageRequest; model.Tag = "CUPreview"; } return(renderEngine.Render(model)); }
/// <summary> /// This is the method that put search pieces together, including constructing /// instructions, performing search, and attach search results on page request object. /// </summary> /// <param name="pageRequest"></param> protected void _GetSearchResults(CMSPageRequest pageRequest) { int pagesize, page; bool all; SiteSearch siteSearch; SearchInstruction instructions = getSearchInstructions(pageRequest, out page, out pagesize, out all); Ingeniux.Search.Search search = new Ingeniux.Search.Search(Request); int count = 0; //use the SearchInstruction based overload method to achieve maxt flexibility pageRequest.Tag = search.QueryFinal(SiteSearch, out count, instructions, 200, all, page, pagesize); }
private static ControllerSummary locateControllerByRequest(CMSPageRequest pageRequest, ref string controller) { var schema = pageRequest.RootElementName; if (_ControllerSummaries == null) { _ControllerSummaries = (from c in TypeFinder.GetDerivedTypesFromAppDomain(typeof(CMSPageDefaultController)) where !c.IsAbstract && !c.IsInterface select new ControllerSummary(c)).ToArray(); } var matchingController = _ControllerSummaries.Where( c => !string.IsNullOrEmpty(schema) && c.Name == schema + "Controller") .FirstOrDefault(); if (matchingController != null) { controller = schema; } return(matchingController); }
/// <summary> /// The standard CMS page handling. If a view with the root element name exists, use it. Otherwise, try to transform /// the page xml content with XSLT, via traditional MSXML 4 DOM, like the old CMS Runtime engine. /// This ensures an existing site can start using the new MVC runtime without any work, and slowly convert to full MVC site page type by page type. /// /// </summary> /// <param name="pageRequest"></param> /// <remarks>This method generally doesn't need overriding at all. Only override it is additional data need to be passed down to view. (e.g Cartella data).e</remarks> /// <returns></returns> internal virtual ActionResult viewOrXsltFallback(CMSPageRequest pageRequest) { string thisControllerName = this.GetType().Name.SubstringBefore("Controller", true, true); string controllerName = thisControllerName; locateControllerByRequest(pageRequest, ref controllerName); string viewName = controllerName != thisControllerName ? "../" + controllerName + "/" + pageRequest.ViewName : pageRequest.ViewName; ViewResult viewResult = View(viewName, pageRequest); ViewEngineResult viewEngineResult = viewResult.ViewEngineCollection.FindView(ControllerContext, viewResult.ViewName, viewResult.MasterName); if (viewEngineResult != null && viewEngineResult.View != null && viewEngineResult.ViewEngine != null) { return(viewResult); } else { //create xslt result, if preview, use the preview site path for xslt string sitePath = pageRequest is CMSPagePreviewRequest ? _DTSitePath : _SitePath; return(new XsltTransformResult(pageRequest, sitePath, _UseTempStylesheetsLocation, _SitePath, _LegacyTransformation)); } }
/// <summary> /// This is the only method that need overriding. /// The goal of override is to set the search results object as .Tag of the pageRequest. /// </summary> /// <param name="pageRequest"></param> /// <returns></returns> internal override ActionResult handleStandardCMSPageRequest(CMSPageRequest pageRequest) { _GetSearchResults(pageRequest); return(base.handleStandardCMSPageRequest(pageRequest)); }
/// <summary> /// This is the method to process request with remaining path. /// Requests with remaining path are routes that will live under a CMS page, and need to use the CMS parent page content /// for part of rendering. /// By default, it is considered as non-existing route and will be throwing 404. Implementer can indeed customize this method directly /// or have sub class to override it. /// </summary> /// <param name="pageRequest"></param> /// <param name="remainingPath"></param> /// <remarks>If remainging path request is to be handled for specific subclass controller, suggest to call "handleStandardCMSPageRequest" /// and add additional information on the ActionResult (view data)</remarks> /// <returns></returns> protected virtual ActionResult handleCmsPageRequestWithRemainingPath(CMSPageRequest pageRequest, string remainingPath) { //throw 404 error, and let the 404 page handle it throw new HttpException(404, Ingeniux.Runtime.Properties.Resources.CannotLocateIngeniuxCMSPage); }
protected void _GetSearchResults(CMSPageRequest pageRequest) { int pagesize, page; bool all; Search.SiteSearch siteSearch; SearchInstruction instructions = getSearchInstructions(pageRequest, out page, out pagesize, out all, out siteSearch); //override pagesize from Schema var pgSize = pageRequest.GetElementValue("ResultsPageSize"); if (pgSize != null) { pagesize = pgSize.ToInt() ?? 10; } Search.Search search = new Search.Search(Request); int count = 0; if (search != null) { //use the SearchInstruction based overload method to achieve max flexibility (non-paginated results) var pageResults = search.QueryFinal(siteSearch, out count, instructions, 200, true); //find matches for both member records and pages var M = new MembersWrapper(); string termsString = pageRequest.QueryString["terms"] ?? ""; //var memDic = M.Search(termsString); var memDic = new List <KeyValuePair <string, Member> >(); var pgCollection = pageResults .Select(r => new KeyValuePair <float, SearchResultItem>(r.Score, r)); //apply sourceFilter and merge the two dictionaries string sourceFilter = pageRequest.QueryString["sourceFilter"] ?? ""; IEnumerable <KeyValuePair <float, object> > mergedCollection = new KeyValuePair <float, object> [0]; if (sourceFilter == "" || sourceFilter != "members") { mergedCollection = pgCollection .Where(x => { bool externalItem = (x.Value.Type == "ingeniux.search.htmlsitesource"); return(sourceFilter == "" || (sourceFilter == "local" && !externalItem) || (sourceFilter == "bni.com" && externalItem)); }) .Select(x => new KeyValuePair <float, object>(x.Key, x.Value)); } if (sourceFilter == "" || sourceFilter == "members") { mergedCollection = mergedCollection .Concat(memDic .Select(x => new KeyValuePair <float, object>(float.Parse(x.Key.SubstringBefore("_")), x.Value))); } //sort results var returnResults = mergedCollection.OrderByDescending(x => x.Key).Select(x => x.Value).ToList(); //apply pagination ViewBag.totalResults = returnResults.Count; ViewBag.pageSize = pagesize; pageRequest.Tag = returnResults.Skip((page - 1) * pagesize).Take(pagesize).ToList(); //pageRequest.Tag = mergedDic; //no pagination } }
protected virtual ActionResult handleRequest(Func <ICMSRoutingRequest, ActionResult> nonCmsRouteHandle, Func <CMSPageRequest, string, ActionResult> remainingPathHandle, Func <CMSPageRequest, ActionResult> standardCmsPageHandle) { if (_InvalidPageResult != null) { return(_InvalidPageResult); } if (_AllowTfrm) { //exception for settings.xml and urlmap.xml, allow them to display only if string path = Request.Url.AbsolutePath.ToLower(); if (path.EndsWith("settings/settings.xml") || path.EndsWith("settings/urlmap.xml")) { var relativePath = path.Substring(Request.ApplicationPath.Length); string filePath = Path.Combine(_SitePath, relativePath.TrimStart('/').Replace("/", @"\")); if (System.IO.File.Exists(filePath)) { return(new XmlResult(XDocument.Load(filePath))); } } } if (_CMSPageRoutingRequest.CMSRequest == null || !_CMSPageRoutingRequest.CMSRequest.Exists) { return(nonCmsRouteHandle(_CMSPageRoutingRequest)); } ICMSRequest cmsRequest = _CMSPageRoutingRequest.CMSRequest; //if the request is for redirection, do redirect if (cmsRequest is CMSPageRedirectRequest) { var cmsRedir = cmsRequest as CMSPageRedirectRequest; //string absoluteUrl = cmsRedir.FinalUrl.ToAbsoluteUrl(); string absoluteUrl = cmsRedir.FinalUrl; if (!absoluteUrl.StartsWith("http://") && !absoluteUrl.StartsWith("https://")) { absoluteUrl = VirtualPathUtility.ToAbsolute("~/" + absoluteUrl.TrimStart('/')); } if (cmsRedir.NoRedirectCache) { Response.Expires = -1; Response.Cache.SetCacheability(HttpCacheability.NoCache); } if (cmsRedir.IsPermanent) { Response.RedirectPermanent(absoluteUrl); } else { Response.Redirect(absoluteUrl); } return(null); } else if (cmsRequest is CMSPageRequest) { CMSPageRequest pageRequest = cmsRequest as CMSPageRequest; //first handle requests with remaining path, if the method doesn't return any result, proceed //to treat it as a standard CMS page string remainigPath = _CMSPageRoutingRequest.RemaingPath; if (!string.IsNullOrEmpty(remainigPath)) { ActionResult cmsWithRemainingPathResult = remainingPathHandle(pageRequest, remainigPath); if (cmsWithRemainingPathResult != null) { return(cmsWithRemainingPathResult); } } if (pageRequest.RestrictedAccess) { disableClientSideCaching(); } return(standardCmsPageHandle(pageRequest)); } else { throw new HttpException(501, Ingeniux.Runtime.Properties.Resources.RequestTypeNotRecognized); } }
internal override System.Web.Mvc.ActionResult handleStandardCMSPageRequest(CMSPageRequest pageRequest) { //handle form post var isSignupPost = pageRequest.Form["signupPost"] == "1"; if (isSignupPost) { var forms = pageRequest.Form; //handle sign up first UserInfo user = new UserInfo { Name = forms["Name"], CoMembers = forms["CoMembers"], Address = forms["Address"], City = forms["City"], State = forms["State"], Zip = forms["Zip"], Phone = forms["Phone"], Email = forms["Email"], Occupation = forms["Occupation"], }; bool isNewUser = forms["IsNewUser"] == "true"; if (isNewUser) { user.UserId = forms["UserId"]; user.Password = forms["Password"]; } else { var sessionUser = Session["user"] as UserInfo; sessionUser.Name = user.Name; sessionUser.CoMembers = user.CoMembers; sessionUser.Address = user.Address; sessionUser.City = user.City; sessionUser.State = user.State; sessionUser.Zip = user.Zip; sessionUser.Phone = user.Phone; sessionUser.Email = user.Email; sessionUser.Occupation = user.Occupation; user = sessionUser; } AuthenticationLib auth = new AuthenticationLib(); try { auth.SignupOrUpdate(user, isNewUser); pageRequest.Tag = isSignupPost; //issue a temp id just allow birds list update Session["tempIdForBirdList"] = user.UserId; } catch (UserExistException e) { pageRequest.Tag = user.Name; } catch (Exception e) { pageRequest.Tag = "Signup Error: " + e.Message; } } return(base.handleStandardCMSPageRequest(pageRequest)); }
protected override ActionResult handleCmsPageRequestWithRemainingPath(CMSPageRequest pageRequest, string remainingPath) { ViewData["RemaingPath"] = remainingPath; return(View(pageRequest)); }
/// <summary> /// This is the method that will construct the SearchInstruction object. /// This is the place to manipulate the SearchInstruction object in order to /// generate a query with custom logics /// </summary> /// <param name="pageRequest">CMS Page object</param> /// <param name="page">Page number, default to 1</param> /// <param name="pagesize">Page size, default to 10</param> /// <param name="all">All records or not</param> /// <returns>Customized search instructions</returns> private SearchInstruction getSearchInstructions(CMSPageRequest pageRequest, out int page, out int pagesize, out bool all) { string[] termsA = pageRequest.QueryString["terms"] .ToNullOrEmptyHelper() .Propagate( s => s.Split(',')) .Return(new string[0]); //default to not categories filter string[] catsA = pageRequest.QueryString["catids"] .ToNullOrEmptyHelper() .Propagate( s => s.Split(',')) .Return(new string[0]); bool categoryById = pageRequest.QueryString["catsbyid"] .ToNullOrEmptyHelper() .Propagate( sa => sa.ToBoolean()) .Return(false); //default to no types filter string[] typesA = pageRequest.QueryString["types"] .ToNullOrEmptyHelper() .Propagate( s => s.Split(',')) .Return(new string[0]); string[] localesA = pageRequest.QueryString["locales"] .ToNullOrEmptyHelper() .Propagate( s => s.Split(',')) .Return(new string[0]); //default to first page instead of all records string pageStr = pageRequest.QueryString["page"] .ToNullOrEmptyHelper() .Return("1"); //default page size to 10 records pagesize = pageRequest.QueryString["pagesize"] .ToNullOrEmptyHelper() .Propagate( ps => ps.ToInt()) .Propagate( ps => ps.Value) .Return(10); string[] sourcesA = pageRequest.QueryString["sources"] .ToNullOrEmptyHelper() .Propagate( s => s.Split(',')) .Return(new string[0]); string sortby = pageRequest.QueryString["sortby"] ?? string.Empty; bool sortAscending = pageRequest.QueryString["sortasc"] .ToNullOrEmptyHelper() .Propagate( sa => sa.ToBoolean()) .Return(false); all = false; if (!int.TryParse(pageStr, out page)) { all = true; } else if (page < 1) { all = true; } //use the hiliter in configuration, or default hiliter with strong tags QueryBuilder.CategoryFilterOperator = Ingeniux.Search.Search.GetCategoryFilterOperator(); SearchInstruction instructions = new SearchInstruction(SiteSearch.DefaultQueryAnalyzer); instructions.AddQuery( instructions.GetFullTextTermQuery(Occur.MUST, true, termsA)); if (typesA.Length > 0) { instructions.AddQuery( instructions.GetTypeQuery(Occur.MUST, typesA)); } if (sourcesA.Length > 0) { instructions.AddQuery( instructions.GetSourceQuery(Occur.MUST, sourcesA)); } if (!string.IsNullOrWhiteSpace(sortby)) { instructions.AddSort(new SortField(sortby, CultureInfo.InvariantCulture, !sortAscending)); } if (localesA.Length > 0) { instructions.AddQuery( instructions.GetLocaleQuery(Occur.MUST, localesA)); } if (catsA.Length > 0) { instructions.AddQuery( (!categoryById) ? instructions.GetCategoryQuery(Occur.MUST, QueryBuilder.CategoryFilterOperator, catsA) : instructions.GetCategoryIdQuery(Occur.MUST, QueryBuilder.CategoryFilterOperator, catsA)); } return(instructions); }