123123
This commit is contained in:
@@ -7,16 +7,10 @@ namespace ZelWiki.Repository
|
||||
{
|
||||
public static class SecurityRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Detect whether this is the first time the WIKI has ever been run and do some initialization.
|
||||
/// Adds the first user with the email and password contained in Constants.DEFAULTUSERNAME and Constants.DEFAULTPASSWORD
|
||||
/// </summary>
|
||||
public static async void ValidateEncryptionAndCreateAdminUser(UserManager<IdentityUser> userManager)
|
||||
{
|
||||
if (ConfigurationRepository.IsFirstRun())
|
||||
{
|
||||
//If this is the first time the app has run on this machine (based on an encryption key) then clear the admin password status.
|
||||
//This will cause the application to set the admin password to the default password and display a warning until it is changed.
|
||||
UsersRepository.SetAdminPasswordClear();
|
||||
}
|
||||
|
||||
@@ -36,7 +30,7 @@ namespace ZelWiki.Repository
|
||||
|
||||
user.EnsureNotNull();
|
||||
|
||||
user.Email = Constants.DEFAULTUSERNAME; // Ensure email is set or updated
|
||||
user.Email = Constants.DEFAULTUSERNAME;
|
||||
user.EmailConfirmed = true;
|
||||
var emailUpdateResult = await userManager.UpdateAsync(user);
|
||||
if (!emailUpdateResult.Succeeded)
|
||||
@@ -79,19 +73,15 @@ namespace ZelWiki.Repository
|
||||
|
||||
public static async void UpsertUserClaims(UserManager<IdentityUser> userManager, IdentityUser user, List<Claim> givenClaims)
|
||||
{
|
||||
// Get existing claims for the user
|
||||
var existingClaims = await userManager.GetClaimsAsync(user);
|
||||
|
||||
foreach (var givenClaim in givenClaims)
|
||||
{
|
||||
// Remove existing claims if they exist
|
||||
var firstNameClaim = existingClaims.FirstOrDefault(c => c.Type == givenClaim.Type);
|
||||
if (firstNameClaim != null)
|
||||
{
|
||||
await userManager.RemoveClaimAsync(user, firstNameClaim);
|
||||
}
|
||||
|
||||
// Add new claim.
|
||||
await userManager.AddClaimAsync(user, givenClaim);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user