mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#21181: Adding the ability for admins to also change password for registered users.
Work Item: 21181
This commit is contained in:
@@ -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<UserPart> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
@@ -81,6 +81,7 @@
|
||||
<Compile Include="Controllers\AccountController.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Drivers\UserPartDriver.cs" />
|
||||
<Compile Include="Drivers\UserPartPasswordDriver.cs" />
|
||||
<Compile Include="Forms\SignInUserForm.cs" />
|
||||
<Compile Include="Forms\VerifyUserUnicityForm.cs" />
|
||||
<Compile Include="Forms\CreateUserForm.cs" />
|
||||
@@ -105,6 +106,7 @@
|
||||
<Compile Include="Services\MissingSettingsBanner.cs" />
|
||||
<Compile Include="Services\UserService.cs" />
|
||||
<Compile Include="ViewModels\UserCreateViewModel.cs" />
|
||||
<Compile Include="ViewModels\UserEditPasswordViewModel.cs" />
|
||||
<Compile Include="ViewModels\UserEditViewModel.cs" />
|
||||
<Compile Include="ViewModels\UsersIndexViewModel.cs" />
|
||||
</ItemGroup>
|
||||
@@ -156,6 +158,7 @@
|
||||
<Content Include="Views\Account\RegistrationPending.cshtml" />
|
||||
<Content Include="Views\EditorTemplates\Parts\User.Edit.cshtml" />
|
||||
<Content Include="Views\EditorTemplates\Parts\User.Create.cshtml" />
|
||||
<Content Include="Views\EditorTemplates\Parts\User.EditPassword.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Account\RequestLostPassword.cshtml" />
|
||||
@@ -186,7 +189,9 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Template.User.Wrapper.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Content Include="Placement.info" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
5
src/Orchard.Web/Modules/Orchard.Users/Placement.info
Normal file
5
src/Orchard.Web/Modules/Orchard.Users/Placement.info
Normal file
@@ -0,0 +1,5 @@
|
||||
<Placement>
|
||||
<Match Path="~/Admin/Users/Edit/*">
|
||||
<Place Parts_User_EditPassword_Edit="Content:1"/>
|
||||
</Match>
|
||||
</Placement>
|
@@ -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; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
@model Orchard.Users.ViewModels.UserEditPasswordViewModel
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.Password, T("Password"))
|
||||
@Html.PasswordFor(m => m.Password, new { @class = "text medium" })
|
||||
@Html.ValidationMessageFor(m => m.Password, "*")
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
@Html.LabelFor(m => m.ConfirmPassword, T("Confirm Password"))
|
||||
@Html.PasswordFor(m => m.ConfirmPassword, new { @class = "text medium" })
|
||||
@Html.ValidationMessageFor(m => m.ConfirmPassword, "*")
|
||||
</fieldset>
|
Reference in New Issue
Block a user