From e7bc86ebb8496615e0b3f73eb4f13ab4c0913dc8 Mon Sep 17 00:00:00 2001 From: Jxiced Date: Sun, 23 Feb 2025 22:16:35 +0000 Subject: Move throw into interface to use in wizard, check for null and invalid username. --- Jellyfin.Api/Controllers/StartupController.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Jellyfin.Api/Controllers/StartupController.cs') diff --git a/Jellyfin.Api/Controllers/StartupController.cs b/Jellyfin.Api/Controllers/StartupController.cs index a6bc84311..b3b900ceb 100644 --- a/Jellyfin.Api/Controllers/StartupController.cs +++ b/Jellyfin.Api/Controllers/StartupController.cs @@ -1,3 +1,4 @@ +using System; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; @@ -130,16 +131,16 @@ public class StartupController : BaseJellyfinApiController [ProducesResponseType(StatusCodes.Status204NoContent)] public async Task UpdateStartupUser([FromBody] StartupUserDto startupUserDto) { + ArgumentNullException.ThrowIfNull(startupUserDto.Name); + _userManager.ThrowIfInvalidUsername(startupUserDto.Name); + var user = _userManager.Users.First(); if (string.IsNullOrWhiteSpace(startupUserDto.Password)) { return BadRequest("Password must not be empty"); } - if (startupUserDto.Name is not null) - { - user.Username = startupUserDto.Name; - } + user.Username = startupUserDto.Name; await _userManager.UpdateUserAsync(user).ConfigureAwait(false); -- cgit v1.2.3