24 changed files with 246 additions and 28 deletions
@ -0,0 +1,48 @@ |
|||||
|
using LINGYUN.Abp.Account.Localization; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Localization; |
||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Identity; |
||||
|
using IIdentityUserRepository = LINGYUN.Abp.Account.IIdentityUserRepository; |
||||
|
|
||||
|
namespace Microsoft.AspNetCore.Identity |
||||
|
{ |
||||
|
[Dependency(ServiceLifetime.Scoped, ReplaceServices = true)] |
||||
|
[ExposeServices(typeof(IUserValidator<IdentityUser>))] |
||||
|
public class PhoneNumberUserValidator : UserValidator<IdentityUser> |
||||
|
{ |
||||
|
private readonly IStringLocalizer<AccountResource> _stringLocalizer; |
||||
|
private readonly IIdentityUserRepository _identityUserRepository; |
||||
|
|
||||
|
public PhoneNumberUserValidator( |
||||
|
IStringLocalizer<AccountResource> stringLocalizer, |
||||
|
IIdentityUserRepository identityUserRepository) |
||||
|
{ |
||||
|
_stringLocalizer = stringLocalizer; |
||||
|
_identityUserRepository = identityUserRepository; |
||||
|
} |
||||
|
public override async Task<IdentityResult> ValidateAsync(UserManager<IdentityUser> manager, IdentityUser user) |
||||
|
{ |
||||
|
await ValidatePhoneNumberAsync(manager, user); |
||||
|
return await base.ValidateAsync(manager, user); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task ValidatePhoneNumberAsync(UserManager<IdentityUser> manager, IdentityUser user) |
||||
|
{ |
||||
|
var phoneNumber = await manager.GetPhoneNumberAsync(user); |
||||
|
if (phoneNumber.IsNullOrWhiteSpace()) |
||||
|
{ |
||||
|
throw new UserFriendlyException(_stringLocalizer["InvalidPhoneNumber"].Value, "InvalidPhoneNumber"); |
||||
|
} |
||||
|
|
||||
|
var phoneNumberHasRegisted = await _identityUserRepository.PhoneNumberHasRegistedAsync(phoneNumber); |
||||
|
if (phoneNumberHasRegisted) |
||||
|
{ |
||||
|
throw new UserFriendlyException(_stringLocalizer["DuplicatePhoneNumber", phoneNumber].Value, "DuplicatePhoneNumber"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.Identity.EntityFrameworkCore; |
||||
|
using Volo.Abp.IdentityServer.EntityFrameworkCore; |
||||
|
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
||||
|
using Volo.Abp.SettingManagement.EntityFrameworkCore; |
||||
|
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
||||
|
|
||||
|
namespace LINGYUN.Platform.EntityFrameworkCore |
||||
|
{ |
||||
|
public class PlatformHttpApiHostMigrationsDbContext : AbpDbContext<PlatformHttpApiHostMigrationsDbContext> |
||||
|
{ |
||||
|
public PlatformHttpApiHostMigrationsDbContext(DbContextOptions<PlatformHttpApiHostMigrationsDbContext> options) |
||||
|
: base(options) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder) |
||||
|
{ |
||||
|
base.OnModelCreating(modelBuilder); |
||||
|
|
||||
|
modelBuilder.ConfigureIdentity(); |
||||
|
modelBuilder.ConfigureIdentityServer(options => |
||||
|
{ |
||||
|
options.TablePrefix = "IdentityServer"; |
||||
|
options.Schema = null; |
||||
|
options.DatabaseProvider = EfCoreDatabaseProvider.MySql; |
||||
|
}); |
||||
|
modelBuilder.ConfigureTenantManagement(); |
||||
|
modelBuilder.ConfigureSettingManagement(); |
||||
|
modelBuilder.ConfigurePermissionManagement(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
using System.IO; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.EntityFrameworkCore.Design; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
|
||||
|
namespace LINGYUN.Platform.EntityFrameworkCore |
||||
|
{ |
||||
|
public class PlatformHttpApiHostMigrationsDbContextFactory : IDesignTimeDbContextFactory<PlatformHttpApiHostMigrationsDbContext> |
||||
|
{ |
||||
|
public PlatformHttpApiHostMigrationsDbContext CreateDbContext(string[] args) |
||||
|
{ |
||||
|
var configuration = BuildConfiguration(); |
||||
|
|
||||
|
var builder = new DbContextOptionsBuilder<PlatformHttpApiHostMigrationsDbContext>() |
||||
|
.UseMySql(configuration.GetConnectionString("Default")); |
||||
|
|
||||
|
return new PlatformHttpApiHostMigrationsDbContext(builder.Options); |
||||
|
} |
||||
|
|
||||
|
private static IConfigurationRoot BuildConfiguration() |
||||
|
{ |
||||
|
var builder = new ConfigurationBuilder() |
||||
|
.SetBasePath(Directory.GetCurrentDirectory()) |
||||
|
.AddJsonFile("appsettings.Development.json", optional: false); |
||||
|
|
||||
|
return builder.Build(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace LINGYUN.Platform.EventBus.Handlers |
||||
|
{ |
||||
|
public class TenantConnectionStringCreateEventHandler |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue