Browse Source

Another bugfix for initial user creation.

pull/85/head
Sebastian Stehle 9 years ago
parent
commit
3de8b1e323
  1. 30
      src/Squidex/Config/Identity/IdentityUsage.cs
  2. 2
      src/Squidex/Config/Identity/MyIdentityOptions.cs
  3. 5
      src/Squidex/Properties/launchSettings.json
  4. 2
      src/Squidex/app/theme/_static.scss

30
src/Squidex/Config/Identity/IdentityUsage.cs

@ -6,6 +6,7 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
@ -13,6 +14,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Squidex.Domain.Users; using Squidex.Domain.Users;
using Squidex.Infrastructure.Log;
using Squidex.Shared.Identity; using Squidex.Shared.Identity;
using Squidex.Shared.Users; using Squidex.Shared.Users;
@ -53,6 +55,8 @@ namespace Squidex.Config.Identity
var userManager = app.ApplicationServices.GetService<UserManager<IUser>>(); var userManager = app.ApplicationServices.GetService<UserManager<IUser>>();
var userFactory = app.ApplicationServices.GetService<IUserFactory>(); var userFactory = app.ApplicationServices.GetService<IUserFactory>();
var log = app.ApplicationServices.GetService<ISemanticLog>();
if (options.IsAdminConfigured()) if (options.IsAdminConfigured())
{ {
var adminEmail = options.AdminEmail; var adminEmail = options.AdminEmail;
@ -60,28 +64,18 @@ namespace Squidex.Config.Identity
Task.Run(async () => Task.Run(async () =>
{ {
var user = await userManager.FindByEmailAsync(adminEmail); if ((userManager.SupportsQueryableUsers && !userManager.Users.Any()))
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 (options.EnforceAdmin) try
{ {
await userInitAsync(user); await userManager.CreateAsync(userFactory, adminEmail, adminEmail, adminPass);
}
} }
else if ((userManager.SupportsQueryableUsers && !userManager.Users.Any()) || options.EnforceAdmin) catch (Exception ex)
{ {
user = userFactory.Create(adminEmail); log.LogError(ex, w => w
.WriteProperty("action", "createAdmin")
await userManager.CreateAsync(user); .WriteProperty("status", "failed"));
await userInitAsync(user); }
} }
}).Wait(); }).Wait();
} }

2
src/Squidex/Config/Identity/MyIdentityOptions.cs

@ -26,8 +26,6 @@ namespace Squidex.Config.Identity
public string MicrosoftSecret { get; set; } public string MicrosoftSecret { get; set; }
public bool EnforceAdmin { get; set; }
public bool RequiresHttps { get; set; } public bool RequiresHttps { get; set; }
public bool AllowPasswordAuth { get; set; } public bool AllowPasswordAuth { get; set; }

5
src/Squidex/Properties/launchSettings.json

@ -18,8 +18,11 @@
"commandName": "Project", "commandName": "Project",
"launchUrl": "http://localhost:5000", "launchUrl": "http://localhost:5000",
"environmentVariables": { "environmentVariables": {
"IDENTITY__ADMINEMAIL": "sebastian@squidex.io",
"IDENTITY__ADMINPASSWORD": "1Xhn2a3b4!?",
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} },
"applicationUrl": "http://localhost:5000"
} }
} }
} }

2
src/Squidex/app/theme/_static.scss

@ -94,7 +94,7 @@ noscript {
&-text { &-text {
color: darken($color-border, 15%); color: darken($color-border, 15%);
display: inline-block; display: inline-block;
background: $color-background; background: $color-dark-foreground;
border: 0; border: 0;
bottom: -.7rem; bottom: -.7rem;
position: relative; position: relative;

Loading…
Cancel
Save