diff --git a/src/Orchard.Web/Modules/Orchard.Users/Drivers/UserPartPasswordDriver.cs b/src/Orchard.Web/Modules/Orchard.Users/Drivers/UserPartPasswordDriver.cs new file mode 100644 index 000000000..f752f50c0 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Users/Drivers/UserPartPasswordDriver.cs @@ -0,0 +1,51 @@ +using Orchard.ContentManagement; +using Orchard.ContentManagement.Drivers; +using Orchard.Environment.Extensions; +using Orchard.Localization; +using Orchard.Security; +using Orchard.Users.Models; +using Orchard.Users.ViewModels; + +namespace Orchard.Users.Drivers{ + + [OrchardFeature("Orchard.Users.PasswordEditor")] + public class UserPartPasswordDriver : ContentPartDriver { + private readonly IMembershipService _membershipService; + + public Localizer T { get; set; } + + public UserPartPasswordDriver(IMembershipService membershipService) { + _membershipService = membershipService; + T = NullLocalizer.Instance; + } + + protected override DriverResult Editor(UserPart part, dynamic shapeHelper) { + return ContentShape("Parts_User_EditPassword_Edit", + () => shapeHelper.EditorTemplate( + TemplateName: "Parts/User.EditPassword", + Model: new UserEditPasswordViewModel { User = part }, + Prefix: Prefix)); + } + + protected override DriverResult Editor(UserPart part, IUpdateModel updater, dynamic shapeHelper) { + var editModel = new UserEditPasswordViewModel { User = part }; + if (updater != null) { + if (updater.TryUpdateModel(editModel,Prefix,null,null)) { + if (!(string.IsNullOrEmpty(editModel.Password) && string.IsNullOrEmpty(editModel.ConfirmPassword))) { + if (string.IsNullOrEmpty(editModel.Password) || string.IsNullOrEmpty(editModel.ConfirmPassword)) { + updater.AddModelError("MissingPassword", T("Password or Confirm Password field is empty.")); + } + else { + if (editModel.Password != editModel.ConfirmPassword){ + updater.AddModelError("ConfirmPassword", T("Password confirmation must match.")); + } + var actUser = _membershipService.GetUser(part.UserName); + _membershipService.SetPassword(actUser, editModel.Password); + } + } + } + } + return Editor(part, shapeHelper); + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Users/Module.txt b/src/Orchard.Web/Modules/Orchard.Users/Module.txt index 9a062d315..240f80386 100644 --- a/src/Orchard.Web/Modules/Orchard.Users/Module.txt +++ b/src/Orchard.Web/Modules/Orchard.Users/Module.txt @@ -15,3 +15,8 @@ Features: Description: Provides User based Workflow Activites. Category: Workflows Dependencies: Orchard.Workflows + Orchard.Users.PasswordEditor: + Name: User Password Editor + Description: Adds the ability for admins to edit users' passwords. + Category: Security + Dependencies: Orchard.Users diff --git a/src/Orchard.Web/Modules/Orchard.Users/Orchard.Users.csproj b/src/Orchard.Web/Modules/Orchard.Users/Orchard.Users.csproj index ab5e10f66..bcdd88414 100644 --- a/src/Orchard.Web/Modules/Orchard.Users/Orchard.Users.csproj +++ b/src/Orchard.Web/Modules/Orchard.Users/Orchard.Users.csproj @@ -81,6 +81,7 @@ + @@ -105,6 +106,7 @@ + @@ -156,6 +158,7 @@ + @@ -186,7 +189,9 @@ - + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/src/Orchard.Web/Modules/Orchard.Users/Placement.info b/src/Orchard.Web/Modules/Orchard.Users/Placement.info new file mode 100644 index 000000000..ef8077a94 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Users/Placement.info @@ -0,0 +1,5 @@ + + + + + diff --git a/src/Orchard.Web/Modules/Orchard.Users/ViewModels/UserEditPasswordViewModel.cs b/src/Orchard.Web/Modules/Orchard.Users/ViewModels/UserEditPasswordViewModel.cs new file mode 100644 index 000000000..fa6c25314 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Users/ViewModels/UserEditPasswordViewModel.cs @@ -0,0 +1,17 @@ +using Orchard.ContentManagement; +using Orchard.Environment.Extensions; +using System.ComponentModel.DataAnnotations; + +namespace Orchard.Users.ViewModels +{ + [OrchardFeature("Orchard.Users.EditPasswordByAdmin")] + public class UserEditPasswordViewModel { + [DataType(DataType.Password)] + [StringLength(50, MinimumLength = 7)] + public string Password { get; set; } + + [DataType(DataType.Password)] + public string ConfirmPassword { get; set; } + public IContent User { get; set; } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Users/Views/EditorTemplates/Parts/User.EditPassword.cshtml b/src/Orchard.Web/Modules/Orchard.Users/Views/EditorTemplates/Parts/User.EditPassword.cshtml new file mode 100644 index 000000000..d1ce22933 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Users/Views/EditorTemplates/Parts/User.EditPassword.cshtml @@ -0,0 +1,11 @@ +@model Orchard.Users.ViewModels.UserEditPasswordViewModel +
+ @Html.LabelFor(m => m.Password, T("Password")) + @Html.PasswordFor(m => m.Password, new { @class = "text medium" }) + @Html.ValidationMessageFor(m => m.Password, "*") +
+
+ @Html.LabelFor(m => m.ConfirmPassword, T("Confirm Password")) + @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "text medium" }) + @Html.ValidationMessageFor(m => m.ConfirmPassword, "*") +
\ No newline at end of file