This commit is contained in:
Zel
2025-02-23 18:47:21 +08:00
parent eaaffeeccb
commit e46a7ca31c
104 changed files with 2630 additions and 2516 deletions

View File

@@ -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);
}