Table of Contents

Class UserServiceBase<TUser, TRole, TKey>

Namespace
NuvTools.Security.Identity.AspNetCore.Services
Assembly
NuvTools.Security.Identity.AspNetCore.dll

Provides a base service for user management operations, built upon UserManager<TUser>.

public abstract class UserServiceBase<TUser, TRole, TKey> where TUser : UserBase<TKey> where TRole : IdentityRole<TKey> where TKey : IEquatable<TKey>

Type Parameters

TUser

The user entity type.

TRole

The role entity type.

TKey

The type of the user's primary key.

Inheritance
UserServiceBase<TUser, TRole, TKey>
Inherited Members

Remarks

This abstract base class consolidates common user-related actions such as creation, updates, password management, email confirmation, and role assignments.
It standardizes the return model using IResult and IResult<T>.

Constructors

UserServiceBase(UserManager<TUser>)

Provides a base service for user management operations, built upon UserManager<TUser>.

protected UserServiceBase(UserManager<TUser> userManager)

Parameters

userManager UserManager<TUser>

Remarks

This abstract base class consolidates common user-related actions such as creation, updates, password management, email confirmation, and role assignments.
It standardizes the return model using IResult and IResult<T>.

Methods

ChangeEmailAsync(TKey, string, string)

Applies an email change using a confirmation token.

public Task<IResult> ChangeEmailAsync(TKey id, string email, string token)

Parameters

id TKey
email string
token string

Returns

Task<IResult>

ChangePasswordAsync(TKey, string, string)

Changes the user's password.

public Task<IResult> ChangePasswordAsync(TKey id, string password, string newPassword)

Parameters

id TKey
password string
newPassword string

Returns

Task<IResult>

ConfirmEmailAsync(TKey, string)

Confirms a user's email address.

public Task<IResult> ConfirmEmailAsync(TKey id, string token)

Parameters

id TKey
token string

Returns

Task<IResult>

CreateAsync(TUser)

Creates a new user in the system.

public Task<IResult<TKey>> CreateAsync(TUser value)

Parameters

value TUser

Returns

Task<IResult<TKey>>

CreateWithRolesAsync(TUser, params string[])

Creates a new user and assigns one or more roles.

public Task<IResult<TKey>> CreateWithRolesAsync(TUser value, params string[] roles)

Parameters

value TUser
roles string[]

Returns

Task<IResult<TKey>>

DeleteAsync(TKey)

Deletes a user by identifier.

public Task<IResult> DeleteAsync(TKey id)

Parameters

id TKey

Returns

Task<IResult>

GenerateEmailConfirmationTokenAsync(TUser)

Generates a base64-encoded token used for email confirmation.

public Task<string> GenerateEmailConfirmationTokenAsync(TUser user)

Parameters

user TUser

Returns

Task<string>

GenerateEmailConfirmationUriAsync(TUser, string, string)

Generates a verification URL for confirming the user's email.

public Task<string> GenerateEmailConfirmationUriAsync(TUser user, string origin, string route = "login")

Parameters

user TUser
origin string
route string

Returns

Task<string>

GetAllAsync()

Gets all users as an IQueryable<T> queryable collection.

public IQueryable<TUser> GetAllAsync()

Returns

IQueryable<TUser>

GetAsync(TKey)

Retrieves a user by their unique identifier.

public Task<TUser?> GetAsync(TKey id)

Parameters

id TKey

Returns

Task<TUser>

GetByEmailAsync(string)

Retrieves a user by their email address.

public Task<TUser?> GetByEmailAsync(string email)

Parameters

email string

Returns

Task<TUser>

GetRolesAsync(TKey)

Retrieves all role names assigned to a user.

public Task<IList<string>?> GetRolesAsync(TKey id)

Parameters

id TKey

Returns

Task<IList<string>>

RequestChangeEmailUrlAsync(string, string, string, string)

Generates a URL for confirming an email change request.

public Task<IResult<string>> RequestChangeEmailUrlAsync(string email, string newEmail, string origin, string route = "security/change-email")

Parameters

email string
newEmail string
origin string
route string

Returns

Task<IResult<string>>

RequestResetPasswordUrlAsync(string, string, string)

Generates a password reset URL for a user with a confirmed email.

public Task<IResult<string>> RequestResetPasswordUrlAsync(string email, string origin, string route = "security/reset-password")

Parameters

email string
origin string
route string

Returns

Task<IResult<string>>

ResetPasswordAsync(string, string, string)

Resets the user's password using a reset token.

public Task<IResult> ResetPasswordAsync(string email, string newPassword, string token)

Parameters

email string
newPassword string
token string

Returns

Task<IResult>

ToggleUserStatusAsync(TKey)

Toggles the user's active status.

public virtual Task<IResult> ToggleUserStatusAsync(TKey id)

Parameters

id TKey

Returns

Task<IResult>

UpdateAsync(TUser)

Updates basic user information (name, surname, etc.).

public Task<IResult> UpdateAsync(TUser value)

Parameters

value TUser

Returns

Task<IResult>

UpdateRolesAsync(TKey, IList<string>)

Replaces all roles of a user with a new set of roles.

public Task<IResult> UpdateRolesAsync(TKey id, IList<string> roles)

Parameters

id TKey
roles IList<string>

Returns

Task<IResult>