private bool ValidatePageUrlSettings(PageSettings pageSettings, TabInfo tab, ref string invalidField, ref string errorMessage) { var portalSettings = PortalController.Instance.GetCurrentPortalSettings(); var urlPath = !string.IsNullOrEmpty(pageSettings.Url) ? pageSettings.Url.TrimStart('/') : string.Empty; if (string.IsNullOrEmpty(urlPath)) { return(true); } bool modified; //Clean Url var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId))); urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); if (modified) { errorMessage = Localization.GetString("UrlPathCleaned"); invalidField = "url"; return(false); } //Validate for uniqueness FriendlyUrlController.ValidateUrl(urlPath, tab?.TabID ?? Null.NullInteger, portalSettings, out modified); if (modified) { errorMessage = Localization.GetString("UrlPathNotUnique"); invalidField = "url"; return(false); } return(true); }
public static string cleanUrl(string url, int portalId) { bool replaced = false; FriendlyUrlOptions options = UrlRewriterUtils.GetOptionsFromSettings(FriendlyUrlController.GetCurrentSettings(portalId)); return(FriendlyUrlController.CleanNameForUrl(url, options, out replaced).ToLower()); }
public HttpResponseMessage UpdateVanityUrl(VanityUrlDTO vanityUrl) { bool modified; // Clean Url var options = UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(this.PortalSettings.PortalId)); var cleanUrl = FriendlyUrlController.CleanNameForUrl(vanityUrl.Url, options, out modified); if (modified) { return(this.Request.CreateResponse( HttpStatusCode.OK, new { Result = "warning", Title = Localization.GetString("CleanWarningTitle", Localization.SharedResourceFile), Message = Localization.GetString("ProfileUrlCleaned", Localization.SharedResourceFile), SuggestedUrl = cleanUrl, })); } // Validate for uniqueness var uniqueUrl = FriendlyUrlController.ValidateUrl(cleanUrl, -1, this.PortalSettings, out modified); if (modified) { return(this.Request.CreateResponse( HttpStatusCode.OK, new { Result = "warning", Title = Localization.GetString("DuplicateUrlWarningTitle", Localization.SharedResourceFile), Message = Localization.GetString("ProfileUrlNotUnique", Localization.SharedResourceFile), SuggestedUrl = uniqueUrl, })); } var user = this.PortalSettings.UserInfo; user.VanityUrl = uniqueUrl; UserController.UpdateUser(this.PortalSettings.PortalId, user); DataCache.RemoveCache(string.Format(CacheController.VanityUrlLookupKey, this.PortalSettings.PortalId)); // Url is clean and validated so we can update the User return(this.Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" })); }
public string CleanTabUrl(string url) { if (string.IsNullOrEmpty(url)) { return(url); } var urlPath = url.TrimStart('/'); bool modified; var portalSettings = PortalController.Instance.GetCurrentPortalSettings(); var friendlyUrlSettings = new FriendlyUrlSettings(portalSettings.PortalId); urlPath = UrlRewriterUtils.CleanExtension(urlPath, friendlyUrlSettings, string.Empty); //Clean Url var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(friendlyUrlSettings)); urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); return('/' + urlPath); }
public HttpResponseMessage UpdateCustomUrl(SaveUrlDto dto) { var urlPath = dto.Path.ValueOrEmpty().TrimStart('/'); bool modified; //Clean Url var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(PortalSettings.PortalId))); //now clean the path urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); if (modified) { return(Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error", Localization.GlobalResourceFile), SuggestedUrlPath = "/" + urlPath })); } //Validate for uniqueness urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, PortalSettings, out modified); if (modified) { return(Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ErrorMessage = Localization.GetString("UrlPathNotUnique.Error", Localization.GlobalResourceFile), SuggestedUrlPath = "/" + urlPath })); } var tab = PortalSettings.ActiveTab; var cultureCode = LocaleController.Instance.GetLocales(PortalId) .Where(l => l.Value.KeyID == dto.LocaleKey) .Select(l => l.Value.Code) .SingleOrDefault(); if (dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture) == "200") { //We need to check if we are updating a current url or creating a new 200 var tabUrl = tab.TabUrls.SingleOrDefault(t => t.SeqNum == dto.Id && t.HttpStatus == "200"); if (tabUrl == null) { //Just create Url tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture), IsSystem = dto.IsSystem // false }; TabController.Instance.SaveTabUrl(tabUrl, PortalId, true); } else { //Change the original 200 url to a redirect tabUrl.HttpStatus = "301"; tabUrl.SeqNum = dto.Id; TabController.Instance.SaveTabUrl(tabUrl, PortalId, true); //Add new custom url tabUrl.Url = dto.Path.ValueOrEmpty(); tabUrl.HttpStatus = "200"; tabUrl.SeqNum = tab.TabUrls.Max(t => t.SeqNum) + 1; TabController.Instance.SaveTabUrl(tabUrl, PortalId, true); } } else { //Just update the url var tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture), IsSystem = dto.IsSystem // false }; TabController.Instance.SaveTabUrl(tabUrl, PortalId, true); } var response = new { Success = true, }; return(Request.CreateResponse(HttpStatusCode.OK, response)); }
private void BindData() { if (User != null) { //If trying to add a SuperUser - check that user is a SuperUser if (VerifyUserPermissions() == false) { return; } if (!Page.IsPostBack) { if ((Request.QueryString["pageno"] != null)) { PageNo = int.Parse(Request.QueryString["pageno"]); } else { PageNo = 0; } } userForm.DataSource = User; if (!Page.IsPostBack) { userForm.DataBind(); } ctlPassword.User = User; ctlPassword.DataBind(); if ((!DisplayServices)) { servicesTab.Visible = false; } else { ctlServices.User = User; ctlServices.DataBind(); } BindUser(); ctlProfile.User = User; ctlProfile.DataBind(); dnnServicesDetails.Visible = DisplayServices; if (!IsPostBack) { var urlSettings = new DotNetNuke.Entities.Urls.FriendlyUrlSettings(PortalSettings.PortalId); var showVanityUrl = (Config.GetFriendlyUrlProvider() == "advanced") && !User.IsSuperUser; if (showVanityUrl) { VanityUrlRow.Visible = true; if (String.IsNullOrEmpty(User.VanityUrl)) { //Clean Display Name bool modified; var options = UrlRewriterUtils.GetOptionsFromSettings(urlSettings); var cleanUrl = FriendlyUrlController.CleanNameForUrl(User.DisplayName, options, out modified); var uniqueUrl = FriendlyUrlController.ValidateUrl(cleanUrl, -1, PortalSettings, out modified).ToLowerInvariant(); VanityUrlAlias.Text = String.Format("{0}/{1}/", PortalSettings.PortalAlias.HTTPAlias, urlSettings.VanityUrlPrefix); VanityUrlTextBox.Text = uniqueUrl; ShowVanityUrl = true; } else { VanityUrl.Text = String.Format("{0}/{1}/{2}", PortalSettings.PortalAlias.HTTPAlias, urlSettings.VanityUrlPrefix, User.VanityUrl); ShowVanityUrl = false; } } } } else { AddModuleMessage("NoUser", ModuleMessage.ModuleMessageType.YellowWarning, true); DisableForm(); } }
public FriendlyUrlOptions GetExtendOptionsForURLs(int portalId) { return(UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalId)))); }
public PageUrlResult CreateCustomUrl(SaveUrlDto dto, TabInfo tab) { var portalSettings = PortalController.Instance.GetCurrentPortalSettings(); var urlPath = dto.Path.ValueOrEmpty().TrimStart('/'); bool modified; //Clean Url var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId))); urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); if (modified) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error"), SuggestedUrlPath = "/" + urlPath }); } //Validate for uniqueness urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, portalSettings, out modified); if (modified) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("UrlPathNotUnique.Error"), SuggestedUrlPath = "/" + urlPath }); } if (tab.TabUrls.Any(u => u.Url.ToLowerInvariant() == dto.Path.ValueOrEmpty().ToLowerInvariant() && (u.PortalAliasId == dto.SiteAliasKey || u.PortalAliasId == -1))) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("DuplicateUrl.Error") }); } var seqNum = (tab.TabUrls.Count > 0) ? tab.TabUrls.Max(t => t.SeqNum) + 1 : 1; var portalLocales = LocaleController.Instance.GetLocales(portalSettings.PortalId); var cultureCode = portalLocales.Where(l => l.Value.KeyID == dto.LocaleKey) .Select(l => l.Value.Code) .SingleOrDefault(); var portalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage; if (portalAliasUsage == PortalAliasUsageType.Default) { var alias = PortalAliasController.Instance.GetPortalAliasesByPortalId(portalSettings.PortalId) .SingleOrDefault(a => a.PortalAliasID == dto.SiteAliasKey); if (string.IsNullOrEmpty(cultureCode) || alias == null) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("InvalidRequest.Error") }); } } else { var cultureAlias = PortalAliasController.Instance.GetPortalAliasesByPortalId(portalSettings.PortalId) .FirstOrDefault(a => a.CultureCode == cultureCode); if (portalLocales.Count > 1 && !portalSettings.ContentLocalizationEnabled && (string.IsNullOrEmpty(cultureCode) || cultureAlias == null)) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("InvalidRequest.Error") }); } } var tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = seqNum, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = portalAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture), IsSystem = false }; TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); return(new PageUrlResult { Success = true, Id = seqNum // returns Id of the created Url }); }
public PageUrlResult UpdateCustomUrl(SaveUrlDto dto, TabInfo tab) { var portalSettings = PortalController.Instance.GetCurrentPortalSettings(); var urlPath = dto.Path.ValueOrEmpty().TrimStart('/'); bool modified; //Clean Url var options = UrlRewriterUtils.ExtendOptionsForCustomURLs( UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId))); //now clean the path urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); if (modified) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error"), SuggestedUrlPath = "/" + urlPath }); } //Validate for uniqueness urlPath = FriendlyUrlController.ValidateUrl(urlPath, tab.TabID, portalSettings, out modified); if (modified) { return(new PageUrlResult { Success = false, ErrorMessage = Localization.GetString("UrlPathNotUnique.Error"), SuggestedUrlPath = "/" + urlPath }); } var cultureCode = LocaleController.Instance.GetLocales(portalSettings.PortalId) .Where(l => l.Value.KeyID == dto.LocaleKey) .Select(l => l.Value.Code) .SingleOrDefault() ?? portalSettings.DefaultLanguage; var statusCodeKey = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture); var tabUrl = tab.TabUrls.SingleOrDefault(t => t.SeqNum == dto.Id && t.HttpStatus == statusCodeKey); if (statusCodeKey == "200") { //We need to check if we are updating a current url or creating a new 200 if (tabUrl == null) { //Just create Url tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = "200", IsSystem = dto.IsSystem // false }; TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } else { if (!tabUrl.Url.Equals("/" + urlPath, StringComparison.InvariantCultureIgnoreCase)) { //Change the original 200 url to a redirect tabUrl.HttpStatus = "301"; tabUrl.SeqNum = dto.Id; TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); //Add new custom url tabUrl.Url = dto.Path.ValueOrEmpty(); tabUrl.HttpStatus = "200"; tabUrl.SeqNum = tab.TabUrls.Max(t => t.SeqNum) + 1; tabUrl.CultureCode = cultureCode; tabUrl.PortalAliasId = dto.SiteAliasKey; tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage; tabUrl.QueryString = dto.QueryString.ValueOrEmpty(); TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } else { //Update the original 200 url tabUrl.CultureCode = cultureCode; tabUrl.PortalAliasId = dto.SiteAliasKey; tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage; tabUrl.QueryString = dto.QueryString.ValueOrEmpty(); TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } } } else { //Update the original non 200 url if (tabUrl == null) { tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = statusCodeKey, IsSystem = dto.IsSystem // false }; TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } else { tabUrl.CultureCode = cultureCode; tabUrl.PortalAliasId = dto.SiteAliasKey; tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage; tabUrl.Url = dto.Path.ValueOrEmpty(); tabUrl.HttpStatus = statusCodeKey; tabUrl.QueryString = dto.QueryString.ValueOrEmpty(); TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); } } return(new PageUrlResult { Success = true }); }
private Outcome UpdateTabUrl(TabInfo tab, int portalId, string fieldValue) { var portalSettings = new PortalSettings(portalId); var urlPath = fieldValue.ValueOrEmpty().TrimStart('/'); bool modified; // Clean Url var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId))); urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); if (modified) { return(new Outcome() { Success = false, ErrorMessage = Constants.ERROR_PAGE_URL_VALUE, //CustomUrlPathCleaned Suggestion = string.Concat(Constants.SLASH, urlPath) }); } // Validate for uniqueness urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, portalSettings, out modified); if (modified) { return(new Outcome() { Success = false, ErrorMessage = Constants.ERROR_PAGE_URL_NOT_UNIQUE, //UrlPathNotUnique Suggestion = string.Concat(Constants.SLASH, urlPath) }); } if (tab.TabUrls.Any(u => u.Url.ToLowerInvariant() == urlPath.ValueOrEmpty().ToLowerInvariant() && (u.PortalAliasId == portalSettings.PrimaryAlias.PortalAliasID || u.PortalAliasId == -1))) { return(new Outcome { Success = false, ErrorMessage = Constants.ERROR_PAGE_URL_DUPLICATE, //DuplicateUrl Suggestion = string.Concat(Constants.SLASH, urlPath) }); } var seqNum = (tab.TabUrls.Count > 0) ? tab.TabUrls.Max(t => t.SeqNum) + 1 : 1; var tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = seqNum, PortalAliasId = portalSettings.PrimaryAlias.PortalAliasID, PortalAliasUsage = PortalAliasUsageType.Default, QueryString = string.Empty, Url = urlPath.ValueOrEmpty(), CultureCode = portalSettings.CultureCode, HttpStatus = Constants.RESPONSE_STATUS_200, IsSystem = false, }; TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true); //tab.Url = fieldValue; return(new Outcome { Success = true, ErrorMessage = string.Empty, Suggestion = string.Empty }); }
private void BindData() { if (this.User != null) { // If trying to add a SuperUser - check that user is a SuperUser if (this.VerifyUserPermissions() == false) { return; } if (!this.Page.IsPostBack) { if (this.Request.QueryString["pageno"] != null) { this.PageNo = int.Parse(this.Request.QueryString["pageno"]); } else { this.PageNo = 0; } } this.userForm.DataSource = this.User; // hide username field in UseEmailAsUserName mode bool disableUsername = PortalController.GetPortalSettingAsBoolean("Registration_UseEmailAsUserName", this.PortalId, false); if (disableUsername) { this.userForm.Items[0].Visible = false; } if (!this.Page.IsPostBack) { this.userForm.DataBind(); } this.ctlPassword.User = this.User; this.ctlPassword.DataBind(); if (!this.DisplayServices) { this.servicesTab.Visible = false; } else { this.ctlServices.User = this.User; this.ctlServices.DataBind(); } this.BindUser(); this.ctlProfile.User = this.User; this.ctlProfile.DataBind(); this.dnnServicesDetails.Visible = this.DisplayServices; var urlSettings = new DotNetNuke.Entities.Urls.FriendlyUrlSettings(this.PortalSettings.PortalId); var showVanityUrl = (Config.GetFriendlyUrlProvider() == "advanced") && !this.User.IsSuperUser; if (showVanityUrl) { this.VanityUrlRow.Visible = true; if (string.IsNullOrEmpty(this.User.VanityUrl)) { // Clean Display Name bool modified; var options = UrlRewriterUtils.GetOptionsFromSettings(urlSettings); var cleanUrl = FriendlyUrlController.CleanNameForUrl(this.User.DisplayName, options, out modified); var uniqueUrl = FriendlyUrlController.ValidateUrl(cleanUrl, -1, this.PortalSettings, out modified).ToLowerInvariant(); this.VanityUrlAlias.Text = string.Format("{0}/{1}/", this.PortalSettings.PortalAlias.HTTPAlias, urlSettings.VanityUrlPrefix); this.VanityUrlTextBox.Text = uniqueUrl; this.ShowVanityUrl = true; } else { this.VanityUrl.Text = string.Format("{0}/{1}/{2}", this.PortalSettings.PortalAlias.HTTPAlias, urlSettings.VanityUrlPrefix, this.User.VanityUrl); this.ShowVanityUrl = false; } } } else { this.AddModuleMessage("NoUser", ModuleMessage.ModuleMessageType.YellowWarning, true); this.DisableForm(); } }
public HttpResponseMessage UpdateCustomUrl(SaveUrlDto dto) { var tab = PortalSettings.ActiveTab; var urlPath = dto.Path.ValueOrEmpty().TrimStart('/'); HttpResponseMessage response; if (string.IsNullOrEmpty(urlPath)) { var tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, }; TestableTabController.Instance.DeleteTabUrl(tabUrl, PortalId, true); response = Request.CreateResponse(HttpStatusCode.OK, new { Success = true, }); } else { bool modified; //Clean Url var options = UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(PortalSettings.PortalId)); //custom urls are special in that they can contain the / character to create path levels options.ReplaceChars = options.ReplaceChars.Replace("/", ""); options.IllegalChars = options.IllegalChars.Replace("/", ""); options.RegexMatch = options.RegexMatch.Replace("[^", "[^/"); //now clean the path urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified); if (modified) { return(Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ErrorMessage = Localization.GetString("UrlPathCleaned.Error", Localization.GlobalResourceFile), SuggestedUrlPath = "/" + urlPath })); } //Validate for uniqueness urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, PortalSettings, out modified); if (modified) { return(Request.CreateResponse(HttpStatusCode.OK, new { Success = false, ErrorMessage = Localization.GetString("UrlPathNotUnique.Error", Localization.GlobalResourceFile), SuggestedUrlPath = "/" + urlPath })); } var cultureCode = LocaleController.Instance.GetLocales(PortalId) .Where(l => l.Value.KeyID == dto.LocaleKey) .Select(l => l.Value.Code) .SingleOrDefault(); var tabUrl = new TabUrlInfo { TabId = tab.TabID, SeqNum = dto.Id, PortalAliasId = dto.SiteAliasKey, PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage, QueryString = dto.QueryString.ValueOrEmpty(), Url = dto.Path.ValueOrEmpty(), CultureCode = cultureCode, HttpStatus = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture), IsSystem = dto.IsSystem // false }; TestableTabController.Instance.SaveTabUrl(tabUrl, PortalId, true); response = Request.CreateResponse(HttpStatusCode.OK, new { Success = true, }); } return(response); }