Files
xSaherElmIds/Interfaces/IXIdentityManager.cs
2026-03-22 14:08:25 +03:30

506 lines
15 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Security.Claims;
using System.Threading.Tasks;
using IdentityModel.Client;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using xCommons.Providers;
using xIdentityModels;
using xIdentityModels.Constants;
using xIdentityModels.Descriptors;
using xIdentityModels.Dtos;
using xIdentityModels.Models;
using xIdentityModels.Navigations;
using xIds.DbContext;
using xModels.Dtos;
namespace xIds.Interfaces
{
public interface IXIdentityManager
{
XIdentityDbContext DbContext { get; }
UserManager<XUser> UserManager { get; }
ILogger<IXIdentityManager> Logger { get; }
SignInManager<XUser> SignInManager { get; }
IXSecurityProvider SecurityProvider { get; }
RoleManager<IdentityRole> RoleManager { get; }
XValidationProvider ValidationProvider { get; }
//
#region Class Getter (s) Methods ...
IQueryable<XUser> GetUsersDbSet(
bool containsDetail = false
);
IQueryable<XUser> GetUsersFullDbSet(bool enableTracking = false);
#endregion
//
#region Tools ...
string GetUserSelectByParam(
XActionRequest model,
bool forceNotNull = true,
ICollection<XUserSelectBy> excludes = null
);
Task<XUser> ValidateUserExistsAndRetrieve(
string userSelectByParam,
bool containsDetail = false,
bool checkCanLoginPolicies = false,
bool checkIsBanned = true,
bool ignoreDisabledUser = false,
bool forceAdmin = false,
Exception exception = null
);
#endregion
//
#region Default Identity Preparation Actions ...
Task CreateIdentityRoles();
Task CreateUserAsync(XIdentityUserDescriptor user);
#endregion
//
#region Identity Actions ...
HttpClient GetHttpClient();
Task<IdentityModel.Client.TokenResponse> RequestScopeAccessToken(string scope);
Task<DiscoveryDocumentResponse> RequestDiscoveryDocument();
Task<IdentityModel.Client.TokenResponse> Authenticate(XLoginRequest model);
Task<XLoginResponse> Login(XLoginRequest model);
Task<XTokenResponse> RefreshTokens(XTokenResponse model);
#endregion
//
#region Role Handlers ...
Task<bool> IsRoleExistsAsync(string roleName);
Task<IdentityResult> CreateRoleAsync(string roleName);
Task<IdentityRole> GetRoleAsync(string roleName);
Task<IdentityResult> AddUserToRoleAsync(XUser user, string roleName);
Task<string> GetRoleNameAsync(string roleId);
Task<IEnumerable<string>> GetRoleNamesAsync(
string userSelectByParam,
bool checkCanLoginPolicies = true,
bool checkIsBanned = true
);
Task<IdentityResult> RemoveFromRoleAsync(XUser user, string roleName);
Task<IdentityResult> RemoveFromRolesAsync(XUser user, IEnumerable<string> roleNames);
#endregion
//
#region User Handlers ...
Task<bool> CanRegister(string userSelectByParam);
Task<bool> IsUserExistsAsync(string userSelectByParam);
Task<XUser> GetUserAsync(
string userSelectByParam,
bool containsDetail = false);
Task<IdentityResult> CreateUserAsync(
XUser user,
string password,
bool checkCanLoginPolicies = true,
bool checkIsBanned = true
);
Task<IdentityResult> UpdateUserAsync(
XUser user,
bool checkCanLoginPolicies = true,
bool checkIsBanned = true
);
Task<IEnumerable<string>> GetUserNamesAsync(
IEnumerable<string> userIds
);
Task<IEnumerable<XUserNameIdResponse>> GetUserNameIdsAsync(
XUserNameIdRequest model
);
Task<Claim[]> ToJwtClaims(
XUser user,
bool checkCanLoginPolicies = true,
bool checkIsBanned = true
);
Task<SignInResult> CheckPasswordSignInAsync(
XUser user,
string password,
XDevice device,
string language,
bool lockoutOnFailure,
bool isForced = true
);
#endregion
//
#region User Profile Handlers ...
Task<XUserProfileDto> GetUserProfileAsync(
string userSelectByParam,
string requestedUserSelectByParam,
bool forceCheckRequestedUser = true,
bool checkCanLoginPolicies = true,
bool checkIsBanned = true
);
Task<XQueryResult<XUserProfileDto>> QueryUsers(
string requestedUserSelectByParam,
XQuery query
);
Task<XQueryResult<XUserProfileDto>> QueryInRoleUsers(
string requestedUserSelectByParam,
string role,
XQuery query,
bool forceRole = false
);
Task<IEnumerable<XUserProfileDto>> GetUserProfilesAsync(
ICollection<string> ids,
string requestedUserSelectByParam,
bool forceCheckRequestedUser = true,
bool checkCanLoginPolicies = true,
bool checkIsBanned = true
);
Task<XQueryResult<XProfileImage>> QueryAvatars(
string userSelectByParam,
XQuery query
);
Task<XUserProfileDto> ProfileUpdateAsync(
string userSelectByParam,
string requestedUserSelectByParam,
XProfileUpdateRequest request
);
Task<XUserProfileDto> FullProfileUpdateAsync(
string userSelectByParam,
string requestedUserSelectByParam,
XProfileUpdateRequest request
);
Task<XActionResponse> RequestConfirmMobile(
string lang,
XDevice device,
string userSelectByParam,
string password,
string mobileNumber = null
);
Task<XActionResponse> RequestConfirmEmail(
string lang,
XDevice device,
string userSelectByParam,
string password,
string emailAddress = null
);
Task<XActionResponse> RequestResetPassword(
string lang,
XDevice device,
string userSelectByParam,
string returnUrl
);
Task RequestConfirmRegistration(
string lang,
XDevice device,
string userSelectByParam,
string password,
string returnUrl
);
Task ChangePassword(
string lang,
XDevice device,
string userSelectByParam,
string password,
string newPassword,
string returnUrl
);
Task ResetPassword(
string lang,
XDevice device,
string actionHash,
string newPassword,
string returnUrl
);
Task<XUserProfileDto> AddAvatar(
string userSelectByParam,
IFormFile file
);
Task<XUserProfileDto> AddAvatars(
string userSelectByParam,
IFormFileCollection files
);
Task<XUserProfileDto> SetAvatar(
string userSelectByParam,
int profileImageId
);
Task<XUserProfileDto> RemoveAvatar(
string userSelectByParam,
ICollection<int> profileImageIds
);
Task ConfirmRegistration(
string lang,
XDevice device,
string actionHash,
string returnUrl
);
Task<XActionResponse> ConfirmMobileNumber(
string lang,
XDevice device,
string registrationHash,
string verificationCode
);
Task<XActionResponse> ConfirmEmailAddress(
string lang,
XDevice device,
string registrationHash,
string verificationCode
);
Task<bool> IsConfirmedEmail(string userSelectByParam);
Task<bool> IsConfirmedMobile(string userSelectByParam);
#endregion
//
#region Registration Handlers ...
Task<XActionResponse> InviteUser(
string lang,
XDevice device,
string email,
string handlerUrl
);
Task<XActionResponse> RequestRegistration(
string lang,
XDevice device,
string invitationHash,
string firstName,
string lastName,
DateTime dateOfBirth,
string mobileNumber = null,
string emailAddress = null
);
Task<XActionResponse> AddAcountInfo(
string lang,
XDevice device,
string registrationHash,
string userName,
string password
);
Task<XActionResponse> AttachProfileImage(
string tokenHash,
IFormFile file
);
Task FinishRegistration(
string lang,
XDevice device,
string userSelectByParam,
string password,
string returnUrl
);
#endregion
//
#region Friendship Handlers ...
//
#region Actions ...
Task<XFriendshipFollowing> Follow(
string userSelectByParam,
string destUserSelectByParam
);
Task<bool> Cancel(
string userSelectByParam,
string destUserSelectByParam
);
Task UnFollowFollower(
string userSelectByParam,
string destUserSelectByParam
);
Task UnFollowFollowing(
string userSelectByParam,
string destUserSelectByParam
);
Task<XFriendshipFollowing> Block(
string userSelectByParam,
string destUserSelectByParam
);
Task<XFriendshipFollowing> UnBlock(
string userSelectByParam,
string destUserSelectByParam
);
#endregion
//
#region Request Handlers ...
Task<XFriendshipFollower> AcceptRequest(
string userSelectByParam,
string destUserSelectByParam
);
Task<XFriendshipFollower> RejectRequest(
string userSelectByParam,
string destUserSelectByParam
);
#endregion
//
#region Getters ...
Task<bool> IsFollower(
string userSelectByParam,
string destUserSelectByParam,
bool checkIsBanned = true,
bool checkCanLoginPolicies = true
);
Task<XFriendshipState> GetFollowerState(
string userSelectByParam,
string destUserSelectByParam,
bool checkIsBanned = true,
bool checkCanLoginPolicies = true
);
Task<XFriendshipFollower> GetFollower(
string userSelectByParam,
string destUserSelectByParam
);
Task<IEnumerable<XFriendshipFollower>> GetFollowers(string userSelectByParam);
Task<IEnumerable<XFriendshipFollower>> GetAllFollowers(string userSelectByParam);
Task<ICollection<string>> GetFollowersList(string userSelectByParam);
Task<XQueryResult<XFriendDto>> QueryFollowers(
XQuery query,
string userSelectByParam
);
Task<bool> IsFollowing(
string userSelectByParam,
string destUserSelectByParam,
bool checkIsBanned = true,
bool checkCanLoginPolicies = true
);
Task<XFriendshipState> GetFollowingState(
string userSelectByParam,
string destUserSelectByParam,
bool checkIsBanned = true,
bool checkCanLoginPolicies = true
);
Task<XFriendshipFollowing> GetFollowing(
string userSelectByParam,
string destUserSelectByParam
);
Task<IEnumerable<XFriendshipFollowing>> GetFollowings(string userSelectByParam);
Task<IEnumerable<XFriendshipFollowing>> GetAllFollowings(string userSelectByParam);
Task<ICollection<string>> GetFollowingList(string userSelectByParam);
Task<XQueryResult<XFriendDto>> QueryFollowings(
XQuery query,
string userSelectByParam
);
#endregion
//
Task<XFriendshipInfoDto> GetFriendshipInfo(
string userSelectByParam,
string destUserSelectByParam,
bool checkCanLoginPolicies = true,
bool checkIsBanned = true
);
#endregion
//
#region Admin Actions ...
Task<ICollection<string>> Ban(
string userSelectByParam,
XUserNameIdRequest model
);
Task<ICollection<string>> UnBan(
string userSelectByParam,
XUserNameIdRequest model
);
Task<bool> IsBanned(
string userSelectByParam,
string destUserSelectByParam
);
#endregion
//
#region Open Actions ...
//
#region OpenGet ...
Task<XOpenActionInnerDto> OpenGet(
XOpenActionInnerDto model
);
Task<XOpenActionInnerDto> OpenGet(
string token,
string actionRequest
);
#endregion
Task<XOpenActionUserInfoDto> GetUserInfo(
XOpenActionRequestDto dto
);
Task<IEnumerable<XOpenActionUserInfoDto>> GetUserInfos(
XOpenActionRequestDto dto
);
#endregion
//
#region Search ...
/// <summary>
/// Query Open To Search User Profiles ...
/// </summary>
/// <param name="requestedUserSelectByParam">requested user's identifier</param>
/// <param name="query">how to filter results based on <see>XQuery</see> structure</param>
/// <returns>an instance of <see>XQueryResult</see> of <see>XUserProfileDto</see></returns>
Task<XQueryResult<XUserProfileDto>> QueryOpenToSearchUsers(
string requestedUserSelectByParam,
XQuery query
);
#endregion
//
#region Query Service ...
/// <summary>
/// Retrieve Users as Query Model for Query Service ...
/// </summary>
/// <param name="requestedUserSelectByParam"></param>
/// <param name="query"></param>
/// <param name="role"></param>
/// <param name="forceRole"></param>
/// <returns></returns>
public Task<XQueryResult<string>> QueryUsers(
string requestedUserSelectByParam,
XQuery query,
string role = null,
bool forceRole = false
);
#endregion
}
}