diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml index 433eb6050e..2daddd527c 100644 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml @@ -21,6 +21,23 @@ @if (Members.IsLoggedIn()) { + Html.EnableClientValidation(); + Html.EnableUnobtrusiveJavaScript(); + Html.RequiresJs("/umbraco_client/ui/jquery.js"); + Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js"); + Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js"); + + var success = TempData["ProfileUpdateSuccess"] != null; + + @*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@ + @Html.RenderJsHere() + + if (success) + { + // This message will show if RedirectOnSucces is set to false (default) +

Profile updated

+ } + using (Html.BeginUmbracoForm("HandleUpdateProfile")) {
@@ -45,10 +62,8 @@ @Html.HiddenFor(m => profileModel.MemberProperties[i].Alias)
} - - @Html.HiddenFor(m => profileModel.MemberTypeAlias)
- } + } } \ No newline at end of file diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/RegisterMember.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/RegisterMember.cshtml index de71c1f77d..f14525bb5c 100644 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/RegisterMember.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/RegisterMember.cshtml @@ -48,7 +48,7 @@ @if (success) { // This message will show if RedirectOnSucces is set to false (default) -

Registration succeeeded.

+

Registration succeeeded.

} else { diff --git a/src/Umbraco.Web/Controllers/UmbProfileController.cs b/src/Umbraco.Web/Controllers/UmbProfileController.cs index f84a5cfbac..1f6e10e249 100644 --- a/src/Umbraco.Web/Controllers/UmbProfileController.cs +++ b/src/Umbraco.Web/Controllers/UmbProfileController.cs @@ -25,7 +25,14 @@ namespace Umbraco.Web.Controllers return CurrentUmbracoPage(); } - Members.UpdateMemberProfile(model); + var updateAttempt = Members.UpdateMemberProfile(model); + if (updateAttempt.Success == false) + { + ModelState.AddModelError("profileModel.Email", updateAttempt.Exception); + return CurrentUmbracoPage(); + } + + TempData.Add("ProfileUpdateSuccess", true); //TODO: Why are we redirecting to home again here?? return Redirect("/"); diff --git a/src/Umbraco.Web/Models/ProfileModel.cs b/src/Umbraco.Web/Models/ProfileModel.cs index 9d8bfd9291..84742c922a 100644 --- a/src/Umbraco.Web/Models/ProfileModel.cs +++ b/src/Umbraco.Web/Models/ProfileModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; @@ -39,10 +40,24 @@ namespace Umbraco.Web.Models ErrorMessage = "Please enter a valid e-mail address")] public string Email { get; set; } + /// + /// The member's real name + /// public string Name { get; set; } + /// + /// The member's member type alias + /// + [ReadOnly(true)] + [Obsolete("This is not used and will be removed from the codebase in future versions")] public string MemberTypeAlias { get; set; } + /// + /// The list of member properties + /// + /// + /// Adding items to this list on the front-end will not add properties to the member in the database. + /// public List MemberProperties { get; set; } } } diff --git a/src/Umbraco.Web/Models/RegisterModel.cs b/src/Umbraco.Web/Models/RegisterModel.cs index 818c66dfd4..21a3c56a4b 100644 --- a/src/Umbraco.Web/Models/RegisterModel.cs +++ b/src/Umbraco.Web/Models/RegisterModel.cs @@ -65,8 +65,14 @@ namespace Umbraco.Web.Models public string RedirectUrl { get; set; } + /// + /// The username of the model, if UsernameIsEmail is true then this is ignored. + /// public string Username { get; set; } + /// + /// Flag to determine if the username should be the email address, if true then the Username property is ignored + /// public bool UsernameIsEmail { get; set; } /// diff --git a/src/Umbraco.Web/Security/MembershipHelper.cs b/src/Umbraco.Web/Security/MembershipHelper.cs index e2477dcd03..107f1fd563 100644 --- a/src/Umbraco.Web/Security/MembershipHelper.cs +++ b/src/Umbraco.Web/Security/MembershipHelper.cs @@ -52,21 +52,41 @@ namespace Umbraco.Web.Security /// Updates the currently logged in members profile /// /// - public void UpdateMemberProfile(ProfileModel model) + /// + /// The updated MembershipUser object + /// + public Attempt UpdateMemberProfile(ProfileModel model) { if (IsLoggedIn() == false) { throw new NotSupportedException("No member is currently logged in"); } - var member = GetCurrentMember(); + //get the current membership user + var membershipUser = Membership.GetUser(); + //NOTE: This should never happen since they are logged in + if (membershipUser == null) throw new InvalidOperationException("Could not find member with username " + _httpContext.User.Identity.Name); + + try + { + //Use the membership provider to change the email since that is configured to do the checks to check for unique emails if that is configured. + membershipUser = UpdateMember(membershipUser, Membership.Provider, model.Email); + } + catch (Exception ex) + { + //This will occur if an email already exists! + return Attempt.Fail(ex); + } + var member = GetCurrentMember(); + + //NOTE: If changing the username is a requirement, than that needs to be done via the IMember directly since MembershipProvider's natively do + // not support changing a username! if (model.Name != null) { member.Name = model.Name; } member.Email = model.Email; - member.Username = model.Email; if (model.MemberProperties != null) { @@ -87,6 +107,8 @@ namespace Umbraco.Web.Security //reset the FormsAuth cookie since the username might have changed FormsAuthentication.SetAuthCookie(member.Username, true); + + return Attempt.Succeed(membershipUser); } ///