80 lines
3.2 KiB
C#
80 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using Volo.Abp.Caching;
|
|
using Volo.Abp.DependencyInjection;
|
|
using Volo.Abp.EventBus.Distributed;
|
|
using Volo.Abp.Identity;
|
|
using Volo.Abp.Security.Claims;
|
|
using Volo.Abp.Settings;
|
|
using Volo.Abp.Threading;
|
|
using IdentityUser = Volo.Abp.Identity.IdentityUser;
|
|
|
|
namespace Kurs.Platform.Identity;
|
|
|
|
[Dependency(ReplaceServices = true)]
|
|
[ExposeServices(typeof(IdentityUserManager))]
|
|
public class PlatformUserManager : IdentityUserManager
|
|
{
|
|
public PlatformUserManager(
|
|
IdentityUserStore store,
|
|
IIdentityRoleRepository roleRepository,
|
|
IIdentityUserRepository userRepository,
|
|
IOptions<IdentityOptions> optionsAccessor,
|
|
IPasswordHasher<IdentityUser> passwordHasher,
|
|
IEnumerable<IUserValidator<IdentityUser>> userValidators,
|
|
IEnumerable<IPasswordValidator<IdentityUser>> passwordValidators,
|
|
ILookupNormalizer keyNormalizer,
|
|
IdentityErrorDescriber errors,
|
|
IServiceProvider services,
|
|
ILogger<IdentityUserManager> logger,
|
|
ICancellationTokenProvider cancellationTokenProvider,
|
|
IOrganizationUnitRepository organizationUnitRepository,
|
|
ISettingProvider settingProvider,
|
|
IDistributedEventBus distributedEventBus,
|
|
IIdentityLinkUserRepository identityLinkUserRepository,
|
|
IDistributedCache<AbpDynamicClaimCacheItem> dynamicClaimCache) : base(store, roleRepository, userRepository, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors, services, logger, cancellationTokenProvider, organizationUnitRepository, settingProvider, distributedEventBus, identityLinkUserRepository, dynamicClaimCache)
|
|
{
|
|
}
|
|
|
|
public override async Task<IdentityResult> AddPasswordAsync(IdentityUser user, string password)
|
|
{
|
|
var result = await base.AddPasswordAsync(user, password);
|
|
if (result.Succeeded)
|
|
await SetPasswordChangeDateAsync(user);
|
|
return result;
|
|
}
|
|
|
|
public override async Task<IdentityResult> ChangePasswordAsync(IdentityUser user, string currentPassword, string newPassword)
|
|
{
|
|
var result = await base.ChangePasswordAsync(user, currentPassword, newPassword);
|
|
if (result.Succeeded)
|
|
await SetPasswordChangeDateAsync(user);
|
|
return result;
|
|
}
|
|
|
|
public override async Task<IdentityResult> ResetPasswordAsync(IdentityUser user, string token, string newPassword)
|
|
{
|
|
var result = await base.ResetPasswordAsync(user, token, newPassword);
|
|
if (result.Succeeded)
|
|
await SetPasswordChangeDateAsync(user);
|
|
return result;
|
|
}
|
|
|
|
public override async Task<IdentityResult> CreateAsync(IdentityUser user, string password)
|
|
{
|
|
var result = await base.CreateAsync(user, password);
|
|
if (result.Succeeded)
|
|
await SetPasswordChangeDateAsync(user);
|
|
return result;
|
|
}
|
|
|
|
protected async Task SetPasswordChangeDateAsync(IdentityUser user)
|
|
{
|
|
user.SetLastPasswordChangeTime(new DateTimeOffset(user.LastModificationTime ?? user.CreationTime));
|
|
await UpdateUserAsync(user);
|
|
}
|
|
}
|