- First registered user is auto-assigned Admin role (empty DB)
- Add auth.public-registration.enabled setting to disable public
registration (only admins can create users via POST /api/users)
- Add DELETE /api/users/{id} endpoint (Admin only) with guards:
- Cannot delete own account
- Cannot delete the last administrator
- Guard AssignRolesAsync to prevent removing Admin from last admin
- Add AuthSettings constants class for well-known setting keys
Adds .AsNoTracking() to all read-only list/pagination queries in
SiteService, AgentService, CameraService, AuditLogService, and
UserService. Prevents EF Core change tracker overhead when only
displaying data.
UserService.ListAsync and UserSites query benefit most (materialize
AppUser/UserSite entities). AuditLogService, SiteService, CameraService,
AgentService paginated lists are read-only so AsNoTracking is safe.
ListAsync called UserManager.GetRolesAsync() per user (N queries
for N users). Now loads all roles and user-site assignments in two
bulk queries, grouped by userId in memory for O(1) lookup.
Setting LockoutEnd to UtcNow locked the user out instead of forcing
a password change. Added MustChangePassword boolean to AppUser entity
with EF Core migration. ResetPasswordAsync now sets this flag instead
of locking the account.
GenerateTemporaryPassword now uses RandomNumberGenerator (cryptographic)
and guarantees at least 1 digit, 1 lowercase letter to satisfy Identity
password rules (RequireDigit=true, RequireLowercase=true).
Also shuffles the result to avoid predictable position patterns.
Fixes flaky ResetPassword_WithAdminAuth_ReturnsTemporaryPassword test.