From 55c7f72d8e8dbd74b42baecaa1ed62842a41d972 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Fri, 29 Mar 2013 23:14:42 +0600 Subject: [PATCH] Converts create.aspx to have the correct webforms file/class structure, fixed logging for userTask, fixed issue with last regex fix for xss --- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 7 +++ src/Umbraco.Web.UI/umbraco/Create.aspx.cs | 44 +++++++++++++++ .../umbraco/Create.aspx.designer.cs} | 11 ++-- src/Umbraco.Web.UI/umbraco/create.aspx | 9 +++- .../Application/HistoryManager.js | 2 +- src/Umbraco.Web/Umbraco.Web.csproj | 17 +++--- .../umbraco.presentation/umbraco/create.aspx | 38 ------------- .../umbraco/create.aspx.cs | 53 +++++++------------ .../umbraco/create/userTasks.cs | 43 ++++----------- 9 files changed, 99 insertions(+), 125 deletions(-) create mode 100644 src/Umbraco.Web.UI/umbraco/Create.aspx.cs rename src/{Umbraco.Web/umbraco.presentation/umbraco/create.aspx.designer.cs => Umbraco.Web.UI/umbraco/Create.aspx.designer.cs} (70%) delete mode 100644 src/Umbraco.Web/umbraco.presentation/umbraco/create.aspx diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 0b57950ed3..b9974b8334 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -289,6 +289,13 @@ loadStarterKits.ascx + + create.aspx + ASPXCodeBehind + + + create.aspx + editMacro.aspx ASPXCodeBehind diff --git a/src/Umbraco.Web.UI/umbraco/Create.aspx.cs b/src/Umbraco.Web.UI/umbraco/Create.aspx.cs new file mode 100644 index 0000000000..b30e2a3f3b --- /dev/null +++ b/src/Umbraco.Web.UI/umbraco/Create.aspx.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Xml; +using Umbraco.Core; +using Umbraco.Core.IO; +using umbraco.cms.presentation.Trees; + +namespace Umbraco.Web.UI.Umbraco +{ + public partial class Create : global::umbraco.cms.presentation.Create + { + + //protected override void OnLoad(EventArgs e) + //{ + // if (SecurityCheck(Request.QueryString["nodeType"])) + // { + // //if we're allowed, then continue + // base.OnLoad(e); + // } + // else + // { + // //otherwise show an error + // UI.Visible = false; + // AccessError.Visible = true; + // } + //} + + //private bool SecurityCheck(string treeAlias) + //{ + // var tree = TreeDefinitionCollection.Instance.FindTree(treeAlias); + // if (tree != null) + // { + // //does the current user have access to the current app? + // var user = this.getUser(); + // var userApps = user.Applications; + // return userApps.Any(x => x.alias.InvariantEquals(tree.App.alias)); + // } + // return false; + //} + + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create.aspx.designer.cs b/src/Umbraco.Web.UI/umbraco/Create.aspx.designer.cs similarity index 70% rename from src/Umbraco.Web/umbraco.presentation/umbraco/create.aspx.designer.cs rename to src/Umbraco.Web.UI/umbraco/Create.aspx.designer.cs index a3d4616bfd..12722853d4 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create.aspx.designer.cs +++ b/src/Umbraco.Web.UI/umbraco/Create.aspx.designer.cs @@ -1,25 +1,24 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.3053 // // Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// the code is regenerated. // //------------------------------------------------------------------------------ -namespace umbraco.cms.presentation { +namespace Umbraco.Web.UI.Umbraco { public partial class Create { /// - /// UI control. + /// AccessError control. /// /// /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// - protected global::System.Web.UI.WebControls.PlaceHolder UI; + protected global::System.Web.UI.WebControls.PlaceHolder AccessError; } } diff --git a/src/Umbraco.Web.UI/umbraco/create.aspx b/src/Umbraco.Web.UI/umbraco/create.aspx index 8bcc0cacb9..ba4b091eda 100644 --- a/src/Umbraco.Web.UI/umbraco/create.aspx +++ b/src/Umbraco.Web.UI/umbraco/create.aspx @@ -1,4 +1,4 @@ -<%@ Page Language="c#" MasterPageFile="masterpages/umbracoDialog.Master" Codebehind="create.aspx.cs" AutoEventWireup="True" Inherits="umbraco.cms.presentation.Create" %> +<%@ Page Language="c#" MasterPageFile="masterpages/umbracoDialog.Master" Codebehind="Create.aspx.cs" AutoEventWireup="True" Inherits="Umbraco.Web.UI.Umbraco.Create" %> <%@ Register Namespace="umbraco" TagPrefix="umb" Assembly="umbraco" %> @@ -18,6 +18,13 @@ + +
+

+ The current user does not have access to create this type of object +

+
+
diff --git a/src/Umbraco.Web.UI/umbraco_client/Application/HistoryManager.js b/src/Umbraco.Web.UI/umbraco_client/Application/HistoryManager.js index b1f44a8f46..bed8630cf5 100644 --- a/src/Umbraco.Web.UI/umbraco_client/Application/HistoryManager.js +++ b/src/Umbraco.Web.UI/umbraco_client/Application/HistoryManager.js @@ -13,7 +13,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Controls"); function getHashFragment(frag) { //tests for xss and ensures only the first alphanumeric chars are matched var result = hashFragmentRegex.exec(frag); - if (result.length > 0) { + if (result != null && result.length > 0) { return result[0]; } return ""; diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 02045b1eaa..89351a42c1 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -342,6 +342,9 @@ + + ASPXCodeBehind + ASPXCodeBehind @@ -980,13 +983,6 @@ SendPublish.aspx - - create.aspx - ASPXCodeBehind - - - create.aspx - content.ascx ASPXCodeBehind @@ -1935,7 +1931,9 @@ ASPXCodeBehind - + + ASPXCodeBehind + @@ -2006,9 +2004,6 @@ - - ASPXCodeBehind - ASPXCodeBehind diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create.aspx b/src/Umbraco.Web/umbraco.presentation/umbraco/create.aspx deleted file mode 100644 index 8bcc0cacb9..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create.aspx +++ /dev/null @@ -1,38 +0,0 @@ -<%@ Page Language="c#" MasterPageFile="masterpages/umbracoDialog.Master" Codebehind="create.aspx.cs" AutoEventWireup="True" Inherits="umbraco.cms.presentation.Create" %> - -<%@ Register Namespace="umbraco" TagPrefix="umb" Assembly="umbraco" %> - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create.aspx.cs index 764428c664..9555996f59 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create.aspx.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.ComponentModel; using System.Data; @@ -11,33 +11,34 @@ using System.Web.UI.HtmlControls; using System.Xml.XPath; using System.Xml; -using umbraco.IO; +using Umbraco.Core.IO; namespace umbraco.cms.presentation { - /// - /// Summary description for create. - /// - public partial class Create : BasePages.UmbracoEnsuredPage + + public class Create : BasePages.UmbracoEnsuredPage { protected umbWindow createWindow; - protected System.Web.UI.WebControls.Label helpText; - protected System.Web.UI.WebControls.TextBox rename; - protected System.Web.UI.WebControls.Label Label1; - protected System.Web.UI.WebControls.ListBox nodeType; + protected Label helpText; + protected TextBox rename; + protected Label Label1; + protected ListBox nodeType; + protected PlaceHolder UI; - protected void Page_Load(object sender, System.EventArgs e) + protected override void OnLoad(EventArgs e) { - // Load create definitions - string nodeType = Request.QueryString["nodeType"]; + base.OnLoad(e); - XmlDocument createDef = new XmlDocument(); - XmlTextReader defReader = new XmlTextReader(IOHelper.MapPath(SystemFiles.CreateUiXml)); + // Load create definitions + var nodeType = Request.QueryString["nodeType"]; + + var createDef = new XmlDocument(); + var defReader = new XmlTextReader(IOHelper.MapPath(SystemFiles.CreateUiXml)); createDef.Load(defReader); defReader.Close(); // Find definition for current nodeType - XmlNode def = createDef.SelectSingleNode("//nodeType [@alias = '" + nodeType + "']"); + var def = createDef.SelectSingleNode("//nodeType [@alias = '" + nodeType + "']"); if (def == null) { throw new ArgumentException("The create dialog for \"" + nodeType + "\" does not match anything defined in the \"" + SystemFiles.CreateUiXml + "\". This could mean an incorrectly installed package or a corrupt UI file"); @@ -46,7 +47,7 @@ namespace umbraco.cms.presentation try { //headerTitle.Text = title.Text; - UI.Controls.Add(new UserControl().LoadControl(SystemDirectories.Umbraco + def.SelectSingleNode("./usercontrol").FirstChild.Value)); + UI.Controls.Add(LoadControl(SystemDirectories.Umbraco + def.SelectSingleNode("./usercontrol").FirstChild.Value)); } catch (Exception ex) { @@ -54,24 +55,6 @@ namespace umbraco.cms.presentation } } - #region Web Form Designer generated code - override protected void OnInit(EventArgs e) - { - // - // CODEGEN: This call is required by the ASP.NET Web Form Designer. - // - InitializeComponent(); - base.OnInit(e); - } - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - - } - #endregion } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs index 050f0aade2..e169d1ee8e 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/userTasks.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.Security; +using Umbraco.Core.Logging; using umbraco.BusinessLogic; using umbraco.DataLayer; using umbraco.BasePages; @@ -11,35 +12,19 @@ namespace umbraco { public class userTasks : interfaces.ITaskReturnUrl { - - private string _alias; - private int _parentID; - private int _typeID; - private int _userID; private string _returnUrl = ""; public int UserId { - set { _userID = value; } - } - public int TypeID - { - set { _typeID = value; } - get { return _typeID; } + set { } } + public int TypeID { get; set; } - public string Alias - { - set { _alias = value; } - get { return _alias; } - } - public int ParentID - { - set { _parentID = value; } - get { return _parentID; } - } + public string Alias { get; set; } + + public int ParentID { get; set; } public string ReturnUrl { @@ -53,11 +38,11 @@ namespace umbraco //BusinessLogic.User.MakeNew(Alias, Alias, "", BusinessLogic.UserType.GetUserType(1)); //return true; - MembershipCreateStatus status = MembershipCreateStatus.ProviderError; + var status = MembershipCreateStatus.ProviderError; try { // Password is auto-generated. They are they required to change the password by editing the user information. - MembershipUser u = Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].CreateUser(Alias, + var u = Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].CreateUser(Alias, Membership.GeneratePassword( Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].MinRequiredPasswordLength, Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].MinRequiredNonAlphanumericCharacters), @@ -69,24 +54,16 @@ namespace umbraco } catch (Exception ex) { - Log.Add(LogTypes.Error, ParentID, String.Format("Failed to create the user. Error from provider: {0}", status.ToString())); - Log.Add(LogTypes.Debug, ParentID, ex.Message); + LogHelper.Error(string.Format("Failed to create the user. Error from provider: {0}", status.ToString()), ex); return false; } } public bool Delete() { - BusinessLogic.User u = BusinessLogic.User.GetUser(ParentID); + var u = User.GetUser(ParentID); u.disable(); return true; } - - public userTasks() - { - // - // TODO: Add constructor logic here - // - } } }