public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { var tenant = new IdentityTenant() { Name = Input.TeamName, Domain = Input.Domain, }; var result = await _tenantManager.CreateAsync(tenant); if (result.Succeeded) { var user = new MultiTenantUser { UserName = Input.Email, Email = Input.Email, TenantId = tenant.Id, }; result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } } else { await _tenantManager.DeleteAsync(tenant); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IdentityResult> CheckSeed() { var panacheSoftwareConfiguration = new PanacheSoftwareConfiguration(); _configuration.Bind("PanacheSoftware", panacheSoftwareConfiguration); var admin = _userManager.FindByNameAsync($"admin@{panacheSoftwareConfiguration.StartDomain}").Result; if (admin == null) { var adminUser = new UserModel() { Id = Guid.Empty, FirstName = "Admin", Surname = "User", FullName = "Admin User", Email = $"admin@{panacheSoftwareConfiguration.StartDomain}", Status = StatusTypes.Open, DateFrom = DateTime.Now, DateTo = DateTime.Now.AddYears(99), Description = "Admin User", Base64ProfileImage = Base64Images.PanacheSoftwareDot }; var identityTenant = new IdentityTenant() { Domain = panacheSoftwareConfiguration.StartDomain, CreatedByEmail = $"admin@{panacheSoftwareConfiguration.StartDomain}", Description = "Default tenant" }; if (CreateTenant(identityTenant) != null) { return(await CreateUserAsync(adminUser, new ModelStateDictionary(), "Passw0rd123!", "Passw0rd123!", identityTenant.Id)); } IdentityErrorDescriber identityError = new IdentityErrorDescriber(); return(IdentityResult.Failed(identityError.InvalidUserName($"admin@{panacheSoftwareConfiguration.StartDomain}"))); } return(IdentityResult.Success); }
private IdentityTenant CreateTenant(IdentityTenant identityTenant) { //Ensure Tenant ID is empty identityTenant.Id = Guid.Empty; identityTenant.CreatedDate = DateTime.Now; identityTenant.DateFrom = identityTenant.CreatedDate; identityTenant.DateTo = identityTenant.DateFrom.AddYears(99); identityTenant.Status = StatusTypes.Open; var tenant = GetTenant(default(Guid), identityTenant.Domain); if (!string.IsNullOrWhiteSpace(identityTenant.Domain) && GetTenant(default(Guid), identityTenant.Domain) == null) { _context.IdetityTenants.Add(identityTenant); _context.SaveChanges(); return(identityTenant); } return(null); }