重写abpusermanager,取消用户名不可重复问题

在domain中创建一个manager,继承UserManager
实现创建用户方法。

public class NonWasteCityUserManager: UserManager<IdentityUser>, IDomainService
{
    public NonWasteCityUserManager(IUserStore<IdentityUser> store, 
        IOptions<IdentityOptions> optionsAccessor, 
        IPasswordHasher<IdentityUser> passwordHasher, 
        IEnumerable<IUserValidator<IdentityUser>> userValidators, 
        IEnumerable<IPasswordValidator<IdentityUser>> passwordValidators, 
        ILookupNormalizer keyNormalizer, IdentityErrorDescriber errors, 
        IServiceProvider services, ILogger<UserManager<IdentityUser>> logger) 
        : base(store, optionsAccessor, passwordHasher, userValidators, passwordValidators, 
            keyNormalizer, errors, services, logger)
    {
        
    }
    
    /// 
    /// Creates the specified  in the backing store with given password,
    /// as an asynchronous operation.
    /// 
    /// The user to create.
    /// The password for the user to hash and store.
    /// to validate Password for the user in the store.
    /// 
    /// The  that represents the asynchronous operation, containing the 
    /// of the operation.
    /// 
    public virtual async Task<IdentityResult> CreateAsync(IdentityUser user, string password, bool validatePassword = false)
    {
        ThrowIfDisposed();
        if (user == null)
        {
            throw new ArgumentNullException(nameof(user));
        }
        if (string.IsNullOrEmpty(password))
        {
            throw new ArgumentNullException(nameof(password));
        }
        var result = await UpdatePasswordHash(user, password,validatePassword);
        if (!result.Succeeded)
        {
            return result;
        }
        return await CreateAsync(user);
    }
    
    private async Task<IdentityResult> CreateAsync(IdentityUser user)
    {
        this.ThrowIfDisposed();
        // await UpdateSecurityStampInternal(user);
        // IdentityResult async = await ValidateUserAsync(user);
        // if (!async.Succeeded)
        //     return async;
        // if (this.Options.Lockout.AllowedForNewUsers && this.SupportsUserLockout)
        //     await this.GetUserLockoutStore().SetLockoutEnabledAsync(user, true, this.CancellationToken);
        await SetLockoutEnabledAsync(user, true);
        await UpdateNormalizedUserNameAsync(user);
        await UpdateNormalizedEmailAsync(user);
        return await Store.CreateAsync(user, this.CancellationToken);
    }
    
}

你可能感兴趣的:(abp,服务器,.netcore)