Ensure default reading profile is created when creating a user

This commit is contained in:
Amelia 2025-05-29 23:25:35 +02:00
parent cfc65d14a0
commit cfab91a29b
No known key found for this signature in database
GPG key ID: D6D0ECE365407EAA
4 changed files with 25 additions and 3 deletions

View file

@ -153,6 +153,9 @@ public class AccountController : BaseApiController
// Assign default streams
AddDefaultStreamsToUser(user);
// Assign default reading profile
AddDefaultReadingProfileToUser(user);
var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
if (string.IsNullOrEmpty(token)) return BadRequest(await _localizationService.Get("en", "confirm-token-gen"));
if (!await ConfirmEmailToken(token, user)) return BadRequest(await _localizationService.Get("en", "validate-email", token));
@ -669,6 +672,9 @@ public class AccountController : BaseApiController
// Assign default streams
AddDefaultStreamsToUser(user);
// Assign default reading profile
AddDefaultReadingProfileToUser(user);
// Assign Roles
var roles = dto.Roles;
var hasAdminRole = dto.Roles.Contains(PolicyConstants.AdminRole);
@ -779,6 +785,15 @@ public class AccountController : BaseApiController
}
}
private void AddDefaultReadingProfileToUser(AppUser user)
{
var profile = new AppUserReadingProfileBuilder(user.Id)
.WithName("Default Profile")
.Build();
user.UserPreferences.ReadingProfiles.Add(profile);
user.UserPreferences.DefaultReadingProfile = profile;
}
/// <summary>
/// Last step in authentication flow, confirms the email token for email
/// </summary>