diff --git a/src/Umbraco.Web.UI.Client/src/less/main.less b/src/Umbraco.Web.UI.Client/src/less/main.less index 00cdd4f9b1..85ab4e6e56 100644 --- a/src/Umbraco.Web.UI.Client/src/less/main.less +++ b/src/Umbraco.Web.UI.Client/src/less/main.less @@ -157,7 +157,7 @@ h5.-black { } .controls-row { - padding-top: 5px; + padding-bottom: 5px; margin-left: 240px; } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs index bec91d3313..9734401d95 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs @@ -30,6 +30,8 @@ using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Services; using PropertyType = umbraco.cms.businesslogic.propertytype.PropertyType; +using System.Text.RegularExpressions; +using System.Text; namespace umbraco.cms.presentation.user { @@ -43,11 +45,16 @@ namespace umbraco.cms.presentation.user CurrentApp = DefaultApps.users.ToString(); } protected HtmlTable macroProperties; - protected TextBox uname = new TextBox(); - protected TextBox lname = new TextBox(); + protected TextBox uname = new TextBox() { ID = "uname" }; + protected RequiredFieldValidator unameValidator = new RequiredFieldValidator(); + protected TextBox lname = new TextBox() { ID = "lname" }; + protected RequiredFieldValidator lnameValidator = new RequiredFieldValidator(); + protected CustomValidator lnameCustomValidator = new CustomValidator(); protected PlaceHolder passw = new PlaceHolder(); protected CheckBoxList lapps = new CheckBoxList(); - protected TextBox email = new TextBox(); + protected TextBox email = new TextBox() { ID = "email" }; + protected RequiredFieldValidator emailValidator = new RequiredFieldValidator(); + protected CustomValidator emailCustomValidator = new CustomValidator(); protected DropDownList userType = new DropDownList(); protected DropDownList userLanguage = new DropDownList(); protected CheckBox NoConsole = new CheckBox(); @@ -148,8 +155,7 @@ namespace umbraco.cms.presentation.user contentPicker.Value = "-1"; content.Controls.Add(contentPicker); - - + // Add password changer var passwordChanger = (passwordChanger)LoadControl(SystemDirectories.Umbraco + "/controls/passwordChanger.ascx"); passwordChanger.MembershipProviderName = UmbracoSettings.DefaultBackofficeProvider; @@ -173,16 +179,7 @@ namespace umbraco.cms.presentation.user passw.Controls.Add(passwordChanger); passw.Controls.Add(validatorContainer); - // Add email validator - var emailValidation = new CustomValidator - { - ID = "EmailValidator", - ErrorMessage = ui.Text("errorHandling", "errorRegExpWithoutTab", "E-mail", CurrentUser), - Display = ValidatorDisplay.None - }; - emailValidation.ServerValidate += EmailValidator_OnServerValidate; - - var validationSummary = new ValidationSummary + var validationSummary = new ValidationSummary { ID = "validationSummary", DisplayMode = ValidationSummaryDisplayMode.BulletList, @@ -191,12 +188,11 @@ namespace umbraco.cms.presentation.user pp.addProperty(validationSummary); - pp.addProperty(ui.Text("user", "username", UmbracoUser), uname); - pp.addProperty(ui.Text("user", "loginname", UmbracoUser), lname); + pp.addProperty(ui.Text("user", "username", UmbracoUser), uname, unameValidator); + pp.addProperty(ui.Text("user", "loginname", UmbracoUser), lname, lnameValidator, lnameCustomValidator); pp.addProperty(ui.Text("user", "password", UmbracoUser), passw); - pp.addProperty(emailValidation); - pp.addProperty(ui.Text("email", UmbracoUser), email); + pp.addProperty(ui.Text("general", "email", UmbracoUser), email, emailValidator, emailCustomValidator); pp.addProperty(ui.Text("user", "usertype", UmbracoUser), userType); pp.addProperty(ui.Text("user", "language", UmbracoUser), userLanguage); @@ -233,12 +229,56 @@ namespace umbraco.cms.presentation.user save.Text = ui.Text("save"); save.ButtonType = MenuButtonType.Primary; - sectionValidator.ServerValidate += new ServerValidateEventHandler(sectionValidator_ServerValidate); + sectionValidator.ServerValidate += SectionValidator_OnServerValidate; sectionValidator.ControlToValidate = lapps.ID; sectionValidator.ErrorMessage = ui.Text("errorHandling", "errorMandatoryWithoutTab", ui.Text("user", "modules", UmbracoUser), UmbracoUser); sectionValidator.CssClass = "error"; sectionValidator.Style.Add("color", "red"); + unameValidator.ControlToValidate = uname.ID; + unameValidator.Display = ValidatorDisplay.Dynamic; + unameValidator.ErrorMessage = ui.Text("defaultdialogs", "requiredField", UmbracoUser); + unameValidator.CssClass = "error"; + unameValidator.Style.Add("color", "red"); + unameValidator.Style.Add("margin-left", "5px"); + unameValidator.Style.Add("line-height", "28px"); + + lnameValidator.ControlToValidate = lname.ID; + lnameValidator.Display = ValidatorDisplay.Dynamic; + lnameValidator.ErrorMessage = ui.Text("defaultdialogs", "requiredField", UmbracoUser); + lnameValidator.CssClass = "error"; + lnameValidator.Style.Add("color", "red"); + lnameValidator.Style.Add("margin-left", "5px"); + lnameValidator.Style.Add("line-height", "28px"); + + lnameCustomValidator.ServerValidate += LnameCustomValidator_OnServerValidate; + lnameCustomValidator.Display = ValidatorDisplay.Dynamic; + lnameCustomValidator.ControlToValidate = lname.ID; + var localizedLname = ui.Text("user", "loginname", UmbracoUser); + lnameCustomValidator.ErrorMessage = ui.Text("errorHandling", "errorExistsWithoutTab", localizedLname, UmbracoUser); + lnameCustomValidator.CssClass = "error"; + lnameCustomValidator.Style.Add("color", "red"); + lnameCustomValidator.Style.Add("margin-left", "5px"); + lnameCustomValidator.Style.Add("line-height", "28px"); + + emailValidator.ControlToValidate = email.ID; + emailValidator.Display = ValidatorDisplay.Dynamic; + emailValidator.ErrorMessage = ui.Text("defaultdialogs", "requiredField", UmbracoUser); + emailValidator.CssClass = "error"; + emailValidator.Style.Add("color", "red"); + emailValidator.Style.Add("margin-left", "5px"); + emailValidator.Style.Add("line-height", "28px"); + + emailCustomValidator.ServerValidate += EmailCustomValidator_OnServerValidate; + emailCustomValidator.Display = ValidatorDisplay.Dynamic; + emailCustomValidator.ControlToValidate = email.ID; + var localizedEmail = ui.Text("general", "email", UmbracoUser); + emailCustomValidator.ErrorMessage = ui.Text("errorHandling", "errorRegExpWithoutTab", localizedEmail, UmbracoUser); + emailCustomValidator.CssClass = "error"; + emailCustomValidator.Style.Add("color", "red"); + emailCustomValidator.Style.Add("margin-left", "5px"); + emailCustomValidator.Style.Add("line-height", "28px"); + SetupForm(); SetupChannel(); @@ -247,12 +287,18 @@ namespace umbraco.cms.presentation.user .SyncTree(UID.ToString(), IsPostBack); } - private void EmailValidator_OnServerValidate(object source, ServerValidateEventArgs args) + private void LnameCustomValidator_OnServerValidate(object source, ServerValidateEventArgs args) { - args.IsValid = MembershipProviderBase.IsEmailValid(email.Text); + var usersWithLoginName = ApplicationContext.Services.UserService.GetByUsername(lname.Text); + args.IsValid = usersWithLoginName == null || usersWithLoginName.Id == u.Id; } - void sectionValidator_ServerValidate(object source, ServerValidateEventArgs args) + private void EmailCustomValidator_OnServerValidate(object source, ServerValidateEventArgs args) + { + args.IsValid = MembershipProviderBase.IsEmailValid(email.Text.Trim()); + } + + private void SectionValidator_OnServerValidate(object source, ServerValidateEventArgs args) { args.IsValid = false; @@ -555,7 +601,9 @@ namespace umbraco.cms.presentation.user } else { - ClientTools.ShowSpeechBubble(speechBubbleIcon.error, ui.Text("speechBubbles", "editUserError", UmbracoUser), ""); + ClientTools.ShowSpeechBubble(speechBubbleIcon.error, + ui.Text("speechBubbles", "validationFailedHeader", UmbracoUser), + ui.Text("speechBubbles", "validationFailedMessage", UmbracoUser)); } } diff --git a/src/umbraco.controls/pane.cs b/src/umbraco.controls/pane.cs index 0facc946a3..499695debf 100644 --- a/src/umbraco.controls/pane.cs +++ b/src/umbraco.controls/pane.cs @@ -36,6 +36,22 @@ namespace umbraco.uicontrols set { m_title = value; } } + public void addProperty(string Caption, Control C, params BaseValidator[] validators) + { + + PropertyPanel pp = new PropertyPanel(); + pp.Controls.Add(C); + + foreach (var validator in validators) + { + validator.Display = ValidatorDisplay.Dynamic; + pp.Controls.Add(validator); + } + pp.Text = Caption; + + this.Controls.Add(pp); + } + public void addProperty(string Caption, Control C) {