Browse Source

Another bugfix for initial user creation.

pull/85/head
Sebastian Stehle 9 years ago
parent
commit
3de8b1e323
  1. 32
      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

32
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<UserManager<IUser>>();
var userFactory = app.ApplicationServices.GetService<IUserFactory>();
var log = app.ApplicationServices.GetService<ISemanticLog>();
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();
}

2
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; }

5
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"
}
}
}

2
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;

Loading…
Cancel
Save