mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#20686 Workflow useractivity and user is approved activity.
Adds workflow activities for IUserEventHandler events Work Item: 20686
This commit is contained in:

committed by
Nicholas Mayne

parent
594ba12303
commit
b3eef7755f
130
src/Orchard.Web/Modules/Orchard.Users/Activities/UserActivity.cs
Normal file
130
src/Orchard.Web/Modules/Orchard.Users/Activities/UserActivity.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Workflows.Models;
|
||||
using Orchard.Workflows.Services;
|
||||
|
||||
namespace Orchard.Users.Activities {
|
||||
public abstract class UserActivity : Event {
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public override bool CanStartWorkflow {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool CanExecute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
return new[] {T("Done")};
|
||||
}
|
||||
|
||||
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
yield return T("Done");
|
||||
}
|
||||
|
||||
public override LocalizedString Category {
|
||||
get { return T("Events"); }
|
||||
}
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Users.Workflows")]
|
||||
public class UserCreatingActivity : UserActivity {
|
||||
public override string Name {
|
||||
get { return "UserCreating"; }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("User is creating."); }
|
||||
}
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Users.Workflows")]
|
||||
public class UserCreatedActivity : UserActivity {
|
||||
public override string Name {
|
||||
get { return "UserCreated"; }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("User is created."); }
|
||||
}
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Users.Workflows")]
|
||||
public class UserLoggedInActivity : UserActivity {
|
||||
public override string Name {
|
||||
get { return "UserLoggedIn"; }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("User is logged in."); }
|
||||
}
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Users.Workflows")]
|
||||
public class UserLoggedOutActivity : UserActivity {
|
||||
public override string Name {
|
||||
get { return "UserLoggedOut"; }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("User is logged out."); }
|
||||
}
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Users.Workflows")]
|
||||
public class UserAccessDeniedActivity : UserActivity {
|
||||
public override string Name {
|
||||
get { return "UserAccessDenied"; }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("User access is denied."); }
|
||||
}
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Users.Workflows")]
|
||||
public class UserChangedPasswordActivity : UserActivity {
|
||||
public override string Name {
|
||||
get { return "UserChangedPassword"; }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("User changed password."); }
|
||||
}
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Users.Workflows")]
|
||||
public class UserSentChallengeEmailActivity : UserActivity {
|
||||
public override string Name {
|
||||
get { return "UserSentChallengeEmail"; }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("User send challenge email."); }
|
||||
}
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Users.Workflows")]
|
||||
public class UserConfirmedEmailActivity : UserActivity {
|
||||
public override string Name {
|
||||
get { return "UserConfirmedEmail"; }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("User confirmed email."); }
|
||||
}
|
||||
}
|
||||
|
||||
[OrchardFeature("Orchard.Users.Workflows")]
|
||||
public class UserApprovedActivity : UserActivity {
|
||||
public override string Name {
|
||||
get { return "UserApproved"; }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("User is approved."); }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Users.Models;
|
||||
using Orchard.Workflows.Models;
|
||||
|
||||
namespace Orchard.Users.Activities {
|
||||
[OrchardFeature("Orchard.Users.Workflows")]
|
||||
public class UserIsApprovedActivity : Workflows.Services.Task {
|
||||
private readonly IWorkContextAccessor _workContextAccessor;
|
||||
|
||||
public UserIsApprovedActivity(IWorkContextAccessor workContextAccessor) {
|
||||
_workContextAccessor = workContextAccessor;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public override string Name {
|
||||
get { return "UserIsApproved"; }
|
||||
}
|
||||
|
||||
public override LocalizedString Category {
|
||||
get { return T("Conditions"); }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("Whether the current user is approved or not."); }
|
||||
}
|
||||
|
||||
public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
return new[] {T("Yes"), T("No")};
|
||||
}
|
||||
|
||||
public override bool CanExecute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
if (UserIsApproved(activityContext)) {
|
||||
yield return T("Yes");
|
||||
}
|
||||
|
||||
yield return T("No");
|
||||
}
|
||||
|
||||
private bool UserIsApproved(ActivityContext context) {
|
||||
// checking if user is in an accepted role
|
||||
var workContext = _workContextAccessor.GetContext();
|
||||
var user = workContext.CurrentUser;
|
||||
if (user == null) return false;
|
||||
return user.As<UserPart>().RegistrationStatus == UserStatus.Approved;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Users.Events;
|
||||
using Orchard.Workflows.Services;
|
||||
|
||||
namespace Orchard.Users.Handlers {
|
||||
[OrchardFeature("Orchard.Users.Workflows")]
|
||||
public class WorkflowUserEventHandler : IUserEventHandler {
|
||||
private IWorkflowManager workflowManager;
|
||||
|
||||
public WorkflowUserEventHandler(IWorkflowManager workflowManager) {
|
||||
this.workflowManager = workflowManager;
|
||||
}
|
||||
|
||||
public void Creating(UserContext context) {
|
||||
workflowManager.TriggerEvent("UserCreating",
|
||||
context.User,
|
||||
() => new Dictionary<string, object> {{"User", context}});
|
||||
}
|
||||
|
||||
public void Created(UserContext context) {
|
||||
workflowManager.TriggerEvent("UserCreated",
|
||||
context.User,
|
||||
() => new Dictionary<string, object> {{"User", context}});
|
||||
}
|
||||
|
||||
public void LoggedIn(Security.IUser user) {
|
||||
workflowManager.TriggerEvent("UserLoggedIn",
|
||||
user,
|
||||
() => new Dictionary<string, object> {{"User", user}});
|
||||
}
|
||||
|
||||
public void LoggedOut(Security.IUser user) {
|
||||
workflowManager.TriggerEvent("UserLoggedOut",
|
||||
user,
|
||||
() => new Dictionary<string, object> {{"User", user}});
|
||||
}
|
||||
|
||||
public void AccessDenied(Security.IUser user) {
|
||||
workflowManager.TriggerEvent("UserAccessDenied",
|
||||
user,
|
||||
() => new Dictionary<string, object> {{"User", user}});
|
||||
}
|
||||
|
||||
public void ChangedPassword(Security.IUser user) {
|
||||
workflowManager.TriggerEvent("UserChangedPassword",
|
||||
user,
|
||||
() => new Dictionary<string, object> {{"User", user}});
|
||||
}
|
||||
|
||||
public void SentChallengeEmail(Security.IUser user) {
|
||||
workflowManager.TriggerEvent("UserSentChallengeEmail",
|
||||
user,
|
||||
() => new Dictionary<string, object> {{"User", user}});
|
||||
}
|
||||
|
||||
public void ConfirmedEmail(Security.IUser user) {
|
||||
workflowManager.TriggerEvent("UserConfirmedEmail",
|
||||
user,
|
||||
() => new Dictionary<string, object> {{"User", user}});
|
||||
}
|
||||
|
||||
public void Approved(Security.IUser user) {
|
||||
workflowManager.TriggerEvent("UserApproved",
|
||||
user,
|
||||
() => new Dictionary<string, object> {{"User", user}});
|
||||
}
|
||||
}
|
||||
}
|
@@ -10,3 +10,8 @@ Features:
|
||||
Description: Standard users.
|
||||
Category: Core
|
||||
Dependencies: Settings
|
||||
Orchard.Users.Workflows:
|
||||
Name: Users Workflows Activities
|
||||
Description: Provides User based Workflow Activites.
|
||||
Category: Workflows
|
||||
Dependencies: Orchard.Workflows
|
||||
|
@@ -71,10 +71,13 @@
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Activities\UserActivity.cs" />
|
||||
<Compile Include="Activities\UserIsApprovedActivity.cs" />
|
||||
<Compile Include="Commands\UserCommands.cs" />
|
||||
<Compile Include="Controllers\AccountController.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="Drivers\UserPartDriver.cs" />
|
||||
<Compile Include="Handlers\WorkflowUserEventHandler.cs" />
|
||||
<Compile Include="Migrations.cs" />
|
||||
<Compile Include="Events\UserContext.cs" />
|
||||
<Compile Include="Handlers\RegistrationSettingsPartHandler.cs" />
|
||||
@@ -125,6 +128,10 @@
|
||||
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
||||
<Name>Orchard.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Orchard.Workflows\Orchard.Workflows.csproj">
|
||||
<Project>{7059493C-8251-4764-9C1E-2368B8B485BC}</Project>
|
||||
<Name>Orchard.Workflows</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Items\Content-User.Edit.cshtml" />
|
||||
@@ -168,6 +175,7 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Template.User.Wrapper.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
Reference in New Issue
Block a user