From 3de8b1e3236fb6ce75c9fe5473d03fe540c21c1f Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Wed, 26 Jul 2017 18:32:56 +0200 Subject: [PATCH] Another bugfix for initial user creation. --- src/Squidex/Config/Identity/IdentityUsage.cs | 32 ++++++++----------- .../Config/Identity/MyIdentityOptions.cs | 2 -- src/Squidex/Properties/launchSettings.json | 5 ++- src/Squidex/app/theme/_static.scss | 2 +- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/Squidex/Config/Identity/IdentityUsage.cs b/src/Squidex/Config/Identity/IdentityUsage.cs index 3212ec834..807e30bac 100644 --- a/src/Squidex/Config/Identity/IdentityUsage.cs +++ b/src/Squidex/Config/Identity/IdentityUsage.cs @@ -6,6 +6,7 @@ // All rights reserved. // ========================================================================== +using System; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; @@ -13,6 +14,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Squidex.Domain.Users; +using Squidex.Infrastructure.Log; using Squidex.Shared.Identity; using Squidex.Shared.Users; @@ -53,6 +55,8 @@ namespace Squidex.Config.Identity var userManager = app.ApplicationServices.GetService>(); var userFactory = app.ApplicationServices.GetService(); + var log = app.ApplicationServices.GetService(); + if (options.IsAdminConfigured()) { var adminEmail = options.AdminEmail; @@ -60,28 +64,18 @@ namespace Squidex.Config.Identity Task.Run(async () => { - var user = await userManager.FindByEmailAsync(adminEmail); - - async Task userInitAsync(IUser theUser) - { - await userManager.RemovePasswordAsync(theUser); - await userManager.ChangePasswordAsync(theUser, null, adminPass); - await userManager.AddToRoleAsync(theUser, SquidexRoles.Administrator); - } - - if (user != null) + if ((userManager.SupportsQueryableUsers && !userManager.Users.Any())) { - if (options.EnforceAdmin) + try { - await userInitAsync(user); + await userManager.CreateAsync(userFactory, adminEmail, adminEmail, adminPass); + } + catch (Exception ex) + { + log.LogError(ex, w => w + .WriteProperty("action", "createAdmin") + .WriteProperty("status", "failed")); } - } - else if ((userManager.SupportsQueryableUsers && !userManager.Users.Any()) || options.EnforceAdmin) - { - user = userFactory.Create(adminEmail); - - await userManager.CreateAsync(user); - await userInitAsync(user); } }).Wait(); } diff --git a/src/Squidex/Config/Identity/MyIdentityOptions.cs b/src/Squidex/Config/Identity/MyIdentityOptions.cs index 10d0fc99a..9dde059cb 100644 --- a/src/Squidex/Config/Identity/MyIdentityOptions.cs +++ b/src/Squidex/Config/Identity/MyIdentityOptions.cs @@ -26,8 +26,6 @@ namespace Squidex.Config.Identity public string MicrosoftSecret { get; set; } - public bool EnforceAdmin { get; set; } - public bool RequiresHttps { get; set; } public bool AllowPasswordAuth { get; set; } diff --git a/src/Squidex/Properties/launchSettings.json b/src/Squidex/Properties/launchSettings.json index 1aa5504bd..32dcc5edc 100644 --- a/src/Squidex/Properties/launchSettings.json +++ b/src/Squidex/Properties/launchSettings.json @@ -18,8 +18,11 @@ "commandName": "Project", "launchUrl": "http://localhost:5000", "environmentVariables": { + "IDENTITY__ADMINEMAIL": "sebastian@squidex.io", + "IDENTITY__ADMINPASSWORD": "1Xhn2a3b4!?", "ASPNETCORE_ENVIRONMENT": "Development" - } + }, + "applicationUrl": "http://localhost:5000" } } } \ No newline at end of file diff --git a/src/Squidex/app/theme/_static.scss b/src/Squidex/app/theme/_static.scss index f37d0960d..6298b2086 100644 --- a/src/Squidex/app/theme/_static.scss +++ b/src/Squidex/app/theme/_static.scss @@ -94,7 +94,7 @@ noscript { &-text { color: darken($color-border, 15%); display: inline-block; - background: $color-background; + background: $color-dark-foreground; border: 0; bottom: -.7rem; position: relative;