Orchardcore crestapps users

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore crestapps users is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for the CrestApps Users module in Orchard Core. Covers user caching, the UserPicker view component and IUserSearchService with audiences, User Display Name with UserFullNamePart and the display_name filter, User Avatar with IUserAvatarProvider, Sign in with an email code, User Audiences with r

How to use this skill

Skill file

CrestApps Users

Configure enhanced user experiences

You are an Orchard Core expert. CrestApps Users extends Orchard Core Users with cached user lookups, a reusable user picker, configurable display names, media-backed avatars, passwordless sign-in with an emailed code, rule-based user audiences, hand-kept cohorts, a front-end "my account" area, front-end notification pages and password re-confirmation for private pages. The core feature is enabled by dependency only; enable the specific capability you need.

Guidelines

Feature overview

| Feature ID | Dependencies | Purpose |

|---|---|---|

| CrestApps.OrchardCore.Users | - | Dependency only. User cache, basic display-name fallback, UserPicker and the user search endpoint, user menu display name |

| CrestApps.OrchardCore.Users.DisplayName | OrchardCore.ContentFields | UserFullNamePart, DisplayNameSettings, display-name search, picker labels, display_name filter |

| CrestApps.OrchardCore.Users.Avatars | OrchardCore.Media | UserAvatarPart, UserAvatarOptions, avatar styles |

| CrestApps.OrchardCore.Users.EmailCodeSignIn | OrchardCore.Users, OrchardCore.Email | Email me a sign-in code on the login form |

| CrestApps.OrchardCore.Users.Audiences | OrchardCore.Users, OrchardCore.Roles | Rule-based audiences, Content > User Audiences, UserAudiences step, In a user audience rule condition |

| CrestApps.OrchardCore.Users.Cohorts | OrchardCore.Users, CrestApps.OrchardCore.Users.Audiences | Hand-kept cohorts, Content > Cohorts, CohortMember audience rule, UserCohorts step |

| CrestApps.OrchardCore.Users.Account | OrchardCore.Users | Dependency only. The /account area, its commerce-account menu and page frame |

With Orchard Core OrchardCore.Notifications enabled, the core feature also adds the front-end /notifications and /notifications/preferences pages. See account and notifications.

{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "CrestApps.OrchardCore.Users.DisplayName",
        "CrestApps.OrchardCore.Users.Avatars",
        "OrchardCore.Liquid"
      ],
      "disable": []
    }
  ]
}

Permissions

UserPermissions (a static class in namespace CrestApps.OrchardCore.Users.Core) declares its descriptions with LocalizationSource.Create("...", typeof(UserPermissions)). Feature IDs are in UsersConstants.Feature (CrestApps.OrchardCore.Users.Abstractions). All are granted to Administrator by default. The two settings permissions are registered with AddSiteSettingsPermission for their settings group, so a role holding only that permission can open the page.

| Permission | Opens |

|---|---|

| ManageDisplaySettings | Settings > User Display Name |

| ManageAvatarSettings | Settings > User Avatars |

| ManageUserAudiences | Content > User Audiences |

| ManageCohorts | Content > Cohorts |

Reusable user picker

The core feature ships a UserPicker view component that renders through the shared ItemSelector component (see orchardcore-crestapps-resources). It searches as the user types and resolves the saved values to display names on first render.

@await Component.InvokeAsync("UserPicker", new
{
    name = Html.NameFor(m => m.OwnerUserId).ToString(),
    selectedValues = new[] { Model.OwnerUserId },
    valueType = "userId",
    multiple = false,
    buttonText = T["Select a user"].Value,
    searchPlaceholder = T["Search users"].Value,
})

| Parameter | Purpose |

|---|---|

| name | Required. Posted field name; use Html.NameFor(...) inside a display driver so it binds under the driver's prefix |

| selectedValues | Saved values, matching valueType |

| valueType | userId (default), userName or normalizedUserName |

| multiple | Allow several users |

| roles | Restrict results to these role names |

| audience | Restrict results to a code audience (IUserAudienceProvider.Name), such as Staff or StaffUnlinked from orchardcore-staff; ignored when no provider has that name |

| required | Mark the selector required |

| label, buttonText, searchPlaceholder, smallButton | Display options |

The picker calls GET Admin/api/crestapps/users/search (route name CrestApps.Users.Search) with query, valueType, role and audience. It requires the SearchUsers permission (Search users in user pickers, UserSearchPermissions.SearchUsers, implied by the admin panel permission, so admin roles keep their pickers while a signed-in storefront customer cannot list users) and returns 403 otherwise. It delegates to IUserSearchService and returns up to 50 enabled users as { value, text, isEnabled } with text from the display name.

Shared user building blocks

The Users abstractions (CrestApps.OrchardCore.Users.Abstractions) hold contracts other modules reuse instead of querying users themselves:

public sealed class PlanRoleSync
{
    private readonly IRoleGrantService _roleGrants;

    public PlanRoleSync(IRoleGrantService roleGrants)
    {
        _roleGrants = roleGrants;
    }

    public Task ActivateAsync(string userId, string planId)
        => _roleGrants.GrantAsync(userId, "Premium", "Plan", planId);

    public Task DeactivateAsync(string userId, string planId)
        => _roleGrants.RevokeAsync(userId, "Premium", "Plan", planId);
}

Define a code audience

using CrestApps.OrchardCore.Users;

namespace MyModule.Services;

public sealed class VolunteersAudienceProvider : IUserAudienceProvider
{
    public string Name => "Volunteers";

    public Task<IReadOnlyCollection<string>> GetRoleNamesAsync(CancellationToken cancellationToken = default)
        => Task.FromResult<IReadOnlyCollection<string>>(["Volunteer", "VolunteerLead"]);
}

Register it with services.TryAddEnumerable(ServiceDescriptor.Scoped<IUserAudienceProvider, VolunteersAudienceProvider>());, then pass audience = "Volunteers" to the UserPicker. It is also listed on Content > User Audiences when that feature is on.

User audiences and cohorts

CrestApps.OrchardCore.Users.Audiences lets administrators define audiences: a technical name, a join (All or Any) and rules from rule sources such as Role (Users), Team (Teams), StaffHireDate and StaffEmploymentType (Staff, see orchardcore-staff), SkillHolder, CertificationHolder, CourseLearner and CohortMember. Membership is resolved when read, through IUserAudienceService (ListAsync, GetMembersAsync, IsMemberAsync, SaveDefinitionAsync). Modules add a rule kind with IUserAudienceRuleSource and services.AddUserAudienceRuleSource<T>(), and block deleting an audience they use with IUserAudienceUsage. With OrchardCore.Rules, the In a user audience condition tests the signed-in user.

CrestApps.OrchardCore.Users.Cohorts keeps hand-maintained groups of users (ICohortService, ICohortMembershipObserver, ICohortUsage) in the Cohorts YesSql collection and adds the CohortMember audience rule.

{
  "steps": [
    {
      "name": "UserAudiences",
      "Audiences": [
        {
          "name": "admins-and-editors",
          "displayName": "Admins and editors",
          "join": "Any",
          "rules": [
            { "source": "Role", "values": ["Administrator", "Editor"] }
          ]
        }
      ]
    },
    {
      "name": "UserCohorts",
      "Cohorts": [
        { "Name": "2026 new hires", "Members": ["ana", "ben@example.com"] }
      ]
    }
  ]
}

See audiences and cohorts for rule sources, service members, a custom rule source and the index declarations.

Confirm the password before private pages

IPasswordConfirmation (Users.Abstractions, registered by the core feature with services.AddPasswordConfirmation()) asks the signed-in person for their password again before a page shows private data such as pay. Put [ConfirmPassword] (namespace CrestApps.OrchardCore.Users, assembly Users.Core) on a controller or action: until confirmed, a GET redirects to Confirm your password at ~/Admin/confirm-password and back; a form posted after the confirmation expired returns to the page it came from. A confirmation is an HttpOnly, SameSite=Strict cookie protected for that user, valid for Window (10 minutes); a wrong password counts toward lockout. Without the Users feature the attribute forbids the request.

using CrestApps.OrchardCore.Users;
using Microsoft.AspNetCore.Mvc;
using OrchardCore.Admin;

namespace MyModule.Controllers;

[Admin]
[ConfirmPassword]
public sealed class MyPayController : Controller
{
    public IActionResult Index() => View();
}

A display driver checks IsConfirmedAsync(user) and links to GetConfirmationUrl(returnUrl). A page that must ask every time it opens checks IsJustConfirmedAsync(user), true only on the first page opened right after confirming (a one-minute cookie the check deletes).

User display names

DisplayNameSettings (namespace CrestApps.OrchardCore.Users.Core.Models) is edited at Settings > User Display Name.

| Type (DisplayNameType) | Result |

|---|---|

| Username (default) | The user name |

| DisplayName | UserFullNamePart.DisplayName, or the user name when empty |

| FirstThenLast | First, middle (when used) and last name, or the user name when all are empty |

| LastThenFirst | Last, First Middle, or the user name when all are empty |

| Other | The Liquid Template, with User, FirstName, MiddleName, LastName, DisplayName and UserName in scope; it must validate before it saves |

DisplayName, FirstName, MiddleName and LastName on the settings are each None, Optional or Required (DisplayNamePropertyType), controlling whether the user editor shows and validates the box. The name boxes show only to users who hold EditUsers for that user. Saving the settings removes the user-display-name cache tag (UsersConstants.UserDisplayNameCacheTag).

{
  "steps": [
    {
      "name": "Settings",
      "DisplayNameSettings": {
        "Type": "FirstThenLast",
        "DisplayName": "None",
        "FirstName": "Required",
        "MiddleName": "Optional",
        "LastName": "Required"
      }
    }
  ]
}

Resolve a display name

using CrestApps.OrchardCore.Users;
using OrchardCore.Users;

namespace MyModule.Services;

public sealed class UserLabelService
{
    private readonly IDisplayNameProvider _displayNameProvider;

    public UserLabelService(IDisplayNameProvider displayNameProvider)
    {
        _displayNameProvider = displayNameProvider;
    }

    public Task<string> GetLabelAsync(IUser user, CancellationToken cancellationToken)
        => _displayNameProvider.GetAsync(user, cancellationToken);
}

With OrchardCore.Liquid enabled:

{{ Model.User | display_name }}

Without the Display Name feature, the core feature's basic provider returns the user name.

Data, search and pickers

User avatars

Configure Settings > User Avatars. UserAvatarOptions has Required and UseDefaultStyle (default true). UserAvatarPart holds a MediaField named Avatar; the editor accepts only image extensions from MediaOptions.AllowedFileExtensions and is shown only to users with ManageMedia.

using CrestApps.OrchardCore.Users.Models;
using Microsoft.Extensions.Options;
using OrchardCore.Users.Models;

namespace MyModule.Services;

public sealed class AvatarReader
{
    private readonly IOptionsMonitor<UserAvatarOptions> _avatarOptions;

    public AvatarReader(IOptionsMonitor<UserAvatarOptions> avatarOptions)
    {
        _avatarOptions = avatarOptions;
    }

    public bool IsAvatarRequired => _avatarOptions.CurrentValue.Required;

    public IReadOnlyList<string> GetPaths(User user)
        => user.As<UserAvatarPart>()?.Avatar?.Paths ?? [];
}
{
  "steps": [
    {
      "name": "Settings",
      "UserAvatarOptions": {
        "Required": false,
        "UseDefaultStyle": true
      }
    }
  ]
}

Sign in with an email code

CrestApps.OrchardCore.Users.EmailCodeSignIn adds Email me a sign-in code to the login form (EmailCodeLoginFormDisplayDriver) and the pages sign-in/email (route EmailSignIn) and sign-in/email/code (route EmailSignInCode).

Re-index users with a recipe

UpdateUserRecipeStepHandler handles IndexUsers when OrchardCore.Users is enabled. It re-saves enabled users by default; IncludeDisabledUsers includes disabled ones. BatchSize defaults to 250 when absent or not positive, and is capped at 1000.

{
  "steps": [
    {
      "name": "IndexUsers",
      "IncludeDisabledUsers": false,
      "BatchSize": 250
    }
  ]
}

Upgrading from 2.x

Troubleshooting

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.