mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-27 04:19:04 +08:00
Add button manage approve disable in edit user (#8321)
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Drivers;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard.Mvc;
|
||||||
|
using Orchard.Users.Models;
|
||||||
|
using Orchard.Users.ViewModels;
|
||||||
|
|
||||||
|
namespace Orchard.Users.Drivers {
|
||||||
|
public class UserApprovePartDriver : ContentPartDriver<UserPart> {
|
||||||
|
private const string TemplateName = "Parts/User.Approve";
|
||||||
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
|
private readonly IOrchardServices _orchardServices;
|
||||||
|
|
||||||
|
public UserApprovePartDriver(
|
||||||
|
IHttpContextAccessor httpContextAccessor,
|
||||||
|
IOrchardServices orchardServices
|
||||||
|
) {
|
||||||
|
|
||||||
|
_httpContextAccessor = httpContextAccessor;
|
||||||
|
_orchardServices = orchardServices;
|
||||||
|
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
protected override DriverResult Editor(UserPart part, dynamic shapeHelper) {
|
||||||
|
var model = new UserEditViewModel { User = part };
|
||||||
|
|
||||||
|
return ContentShape("Parts_UserApprove_Edit",
|
||||||
|
() => {
|
||||||
|
if (!_orchardServices.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users"))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override DriverResult Editor(UserPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
|
var model = new UserEditViewModel { User = part };
|
||||||
|
|
||||||
|
return ContentShape("Parts_UserApprove_Edit",
|
||||||
|
() => {
|
||||||
|
if (!_orchardServices.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users"))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
using Orchard.ContentManagement.Handlers;
|
||||||
|
using Orchard.Mvc;
|
||||||
|
using Orchard.Users.Events;
|
||||||
|
using Orchard.Users.Models;
|
||||||
|
using Orchard.Users.Services;
|
||||||
|
|
||||||
|
namespace Orchard.Users.Handlers {
|
||||||
|
public class ApproveUserHandler : ContentHandler {
|
||||||
|
private readonly IApproveUserService _approveUserService;
|
||||||
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
|
|
||||||
|
public ApproveUserHandler(
|
||||||
|
IApproveUserService approveUserService,
|
||||||
|
IHttpContextAccessor httpContextAccessor) {
|
||||||
|
_approveUserService = approveUserService;
|
||||||
|
_httpContextAccessor = httpContextAccessor;
|
||||||
|
|
||||||
|
OnPublished<UserPart>((context, part) => {
|
||||||
|
var httpContext = _httpContextAccessor.Current();
|
||||||
|
// verify user click correct button and
|
||||||
|
// registration status is correct to approve/disable
|
||||||
|
if (httpContext.Request.Form["submit.Save"] == "submit.ApproveUser" &&
|
||||||
|
part.RegistrationStatus == UserStatus.Pending) {
|
||||||
|
_approveUserService.Approve(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (httpContext.Request.Form["submit.Save"] == "submit.DisableUser" &&
|
||||||
|
part.RegistrationStatus == UserStatus.Approved) {
|
||||||
|
_approveUserService.Disable(part);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -111,6 +111,7 @@
|
|||||||
<Compile Include="Constants\UserPasswordValidationResults.cs" />
|
<Compile Include="Constants\UserPasswordValidationResults.cs" />
|
||||||
<Compile Include="Controllers\AccountController.cs" />
|
<Compile Include="Controllers\AccountController.cs" />
|
||||||
<Compile Include="Controllers\AdminController.cs" />
|
<Compile Include="Controllers\AdminController.cs" />
|
||||||
|
<Compile Include="Drivers\UserApprovePartDriver.cs" />
|
||||||
<Compile Include="Drivers\UserPartDriver.cs" />
|
<Compile Include="Drivers\UserPartDriver.cs" />
|
||||||
<Compile Include="Drivers\UserPartPasswordDriver.cs" />
|
<Compile Include="Drivers\UserPartPasswordDriver.cs" />
|
||||||
<Compile Include="Events\LoginUserEventHandler.cs" />
|
<Compile Include="Events\LoginUserEventHandler.cs" />
|
||||||
@@ -119,6 +120,7 @@
|
|||||||
<Compile Include="Forms\SignInUserForm.cs" />
|
<Compile Include="Forms\SignInUserForm.cs" />
|
||||||
<Compile Include="Forms\VerifyUserUnicityForm.cs" />
|
<Compile Include="Forms\VerifyUserUnicityForm.cs" />
|
||||||
<Compile Include="Forms\CreateUserForm.cs" />
|
<Compile Include="Forms\CreateUserForm.cs" />
|
||||||
|
<Compile Include="Handlers\ApproveUserHandler.cs" />
|
||||||
<Compile Include="Handlers\SecuritySettingsPartHandler.cs" />
|
<Compile Include="Handlers\SecuritySettingsPartHandler.cs" />
|
||||||
<Compile Include="Handlers\WorkflowUserEventHandler.cs" />
|
<Compile Include="Handlers\WorkflowUserEventHandler.cs" />
|
||||||
<Compile Include="Extensions\ModelStateDictionaryExtensions.cs" />
|
<Compile Include="Extensions\ModelStateDictionaryExtensions.cs" />
|
||||||
@@ -135,6 +137,7 @@
|
|||||||
<Compile Include="Models\UserStatus.cs" />
|
<Compile Include="Models\UserStatus.cs" />
|
||||||
<Compile Include="Permissions.cs" />
|
<Compile Include="Permissions.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Services\ApproveUserService.cs" />
|
||||||
<Compile Include="Services\AuthenticationRedirectionFilter.cs" />
|
<Compile Include="Services\AuthenticationRedirectionFilter.cs" />
|
||||||
<Compile Include="Services\IUserService.cs" />
|
<Compile Include="Services\IUserService.cs" />
|
||||||
<Compile Include="Services\MembershipValidationService.cs" />
|
<Compile Include="Services\MembershipValidationService.cs" />
|
||||||
@@ -244,6 +247,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\EditorTemplates\Parts\Users.SecuritySettings.cshtml" />
|
<Content Include="Views\EditorTemplates\Parts\Users.SecuritySettings.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Views\EditorTemplates\Parts\User.Approve.cshtml" />
|
||||||
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<Placement>
|
<Placement>
|
||||||
<Match Path="~/Admin/Users/Edit/*">
|
<Match Path="~/Admin/Users/Edit/*">
|
||||||
<Place Parts_User_EditPassword_Edit="Content:1"/>
|
<Place Parts_User_EditPassword_Edit="Content:1"/>
|
||||||
|
<Place Parts_UserApprove_Edit="Sidebar:25"/> <!-- immediately following the contents module's Approve Now button -->
|
||||||
</Match>
|
</Match>
|
||||||
</Placement>
|
</Placement>
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using Orchard;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.Localization;
|
||||||
|
using Orchard.Users;
|
||||||
|
using Orchard.Security;
|
||||||
|
using Orchard.Users.Models;
|
||||||
|
using Orchard.UI.Notify;
|
||||||
|
using Orchard.Users.Events;
|
||||||
|
|
||||||
|
namespace Orchard.Users.Services {
|
||||||
|
public interface IApproveUserService : IDependency {
|
||||||
|
void Approve(UserPart contentItem);
|
||||||
|
void Disable(UserPart contentItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ApproveUserService : IApproveUserService {
|
||||||
|
|
||||||
|
private readonly IUserEventHandler _userEventHandlers;
|
||||||
|
private readonly IOrchardServices _orchardServices;
|
||||||
|
|
||||||
|
public ApproveUserService(
|
||||||
|
IUserEventHandler userEventHandlers,
|
||||||
|
IOrchardServices orchardServices) {
|
||||||
|
|
||||||
|
_userEventHandlers = userEventHandlers;
|
||||||
|
_orchardServices = orchardServices;
|
||||||
|
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public void Approve(UserPart part) {
|
||||||
|
if (!_orchardServices.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (part == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
part.RegistrationStatus = UserStatus.Approved;
|
||||||
|
_orchardServices.Notifier.Information(T("User {0} approved", part.UserName));
|
||||||
|
_userEventHandlers.Approved(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Disable(UserPart part) {
|
||||||
|
if (!_orchardServices.Authorizer.Authorize(Permissions.ManageUsers, T("Not authorized to manage users")))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (part == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
part.RegistrationStatus = UserStatus.Pending;
|
||||||
|
_orchardServices.Notifier.Information(T("User {0} disabled", part.UserName));
|
||||||
|
_userEventHandlers.Moderate(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
@model Orchard.Users.ViewModels.UserEditViewModel
|
||||||
|
|
||||||
|
@using Orchard.Users.Models;
|
||||||
|
@using Orchard.ContentManagement;
|
||||||
|
@using Orchard.Core.Contents;
|
||||||
|
@using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
.approve-user {
|
||||||
|
float: left;
|
||||||
|
clear: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.approve-user legend {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.approve-user button {
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<fieldset class="approve-user">
|
||||||
|
<legend>@T("Approve User")</legend>
|
||||||
|
@if (Model.User != null) {
|
||||||
|
var user = Model.User.As<UserPart>();
|
||||||
|
if (user.RegistrationStatus == UserStatus.Pending) {
|
||||||
|
<button type="submit" name="submit.Save" value="submit.ApproveUser">@T("Approve")</button>
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
<button type="submit" name="submit.Save" value="submit.DisableUser">@T("Disable")</button>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</fieldset>
|
||||||
Reference in New Issue
Block a user