Path: redb/redb.Core/Providers/IUserProvider.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Providers/IUserProvider.cs
----
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using redb.Core.Models.Contracts;
using redb.Core.Models.Users;
namespace redb.Core.Providers
{
///
/// Provider for user management.
/// Provides CRUD operations and business logic for working with users.
///
public interface IUserProvider
{
// === CRUD OPERATIONS ===
///
/// Create new user.
///
/// User creation data
/// Current user (for audit)
/// Created user
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task CreateUserAsync(CreateUserRequest request, IRedbUser? currentUser = null,
CancellationToken cancellationToken = default);
///
/// Update user data.
///
/// User to update
/// New user data
/// Current user (for audit)
/// Updated user
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task UpdateUserAsync(IRedbUser user, UpdateUserRequest request, IRedbUser? currentUser = null,
CancellationToken cancellationToken = default);
///
/// Delete user (soft delete - deactivation).
/// System users (ID 0, 1) cannot be deleted.
///
/// User to delete
/// Current user (for audit)
/// true if user deleted
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task DeleteUserAsync(IRedbUser user, IRedbUser? currentUser = null,
CancellationToken cancellationToken = default);
// === SEARCH AND RETRIEVAL ===
///
/// Get user by ID.
///
/// User ID
/// User or null if not found
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task GetUserByIdAsync(long userId,
CancellationToken cancellationToken = default);
///
/// Get multiple users by IDs in a single query.
///
Task> GetUsersByIdsAsync(IEnumerable userIds,
CancellationToken cancellationToken = default);
///
/// Get user by login.
///
/// User login
/// User or null if not found
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task GetUserByLoginAsync(string login,
CancellationToken cancellationToken = default);
///
/// Get the first user whose _email matches the supplied address
/// (case-insensitive). Email is NOT enforced unique at the schema level —
/// one address may legitimately be reused after a prior account is soft-deleted
/// or whoever owned it changed their address. Callers that need a uniqueness
/// invariant (e.g. federation-conflict probes) should still verify the result
/// against their own policy.
///
/// Email address to search by. Whitespace and surrounding
/// punctuation are NOT trimmed — pass a canonicalised value.
/// First matching active user, or null when no row matches.
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task GetUserByEmailAsync(string email,
CancellationToken cancellationToken = default);
///
/// Load user by login (throws exception if not found).
///
/// User login
/// User
/// If user not found
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task LoadUserAsync(string login,
CancellationToken cancellationToken = default);
///
/// Load user by ID (throws exception if not found).
///
/// User ID
/// User
/// If user not found
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task LoadUserAsync(long userId,
CancellationToken cancellationToken = default);
///
/// Get list of users with filtering.
///
/// Search criteria (can be null)
/// List of users
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task> GetUsersAsync(UserSearchCriteria? criteria = null,
CancellationToken cancellationToken = default);
///
/// Count users matching criteria without loading data.
///
Task CountUsersAsync(UserSearchCriteria? criteria = null,
CancellationToken cancellationToken = default);
// === AUTHENTICATION ===
///
/// Validate user login and password.
///
/// Login
/// Password (plain text)
/// User if credentials valid, null if invalid
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task ValidateUserAsync(string login, string password,
CancellationToken cancellationToken = default);
///
/// Change user password.
///
/// User
/// Current password (for verification)
/// New password
/// Current user (for audit)
/// true if password changed
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task ChangePasswordAsync(IRedbUser user, string currentPassword, string newPassword, IRedbUser? currentUser = null,
CancellationToken cancellationToken = default);
///
/// Set new password for user (without checking old password).
/// For administrators only.
///
/// User
/// New password
/// Current user (for audit)
/// true if password set
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task SetPasswordAsync(IRedbUser user, string newPassword, IRedbUser? currentUser = null,
CancellationToken cancellationToken = default);
///
/// Store a password hash computed elsewhere, for example an administrator password given in
/// configuration as a hash rather than in plain text. The hash is written as is, so it must be
/// one the configured verifies: with the
/// default hasher, a BCrypt hash ($2a$, $2b$ or $2y$).
/// Same access rules as .
///
/// User
/// Password hash
/// Current user (for audit)
/// true if the hash was stored
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task SetPasswordHashAsync(IRedbUser user, string passwordHash, IRedbUser? currentUser = null,
CancellationToken cancellationToken = default)
=> throw new NotSupportedException($"{GetType().Name} does not support setting a password hash.");
// === STATUS MANAGEMENT ===
///
/// Activate user.
///
/// User
/// Current user (for audit)
/// true if user activated
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task EnableUserAsync(IRedbUser user, IRedbUser? currentUser = null,
CancellationToken cancellationToken = default);
///
/// Deactivate user.
/// System users (ID 0, 1) cannot be deactivated.
///
/// User
/// Current user (for audit)
/// true if user deactivated
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task DisableUserAsync(IRedbUser user, IRedbUser? currentUser = null,
CancellationToken cancellationToken = default);
// === VALIDATION ===
///
/// Validate user data correctness.
///
/// Data to validate
/// Validation result
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task ValidateUserDataAsync(CreateUserRequest request,
CancellationToken cancellationToken = default);
///
/// Check login availability.
///
/// Login to check
/// User ID to exclude (for update)
/// true if login available
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task IsLoginAvailableAsync(string login, long? excludeUserId = null,
CancellationToken cancellationToken = default);
// === STATISTICS ===
///
/// Get user count.
///
/// Include deactivated users
/// Number of users
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task GetUserCountAsync(bool includeDisabled = false,
CancellationToken cancellationToken = default);
///
/// Get active user count for period.
///
/// Start date
/// End date
/// Number of active users
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task GetActiveUserCountAsync(DateTimeOffset fromDate, DateTimeOffset toDate,
CancellationToken cancellationToken = default);
// === CONFIGURATION MANAGEMENT ===
///
/// Get user configuration ID.
///
/// User ID
/// Configuration ID or null if not set
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task GetUserConfigurationIdAsync(long userId,
CancellationToken cancellationToken = default);
///
/// Set user configuration.
///
/// User ID
/// Configuration ID (RedbObject<UserConfigurationProps>) or null to reset
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task SetUserConfigurationAsync(long userId, long? configId,
CancellationToken cancellationToken = default);
///
/// Get user roles.
/// Used for building effective configuration.
///
/// User ID
/// List of user roles
/// Cancels the operation (OCE only; a rollback in flight always completes).
Task> GetUserRolesAsync(long userId,
CancellationToken cancellationToken = default);
}
}