Merge pull request #442 from Moonlight-Panel/v2_ChangeArchitecture_FirstUserAdmin

Implemented first user admin feature
This commit is contained in:
2025-05-17 18:07:15 +02:00
committed by GitHub
2 changed files with 13 additions and 2 deletions

View File

@@ -44,6 +44,8 @@ public class AppConfiguration
public string? AuthorizationEndpoint { get; set; }
public string? AccessEndpoint { get; set; }
public string? AuthorizationRedirect { get; set; }
public bool FirstUserAdmin { get; set; } = true;
}
}

View File

@@ -273,13 +273,22 @@ public class OAuth2Controller : Controller
if (await UserRepository.Get().AnyAsync(x => x.Email == email))
throw new HttpApiException("A account with that email already exists", 400);
var user = new User()
{
Username = username,
Email = email,
Password = HashHelper.Hash(password)
Password = HashHelper.Hash(password),
};
if (Configuration.Authentication.OAuth2.FirstUserAdmin)
{
var userCount = await UserRepository.Get().CountAsync();
if (userCount == 0)
user.PermissionsJson = "[\"*\"]";
}
return await UserRepository.Add(user);
}