public AuthenticationService( TenantRepository tenantRepository, UserRepository userRepository, EncryptionService encryptionService) { this.EncryptionService = encryptionService; this.TenantRepository = tenantRepository; this.UserRepository = userRepository; }
public TenantProvisioningService( TenantRepository tenantRepository, UserRepository userRepository, RoleRepository roleRepository) { this.RoleRepository = roleRepository; this.TenantRepository = tenantRepository; this.UserRepository = userRepository; }
public OctopusRepository(IOctopusClient client) { this.Client = client; Feeds = new FeedRepository(client); Backups = new BackupRepository(client); Machines = new MachineRepository(client); MachineRoles = new MachineRoleRepository(client); MachinePolicies = new MachinePolicyRepository(client); Subscriptions = new SubscriptionRepository(client); Environments = new EnvironmentRepository(client); Events = new EventRepository(client); FeaturesConfiguration = new FeaturesConfigurationRepository(client); ProjectGroups = new ProjectGroupRepository(client); Projects = new ProjectRepository(client); Proxies = new ProxyRepository(client); Tasks = new TaskRepository(client); Users = new UserRepository(client); VariableSets = new VariableSetRepository(client); LibraryVariableSets = new LibraryVariableSetRepository(client); DeploymentProcesses = new DeploymentProcessRepository(client); Releases = new ReleaseRepository(client); Deployments = new DeploymentRepository(client); Certificates = new CertificateRepository(client); Dashboards = new DashboardRepository(client); DashboardConfigurations = new DashboardConfigurationRepository(client); Artifacts = new ArtifactRepository(client); Interruptions = new InterruptionRepository(client); ServerStatus = new ServerStatusRepository(client); UserRoles = new UserRolesRepository(client); Teams = new TeamsRepository(client); RetentionPolicies = new RetentionPolicyRepository(client); Accounts = new AccountRepository(client); Defects = new DefectsRepository(client); Lifecycles = new LifecyclesRepository(client); OctopusServerNodes = new OctopusServerNodeRepository(client); Channels = new ChannelRepository(client); ProjectTriggers = new ProjectTriggerRepository(client); Schedulers = new SchedulerRepository(client); Tenants = new TenantRepository(client); TagSets = new TagSetRepository(client); BuiltInPackageRepository = new BuiltInPackageRepositoryRepository(client); ActionTemplates = new ActionTemplateRepository(client); CommunityActionTemplates = new CommunityActionTemplateRepository(client); }
public virtual async Task <TenantDto> CreateAsync(TenantCreateDto input) { var tenant = await TenantManager.CreateAsync(input.Name); await TenantRepository.InsertAsync(tenant); using (CurrentTenant.Change(tenant.Id, tenant.Name)) { //TODO: Handle database creation? await DataSeeder.SeedAsync( new DataSeedContext(tenant.Id) .WithProperty("AdminEmail", input.AdminEmailAddress) .WithProperty("AdminPassword", input.AdminPassword) ); } return(ObjectMapper.Map <Tenant, TenantDto>(tenant)); }
public OctopusAsyncRepository(IOctopusAsyncClient client) { this.Client = client; Feeds = new FeedRepository(client); Backups = new BackupRepository(client); ActionTemplates = new ActionTemplateRepository(client); Machines = new MachineRepository(client); MachineRoles = new MachineRoleRepository(client); MachinePolicies = new MachinePolicyRepository(client); Environments = new EnvironmentRepository(client); Events = new EventRepository(client); FeaturesConfiguration = new FeaturesConfigurationRepository(client); ProjectGroups = new ProjectGroupRepository(client); Projects = new ProjectsRepository(client); Proxies = new ProxyRepository(client); Tasks = new TaskRepository(client); Users = new UserRepository(client); VariableSets = new VariableSetRepository(client); LibraryVariableSets = new LibraryVariableSetRepository(client); DeploymentProcesses = new DeploymentProcessRepository(client); Releases = new ReleaseRepository(client); Deployments = new DeploymentRepository(client); Certificates = new CertificateRepository(client); Dashboards = new DashboardRepository(client); DashboardConfigurations = new DashboardConfigurationRepository(client); Artifacts = new ArtifactRepository(client); Interruptions = new InterruptionRepository(client); ServerStatus = new ServerStatusRepository(client); UserRoles = new UserRolesRepository(client); Teams = new TeamsRepository(client); RetentionPolicies = new RetentionPolicyRepository(client); Accounts = new AccountRepository(client); Defects = new DefectsRepository(client); Lifecycles = new LifecyclesRepository(client); OctopusServerNodes = new OctopusServerNodeRepository(client); Channels = new ChannelRepository(client); ProjectTriggers = new ProjectTriggerRepository(client); Schedulers = new SchedulerRepository(client); Subscriptions = new SubscriptionRepository(client); Tenants = new TenantRepository(client); TagSets = new TagSetRepository(client); BuiltInPackageRepository = new BuiltInPackageRepositoryRepository(client); }
private async Task <TenantRepository> SetupTenantRepository() { var inMemoryDatabase = new TestSQLiteInMemoryDatabase().GetConnection(); var tenants = (await Tenant.GetDummyTenantSet()).ToList(); const string createTenantsTableQuery = @" CREATE TABLE Tenants ( Id INTEGER PRIMARY KEY, Name TEXT NOT NULL, Alias TEXT NOT NULL, Guid TEXT NOT NULL UNIQUE ); "; await inMemoryDatabase.ExecuteAsync(createTenantsTableQuery); const string insertTenantQuery = @" INSERT INTO Tenants (Id, Name, Alias, Guid) VALUES (@Id, @Name, @Alias, @Guid); "; foreach (var tenant in tenants) { await inMemoryDatabase.ExecuteAsync(insertTenantQuery, new { @Id = tenant.Id, @Name = tenant.Name, @Alias = tenant.Alias, @Guid = tenant.Guid.ToString() }); } var databaseConfiguration = new Mock <DatabaseConfiguration>(); var databaseConnectionFactory = new Mock <DatabaseConnectionFactory>(databaseConfiguration.Object); databaseConnectionFactory.Setup(factory => factory.GetConnection()).Returns(inMemoryDatabase); var tenantRepository = new TenantRepository(databaseConnectionFactory.Object); SqlMapper.AddTypeHandler(typeof(Guid), new TestGuidTypeHandler()); return(tenantRepository); }
public virtual async Task <TenantDto> UpdateAsync(Guid id, TenantUpdateDto input) { var tenant = await TenantRepository.GetAsync(id, false); var updateEventData = new UpdateEventData { Id = tenant.Id, OriginName = tenant.Name, Name = input.Name }; await TenantManager.ChangeNameAsync(tenant, input.Name); input.MapExtraPropertiesTo(tenant); await TenantRepository.UpdateAsync(tenant); await EventBus.PublishAsync(updateEventData); return(ObjectMapper.Map <Tenant, TenantDto>(tenant)); }
public async Task <AbpLoginResult <TTenant, TUser> > LoginAsyncInternal(string login, string tenancyName) { if (string.IsNullOrWhiteSpace(login)) { throw new ArgumentException("login"); } //Get and check tenant TTenant tenant = null; if (!MultiTenancyConfig.IsEnabled) { tenant = await GetDefaultTenantAsync(); } else if (!string.IsNullOrWhiteSpace(tenancyName)) { tenant = await TenantRepository.FirstOrDefaultAsync(t => t.TenancyName == tenancyName); if (tenant == null) { return(new AbpLoginResult <TTenant, TUser>(AbpLoginResultType.InvalidTenancyName)); } if (!tenant.IsActive) { return(new AbpLoginResult <TTenant, TUser>(AbpLoginResultType.TenantIsNotActive, tenant)); } } int?tenantId = tenant == null ? (int?)null : tenant.Id; using (UnitOfWorkManager.Current.SetTenantId(tenantId)) { var user = await UserManager.FindByNameOrEmailAsync(login); if (user == null) { return(new AbpLoginResult <TTenant, TUser>(AbpLoginResultType.UnknownExternalLogin, tenant)); } return(await CreateLoginResultAsync(login, tenant)); } }
protected virtual async Task <JTLoginResult <TTenant, TUser> > LoginAsyncInternal(UserLoginInfo login, string tenancyName) { if (login == null || login.LoginProvider.IsNullOrEmpty() || login.ProviderKey.IsNullOrEmpty()) { throw new ArgumentException("login"); } //Get and check tenant TTenant tenant = null; if (!MultiTenancyConfig.IsEnabled) { tenant = await GetDefaultTenantAsync(); } else if (!string.IsNullOrWhiteSpace(tenancyName)) { tenant = await TenantRepository.FirstOrDefaultAsync(t => t.TenancyName == tenancyName); if (tenant == null) { return(new JTLoginResult <TTenant, TUser>(JTLoginResultType.InvalidTenancyName)); } if (!tenant.IsActive) { return(new JTLoginResult <TTenant, TUser>(JTLoginResultType.TenantIsNotActive, tenant)); } } int?tenantId = tenant == null ? (int?)null : tenant.Id; using (UnitOfWorkManager.Current.SetTenantId(tenantId)) { TUser user = await UserManager.FindAsync(tenantId, login); if (user == null) { return(new JTLoginResult <TTenant, TUser>(JTLoginResultType.UnknownExternalLogin, tenant)); } return(await CreateLoginResultAsync(user, tenant)); } }
public virtual async Task <TenantDto> CreateAsync(TenantCreateDto input) { var tenant = await TenantManager.CreateAsync(input.Name); input.MapExtraPropertiesTo(tenant); await TenantRepository.InsertAsync(tenant); using (CurrentTenant.Change(tenant.Id, tenant.Name)) { //TODO: 对新建的租户数据进行初始化 await DataSeeder.SeedAsync( new DataSeedContext (tenant.Id) .WithProperty ("AdminEmail", input.AdminPhoneNumber) .WithProperty("AdminPassword", input.AdminPassword) ); } return(ObjectMapper.Map <Tenant, TenantDto> (tenant)); }
public virtual async Task<PagedResultDto<TenantDto>> GetListAsync(GetTenantsInput input) { if (input.Sorting.IsNullOrWhiteSpace()) { input.Sorting = nameof(Tenant.Name); } var count = await TenantRepository.GetCountAsync(input.Filter); var list = await TenantRepository.GetListAsync( input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter ); return new PagedResultDto<TenantDto>( count, ObjectMapper.Map<List<Tenant>, List<TenantDto>>(list) ); }
public virtual async Task <TenantConnectionStringDto> SetConnectionStringAsync(Guid id, TenantConnectionStringCreateOrUpdateDto tenantConnectionStringCreateOrUpdate) { var tenant = await TenantRepository.GetAsync(id); tenant.SetConnectionString(tenantConnectionStringCreateOrUpdate.Name, tenantConnectionStringCreateOrUpdate.Value); var updateEventData = new UpdateEventData { Id = tenant.Id, OriginName = tenant.Name, Name = tenant.Name }; // abp当前版本(3.0.0)在EntityChangeEventHelper中存在一个问题,无法发送框架默认的Eto,预计3.1.0修复 // 发送自定义的事件数据来确保缓存被更新 await EventBus.PublishAsync(updateEventData); return(new TenantConnectionStringDto { Name = tenantConnectionStringCreateOrUpdate.Name, Value = tenantConnectionStringCreateOrUpdate.Value }); }
protected virtual async Task <AbpLoginResult <Tenant, User> > LoginAsyncInternal(string yunToken, string appID, string appSecret, string yunXT, string teancyName) { if (string.IsNullOrWhiteSpace(yunToken)) { throw new ArgumentException("login"); } Tenant tenant = null; if (!MultiTenancyConfig.IsEnabled) { tenant = await GetDefaultTenantAsync(); } else if (!string.IsNullOrWhiteSpace(teancyName)) { tenant = await TenantRepository.FirstOrDefaultAsync(t => t.TenancyName == teancyName); if (tenant == null) { return(new AbpLoginResult <Tenant, User>(AbpLoginResultType.TenantIsNotActive, tenant)); } } int?tenantId = tenant == null ? (int?)null : tenant.Id; using (UnitOfWorkManager.Current.SetTenantId(tenantId)) { //解析云之家token var yunUser = await GetUserByToken(yunToken, appID, appSecret, yunXT); string userName = yunUser.mobile; var user = await UserManager.AbpStore.FindByNameAsync(userName); if (user == null) { return(new AbpLoginResult <Tenant, User>(AbpLoginResultType.InvalidUserNameOrEmailAddress)); } return(await CreateLoginResultAsync(user, tenant)); } }
public virtual async Task <TenantDto> CreateAsync(TenantCreateDto input) { var tenant = await TenantManager.CreateAsync(input.Name); input.MapExtraPropertiesTo(tenant); await TenantRepository.InsertAsync(tenant); await CurrentUnitOfWork.SaveChangesAsync(); var createEventData = new CreateEventData { Id = tenant.Id, Name = tenant.Name, AdminEmailAddress = input.AdminEmailAddress, AdminPassword = input.AdminPassword }; // 因为项目各自独立,租户增加时添加管理用户必须通过事件总线 // 而 TenantEto 对象没有包含所需的用户名密码,需要独立发布事件 await EventBus.PublishAsync(createEventData); return(ObjectMapper.Map <Tenant, TenantDto>(tenant)); }
public async Task <RegisterTenantResult> Create(RegisterTenantInput input, CancellationToken ct) { using (DataFilter.Disable <IMultiTenant>()) { var existsTenant = await TenantRepository.FindByNameAsync(input.Name, false, ct); if (existsTenant != null) { throw new BusinessException(ScoringDomainErrorCodes.TenantAlreadyExists) .WithData("name", input.Name); } } // Create tenant var tenant = await TenantManager.CreateAsync(input.Name); tenant = await TenantRepository.InsertAsync(tenant, true, ct); IdentityUser adminIdentity; using (CurrentTenant.Change(tenant.Id)) { await DataSeeder.SeedAsync( new DataSeedContext(tenant.Id) .WithProperty("AdminEmail", input.AdminEmailAddress) .WithProperty("AdminPassword", input.AdminPassword) ); adminIdentity = await UserManager.FindByEmailAsync(input.AdminEmailAddress); } var adminTokenDto = new RegisterAdminTokenDto(await AuthJwtProvider.GenerateJwt(adminIdentity, ct)); var tenantDto = ObjectMapper.Map <Tenant, TenantDto>(tenant); return(new RegisterTenantResult(adminTokenDto, tenantDto)); }
public virtual async Task <string> GetDefaultConnectionStringAsync(Guid id) { var tenant = await TenantRepository.GetAsync(id); return(tenant?.FindDefaultConnectionString()); }
public virtual async Task <SaasTenantDto> GetAsync(Guid id) { return(ObjectMapper.Map <SaasTenant, SaasTenantDto>( await TenantRepository.GetAsync(id))); }
/// <summary> /// 删除商户 /// </summary> /// <param name="tenant">商户对象</param> /// <returns></returns> public virtual async Task <IdentityResult> DeleteAsync(TTenant tenant) { await TenantRepository.DeleteAsync(tenant); return(IdentityResult.Success); }
public OctopusAsyncRepository(IOctopusAsyncClient client, RepositoryScope repositoryScope = null) { #if FULL_FRAMEWORK LocationChecker.CheckAssemblyLocation(); #endif Client = client; Scope = repositoryScope ?? RepositoryScope.Unspecified(); Accounts = new AccountRepository(this); ActionTemplates = new ActionTemplateRepository(this); Artifacts = new ArtifactRepository(this); Backups = new BackupRepository(this); BuiltInPackageRepository = new BuiltInPackageRepositoryRepository(this); BuildInformationRepository = new BuildInformationRepository(this); CertificateConfiguration = new CertificateConfigurationRepository(this); Certificates = new CertificateRepository(this); Channels = new ChannelRepository(this); CommunityActionTemplates = new CommunityActionTemplateRepository(this); Configuration = new ConfigurationRepository(this); DashboardConfigurations = new DashboardConfigurationRepository(this); Dashboards = new DashboardRepository(this); Defects = new DefectsRepository(this); DeploymentProcesses = new DeploymentProcessRepository(this); DeploymentSettings = new DeploymentSettingsRepository(this); Deployments = new DeploymentRepository(this); Environments = new EnvironmentRepository(this); Events = new EventRepository(this); FeaturesConfiguration = new FeaturesConfigurationRepository(this); Feeds = new FeedRepository(this); GitCredentials = new GitCredentialRepository(this); Interruptions = new InterruptionRepository(this); LibraryVariableSets = new LibraryVariableSetRepository(this); Licenses = new LicensesRepository(this); Lifecycles = new LifecyclesRepository(this); MachinePolicies = new MachinePolicyRepository(this); MachineRoles = new MachineRoleRepository(this); Machines = new MachineRepository(this); Migrations = new MigrationRepository(this); OctopusServerNodes = new OctopusServerNodeRepository(this); PerformanceConfiguration = new PerformanceConfigurationRepository(this); ProjectGroups = new ProjectGroupRepository(this); Projects = new ProjectRepository(this); Runbooks = new RunbookRepository(this); RunbookProcesses = new RunbookProcessRepository(this); RunbookSnapshots = new RunbookSnapshotRepository(this); RunbookRuns = new RunbookRunRepository(this); ProjectTriggers = new ProjectTriggerRepository(this); Proxies = new ProxyRepository(this); Releases = new ReleaseRepository(this); RetentionPolicies = new RetentionPolicyRepository(this); Schedulers = new SchedulerRepository(this); ServerStatus = new ServerStatusRepository(this); Spaces = new SpaceRepository(this); Subscriptions = new SubscriptionRepository(this); TagSets = new TagSetRepository(this); Tasks = new TaskRepository(this); Teams = new TeamsRepository(this); TelemetryConfigurationRepository = new TelemetryConfigurationRepository(this); Tenants = new TenantRepository(this); TenantVariables = new TenantVariablesRepository(this); UserInvites = new UserInvitesRepository(this); UserRoles = new UserRolesRepository(this); Users = new UserRepository(this); VariableSets = new VariableSetRepository(this); Workers = new WorkerRepository(this); WorkerPools = new WorkerPoolRepository(this); ScopedUserRoles = new ScopedUserRoleRepository(this); UserPermissions = new UserPermissionsRepository(this); UserTeams = new UserTeamsRepository(this); UpgradeConfiguration = new UpgradeConfigurationRepository(this); loadRootResource = new Lazy <Task <RootResource> >(LoadRootDocumentInner, true); loadSpaceRootResource = new Lazy <Task <SpaceRootResource> >(LoadSpaceRootDocumentInner, true); }
protected virtual async Task <AbpLoginResult <TTenant, TUser> > LoginAsyncInternal (string userNameOrEmailAddress, string plainPassword, string tenancyName, bool shouldLockout) { if (userNameOrEmailAddress.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(userNameOrEmailAddress)); } if (plainPassword.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(plainPassword)); } //Get and check tenant TTenant tenant = null; using (UnitOfWorkManager.Current.SetTenantId(null)) { if (!MultiTenancyConfig.IsEnabled) { tenant = await GetDefaultTenantAsync(); } else if (!string.IsNullOrWhiteSpace(tenancyName)) { tenant = await TenantRepository.FirstOrDefaultAsync(t => t.TenancyName == tenancyName); if (tenant == null) { return(new AbpLoginResult <TTenant, TUser>(AbpLoginResultType.InvalidTenancyName)); } if (!tenant.IsActive) { return(new AbpLoginResult <TTenant, TUser>(AbpLoginResultType.TenantIsNotActive, tenant)); } } } var tenantId = tenant == null ? (int?)null : tenant.Id; using (UnitOfWorkManager.Current.SetTenantId(tenantId)) { //TryLoginFromExternalAuthenticationSources method may create the user, that's why we are calling it before AbpStore.FindByNameOrEmailAsync var loggedInFromExternalSource = await TryLoginFromExternalAuthenticationSources (userNameOrEmailAddress, plainPassword, tenant); var user = await UserManager.AbpStore.FindByNameOrEmailAsync(tenantId, userNameOrEmailAddress); if (user == null) { return(new AbpLoginResult <TTenant, TUser>(AbpLoginResultType.InvalidUserNameOrEmailAddress, tenant)); } if (await UserManager.IsLockedOutAsync(user.Id)) { return(new AbpLoginResult <TTenant, TUser>(AbpLoginResultType.LockedOut, tenant, user)); } if (!loggedInFromExternalSource) { UserManager.InitializeLockoutSettings(tenantId); var verificationResult = UserManager.PasswordHasher.VerifyHashedPassword (user.Password, plainPassword); if (verificationResult == PasswordVerificationResult.Failed) { return(await GetFailedPasswordValidationAsLoginResultAsync(user, tenant, shouldLockout)); } if (verificationResult == PasswordVerificationResult.SuccessRehashNeeded) { return(await GetSuccessRehashNeededAsLoginResultAsync(user, tenant)); } await UserManager.ResetAccessFailedCountAsync(user.Id); } return(await CreateLoginResultAsync(user, tenant)); } }
public virtual void Delete(TTenant tenant) { TenantRepository.Delete(tenant); }
public virtual Task <TTenant> FindByTenancyNameAsync(string tenancyName) { return(TenantRepository.FirstOrDefaultAsync(t => t.TenancyName == tenancyName)); }
public async Task <TenantDto> GetAsync(Guid id) { return(ObjectMapper.Map <Tenant, TenantDto>( await TenantRepository.GetAsync(id) )); }
public TenantController(TenantRepository tenantRepository) { _tenantRepository = tenantRepository; }
// This function will get triggered/executed when a new message is written // on an Azure Queue called queue. public static async Task ProcessQueueMessage([QueueTrigger("tenant-queue")] Tenant tenant) { TenantRepository tenantRepo = new TenantRepository(tenant.TenantID); data.ITenant t = await tenantRepo.GetAsync(); if (t == null || string.IsNullOrEmpty(t.Server) == false || string.IsNullOrEmpty(t.Database) == false) { Console.WriteLine("[{0}] Tenant already configured or something when wrong.", tenant.TenantID); return; } var credentials = SdkContext.AzureCredentialsFactory .FromServicePrincipal(CloudConfigurationManager.GetSetting("az:clientId"), //clientId, CloudConfigurationManager.GetSetting("az:clientSecret"), //clientSecret, CloudConfigurationManager.GetSetting("az:tenantId"), //tenantId, AzureEnvironment.AzureGlobalCloud); var azure = Microsoft.Azure.Management.Fluent.Azure .Configure() .Authenticate(credentials) .WithDefaultSubscription(); string startAddress = "0.0.0.0"; string endAddress = "255.255.255.255"; var servers = await azure.SqlServers.ListAsync(); var avaibleServers = servers.Where(x => x.Databases.List().Count < 150 && x.ResourceGroupName == "ssas-demo"); ISqlServer sqlServer; if (avaibleServers.Any()) { sqlServer = avaibleServers.FirstOrDefault(); } else { string sqlServerName = SdkContext.RandomResourceName("saas-", 8); // Create the SQL server instance sqlServer = azure.SqlServers.Define(sqlServerName) .WithRegion(Region.USEast) .WithExistingResourceGroup("ssas-demo") .WithAdministratorLogin(CloudConfigurationManager.GetSetting("sqlserver:username")) .WithAdministratorPassword(CloudConfigurationManager.GetSetting("sqlserver:password")) .WithNewFirewallRule(startAddress, endAddress) .Create(); } string dbName = SdkContext.RandomResourceName("saas-", 8); // Create the database ISqlDatabase sqlDb = sqlServer.Databases.Define(dbName) .WithEdition(DatabaseEditions.Standard) .WithServiceObjective(ServiceObjectiveName.S0) .Create(); Console.WriteLine(sqlServer.FullyQualifiedDomainName); Console.WriteLine(sqlDb.Name); await tenantRepo.UpdateAsync(sqlDb.SqlServerName, sqlDb.Name); if (string.IsNullOrEmpty(tenant.Email) == false) { await SendEmailNotification(tenant.Email, tenant.Organization); } }
public Db() { _tenantRepository = new TenantRepository(Connection); }
public virtual TTenant FindById(int id) { return(TenantRepository.FirstOrDefault(id)); }
protected virtual async Task <ShaLoginResult <TTenant, TUser> > LoginAsyncInternal(string userNameOrEmailAddress, string plainPassword, string imei, string tenancyName, bool shouldLockout) { if (userNameOrEmailAddress.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(userNameOrEmailAddress)); } if (plainPassword.IsNullOrEmpty()) { throw new ArgumentNullException(nameof(plainPassword)); } //Get and check tenant TTenant tenant = null; using (UnitOfWorkManager.Current.SetTenantId(null)) { if (!MultiTenancyConfig.IsEnabled) { tenant = await GetDefaultTenantAsync(); } else if (!string.IsNullOrWhiteSpace(tenancyName)) { tenant = await TenantRepository.FirstOrDefaultAsync(t => t.TenancyName == tenancyName); if (tenant == null) { return(new ShaLoginResult <TTenant, TUser>(ShaLoginResultType.InvalidTenancyName)); } if (!tenant.IsActive) { return(new ShaLoginResult <TTenant, TUser>(ShaLoginResultType.TenantIsNotActive, tenant)); } } } var tenantId = tenant?.Id; using (UnitOfWorkManager.Current.SetTenantId(tenantId)) { await UserManager.InitializeOptionsAsync(tenantId); //TryLoginFromExternalAuthenticationSources method may create the user, that's why we are calling it before AbpUserStore.FindByNameOrEmailAsync var loggedInFromExternalSource = await TryLoginFromExternalAuthenticationSourcesAsync(userNameOrEmailAddress, plainPassword, tenant); var user = await UserManager.FindByNameOrEmailAsync(tenantId, userNameOrEmailAddress); if (user == null) { return(new ShaLoginResult <TTenant, TUser>(ShaLoginResultType.InvalidUserNameOrEmailAddress, tenant)); } else if (IocResolver.IsRegistered <IEmailLoginFilter <TUser> >() && userNameOrEmailAddress.IsEmail()) { var filter = IocResolver.Resolve <IEmailLoginFilter <TUser> >(); if (!filter.AllowToLoginUsingEmail(userNameOrEmailAddress, user)) { return(new ShaLoginResult <TTenant, TUser>(ShaLoginResultType.InvalidUserName, tenant, user)); } } if (await UserManager.IsLockedOutAsync(user)) { return(new ShaLoginResult <TTenant, TUser>(ShaLoginResultType.LockedOut, tenant, user)); } if (!loggedInFromExternalSource) { if (!await UserManager.CheckPasswordAsync(user, plainPassword)) { if (shouldLockout) { if (await TryLockOutAsync(tenantId, user.Id)) { return(new ShaLoginResult <TTenant, TUser>(ShaLoginResultType.LockedOut, tenant, user)); } } return(new ShaLoginResult <TTenant, TUser>(ShaLoginResultType.InvalidPassword, tenant, user)); } // authenticated using internal account, check IMEI if (!(await CheckImeiAsync(imei))) { return(new ShaLoginResult <TTenant, TUser>(ShaLoginResultType.DeviceNotRegistered, tenant, user)); } await UserManager.ResetAccessFailedCountAsync(user); } else { // authenticated using external source, check IMEI if (!(await CheckImeiAsync(imei))) { return(new ShaLoginResult <TTenant, TUser>(ShaLoginResultType.DeviceNotRegistered, tenant, user)); } } return(await CreateLoginResultAsync(user, tenant)); } }
/// <summary> /// 获取租户 /// </summary> /// <param name="id"></param> /// <returns></returns> public virtual async Task <TenantResult> GetAsync(string id) { var tenant = await TenantRepository.FirstOrDefaultAsync(p => p.Id == id); return(tenant?.MapTo <TenantResult>()); }
public virtual async Task <TTenant> FindByIdAsync(int id) { return(await TenantRepository.FirstOrDefaultAsync(id)); }
/// <summary> /// 获取租户列表 /// </summary> /// <param name="input"></param> /// <returns></returns> public virtual async Task <PagedResult <TenantResult> > GetListAsync(TenantRequest input) { return(await TenantRepository.Query().ToPageResultAsync <Tenant, TenantResult>(input)); }
public virtual async Task DeleteAsync(TTenant tenant) { await TenantRepository.DeleteAsync(tenant); }
public virtual TTenant FindByTenancyName(string tenancyName) { return(TenantRepository.FirstOrDefault(t => t.TenancyName == tenancyName)); }