UserController.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Jellyfin.Api.Constants;
  7. using Jellyfin.Api.Helpers;
  8. using Jellyfin.Api.Models.UserDtos;
  9. using Jellyfin.Data.Enums;
  10. using MediaBrowser.Common.Extensions;
  11. using MediaBrowser.Common.Net;
  12. using MediaBrowser.Controller.Authentication;
  13. using MediaBrowser.Controller.Configuration;
  14. using MediaBrowser.Controller.Devices;
  15. using MediaBrowser.Controller.Library;
  16. using MediaBrowser.Controller.Net;
  17. using MediaBrowser.Controller.Session;
  18. using MediaBrowser.Model.Configuration;
  19. using MediaBrowser.Model.Dto;
  20. using MediaBrowser.Model.Users;
  21. using Microsoft.AspNetCore.Authorization;
  22. using Microsoft.AspNetCore.Http;
  23. using Microsoft.AspNetCore.Mvc;
  24. namespace Jellyfin.Api.Controllers
  25. {
  26. /// <summary>
  27. /// User controller.
  28. /// </summary>
  29. [Route("Users")]
  30. public class UserController : BaseJellyfinApiController
  31. {
  32. private readonly IUserManager _userManager;
  33. private readonly ISessionManager _sessionManager;
  34. private readonly INetworkManager _networkManager;
  35. private readonly IDeviceManager _deviceManager;
  36. private readonly IAuthorizationContext _authContext;
  37. private readonly IServerConfigurationManager _config;
  38. /// <summary>
  39. /// Initializes a new instance of the <see cref="UserController"/> class.
  40. /// </summary>
  41. /// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
  42. /// <param name="sessionManager">Instance of the <see cref="ISessionManager"/> interface.</param>
  43. /// <param name="networkManager">Instance of the <see cref="INetworkManager"/> interface.</param>
  44. /// <param name="deviceManager">Instance of the <see cref="IDeviceManager"/> interface.</param>
  45. /// <param name="authContext">Instance of the <see cref="IAuthorizationContext"/> interface.</param>
  46. /// <param name="config">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
  47. public UserController(
  48. IUserManager userManager,
  49. ISessionManager sessionManager,
  50. INetworkManager networkManager,
  51. IDeviceManager deviceManager,
  52. IAuthorizationContext authContext,
  53. IServerConfigurationManager config)
  54. {
  55. _userManager = userManager;
  56. _sessionManager = sessionManager;
  57. _networkManager = networkManager;
  58. _deviceManager = deviceManager;
  59. _authContext = authContext;
  60. _config = config;
  61. }
  62. /// <summary>
  63. /// Gets a list of users.
  64. /// </summary>
  65. /// <param name="isHidden">Optional filter by IsHidden=true or false.</param>
  66. /// <param name="isDisabled">Optional filter by IsDisabled=true or false.</param>
  67. /// <response code="200">Users returned.</response>
  68. /// <returns>An <see cref="IEnumerable{UserDto}"/> containing the users.</returns>
  69. [HttpGet]
  70. [Authorize(Policy = Policies.DefaultAuthorization)]
  71. [ProducesResponseType(StatusCodes.Status200OK)]
  72. public ActionResult<IEnumerable<UserDto>> GetUsers(
  73. [FromQuery] bool? isHidden,
  74. [FromQuery] bool? isDisabled)
  75. {
  76. var users = Get(isHidden, isDisabled, false, false);
  77. return Ok(users);
  78. }
  79. /// <summary>
  80. /// Gets a list of publicly visible users for display on a login screen.
  81. /// </summary>
  82. /// <response code="200">Public users returned.</response>
  83. /// <returns>An <see cref="IEnumerable{UserDto}"/> containing the public users.</returns>
  84. [HttpGet("Public")]
  85. [ProducesResponseType(StatusCodes.Status200OK)]
  86. public ActionResult<IEnumerable<UserDto>> GetPublicUsers()
  87. {
  88. // If the startup wizard hasn't been completed then just return all users
  89. if (!_config.Configuration.IsStartupWizardCompleted)
  90. {
  91. return Ok(Get(false, false, false, false));
  92. }
  93. return Ok(Get(false, false, true, true));
  94. }
  95. /// <summary>
  96. /// Gets a user by Id.
  97. /// </summary>
  98. /// <param name="userId">The user id.</param>
  99. /// <response code="200">User returned.</response>
  100. /// <response code="404">User not found.</response>
  101. /// <returns>An <see cref="UserDto"/> with information about the user or a <see cref="NotFoundResult"/> if the user was not found.</returns>
  102. [HttpGet("{userId}")]
  103. [Authorize(Policy = Policies.IgnoreParentalControl)]
  104. [ProducesResponseType(StatusCodes.Status200OK)]
  105. [ProducesResponseType(StatusCodes.Status404NotFound)]
  106. public ActionResult<UserDto> GetUserById([FromRoute, Required] Guid userId)
  107. {
  108. var user = _userManager.GetUserById(userId);
  109. if (user == null)
  110. {
  111. return NotFound("User not found");
  112. }
  113. var result = _userManager.GetUserDto(user, HttpContext.GetNormalizedRemoteIp());
  114. return result;
  115. }
  116. /// <summary>
  117. /// Deletes a user.
  118. /// </summary>
  119. /// <param name="userId">The user id.</param>
  120. /// <response code="204">User deleted.</response>
  121. /// <response code="404">User not found.</response>
  122. /// <returns>A <see cref="NoContentResult"/> indicating success or a <see cref="NotFoundResult"/> if the user was not found.</returns>
  123. [HttpDelete("{userId}")]
  124. [Authorize(Policy = Policies.RequiresElevation)]
  125. [ProducesResponseType(StatusCodes.Status204NoContent)]
  126. [ProducesResponseType(StatusCodes.Status404NotFound)]
  127. public ActionResult DeleteUser([FromRoute, Required] Guid userId)
  128. {
  129. var user = _userManager.GetUserById(userId);
  130. _sessionManager.RevokeUserTokens(user.Id, null);
  131. _userManager.DeleteUser(userId);
  132. return NoContent();
  133. }
  134. /// <summary>
  135. /// Authenticates a user.
  136. /// </summary>
  137. /// <param name="userId">The user id.</param>
  138. /// <param name="pw">The password as plain text.</param>
  139. /// <param name="password">The password sha1-hash.</param>
  140. /// <response code="200">User authenticated.</response>
  141. /// <response code="403">Sha1-hashed password only is not allowed.</response>
  142. /// <response code="404">User not found.</response>
  143. /// <returns>A <see cref="Task"/> containing an <see cref="AuthenticationResult"/>.</returns>
  144. [HttpPost("{userId}/Authenticate")]
  145. [ProducesResponseType(StatusCodes.Status200OK)]
  146. [ProducesResponseType(StatusCodes.Status403Forbidden)]
  147. [ProducesResponseType(StatusCodes.Status404NotFound)]
  148. public async Task<ActionResult<AuthenticationResult>> AuthenticateUser(
  149. [FromRoute, Required] Guid userId,
  150. [FromQuery, Required] string pw,
  151. [FromQuery] string? password)
  152. {
  153. var user = _userManager.GetUserById(userId);
  154. if (user == null)
  155. {
  156. return NotFound("User not found");
  157. }
  158. if (!string.IsNullOrEmpty(password) && string.IsNullOrEmpty(pw))
  159. {
  160. return Forbid("Only sha1 password is not allowed.");
  161. }
  162. // Password should always be null
  163. AuthenticateUserByName request = new AuthenticateUserByName
  164. {
  165. Username = user.Username,
  166. Password = null,
  167. Pw = pw
  168. };
  169. return await AuthenticateUserByName(request).ConfigureAwait(false);
  170. }
  171. /// <summary>
  172. /// Authenticates a user by name.
  173. /// </summary>
  174. /// <param name="request">The <see cref="AuthenticateUserByName"/> request.</param>
  175. /// <response code="200">User authenticated.</response>
  176. /// <returns>A <see cref="Task"/> containing an <see cref="AuthenticationRequest"/> with information about the new session.</returns>
  177. [HttpPost("AuthenticateByName")]
  178. [ProducesResponseType(StatusCodes.Status200OK)]
  179. public async Task<ActionResult<AuthenticationResult>> AuthenticateUserByName([FromBody, Required] AuthenticateUserByName request)
  180. {
  181. var auth = _authContext.GetAuthorizationInfo(Request);
  182. try
  183. {
  184. var result = await _sessionManager.AuthenticateNewSession(new AuthenticationRequest
  185. {
  186. App = auth.Client,
  187. AppVersion = auth.Version,
  188. DeviceId = auth.DeviceId,
  189. DeviceName = auth.Device,
  190. Password = request.Pw,
  191. PasswordSha1 = request.Password,
  192. RemoteEndPoint = HttpContext.GetNormalizedRemoteIp(),
  193. Username = request.Username
  194. }).ConfigureAwait(false);
  195. return result;
  196. }
  197. catch (SecurityException e)
  198. {
  199. // rethrow adding IP address to message
  200. throw new SecurityException($"[{HttpContext.GetNormalizedRemoteIp()}] {e.Message}", e);
  201. }
  202. }
  203. /// <summary>
  204. /// Authenticates a user with quick connect.
  205. /// </summary>
  206. /// <param name="request">The <see cref="QuickConnectDto"/> request.</param>
  207. /// <response code="200">User authenticated.</response>
  208. /// <response code="400">Missing token.</response>
  209. /// <returns>A <see cref="Task"/> containing an <see cref="AuthenticationRequest"/> with information about the new session.</returns>
  210. [HttpPost("AuthenticateWithQuickConnect")]
  211. [ProducesResponseType(StatusCodes.Status200OK)]
  212. public async Task<ActionResult<AuthenticationResult>> AuthenticateWithQuickConnect([FromBody, Required] QuickConnectDto request)
  213. {
  214. var auth = _authContext.GetAuthorizationInfo(Request);
  215. try
  216. {
  217. var authRequest = new AuthenticationRequest
  218. {
  219. App = auth.Client,
  220. AppVersion = auth.Version,
  221. DeviceId = auth.DeviceId,
  222. DeviceName = auth.Device,
  223. };
  224. return await _sessionManager.AuthenticateQuickConnect(
  225. authRequest,
  226. request.Token).ConfigureAwait(false);
  227. }
  228. catch (SecurityException e)
  229. {
  230. // rethrow adding IP address to message
  231. throw new SecurityException($"[{HttpContext.GetNormalizedRemoteIp()}] {e.Message}", e);
  232. }
  233. }
  234. /// <summary>
  235. /// Updates a user's password.
  236. /// </summary>
  237. /// <param name="userId">The user id.</param>
  238. /// <param name="request">The <see cref="UpdateUserPassword"/> request.</param>
  239. /// <response code="204">Password successfully reset.</response>
  240. /// <response code="403">User is not allowed to update the password.</response>
  241. /// <response code="404">User not found.</response>
  242. /// <returns>A <see cref="NoContentResult"/> indicating success or a <see cref="ForbidResult"/> or a <see cref="NotFoundResult"/> on failure.</returns>
  243. [HttpPost("{userId}/Password")]
  244. [Authorize(Policy = Policies.DefaultAuthorization)]
  245. [ProducesResponseType(StatusCodes.Status204NoContent)]
  246. [ProducesResponseType(StatusCodes.Status403Forbidden)]
  247. [ProducesResponseType(StatusCodes.Status404NotFound)]
  248. public async Task<ActionResult> UpdateUserPassword(
  249. [FromRoute, Required] Guid userId,
  250. [FromBody] UpdateUserPassword request)
  251. {
  252. if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, userId, true))
  253. {
  254. return Forbid("User is not allowed to update the password.");
  255. }
  256. var user = _userManager.GetUserById(userId);
  257. if (user == null)
  258. {
  259. return NotFound("User not found");
  260. }
  261. if (request.ResetPassword)
  262. {
  263. await _userManager.ResetPassword(user).ConfigureAwait(false);
  264. }
  265. else
  266. {
  267. var success = await _userManager.AuthenticateUser(
  268. user.Username,
  269. request.CurrentPw,
  270. request.CurrentPw,
  271. HttpContext.GetNormalizedRemoteIp(),
  272. false).ConfigureAwait(false);
  273. if (success == null)
  274. {
  275. return Forbid("Invalid user or password entered.");
  276. }
  277. await _userManager.ChangePassword(user, request.NewPw).ConfigureAwait(false);
  278. var currentToken = _authContext.GetAuthorizationInfo(Request).Token;
  279. _sessionManager.RevokeUserTokens(user.Id, currentToken);
  280. }
  281. return NoContent();
  282. }
  283. /// <summary>
  284. /// Updates a user's easy password.
  285. /// </summary>
  286. /// <param name="userId">The user id.</param>
  287. /// <param name="request">The <see cref="UpdateUserEasyPassword"/> request.</param>
  288. /// <response code="204">Password successfully reset.</response>
  289. /// <response code="403">User is not allowed to update the password.</response>
  290. /// <response code="404">User not found.</response>
  291. /// <returns>A <see cref="NoContentResult"/> indicating success or a <see cref="ForbidResult"/> or a <see cref="NotFoundResult"/> on failure.</returns>
  292. [HttpPost("{userId}/EasyPassword")]
  293. [Authorize(Policy = Policies.DefaultAuthorization)]
  294. [ProducesResponseType(StatusCodes.Status204NoContent)]
  295. [ProducesResponseType(StatusCodes.Status403Forbidden)]
  296. [ProducesResponseType(StatusCodes.Status404NotFound)]
  297. public ActionResult UpdateUserEasyPassword(
  298. [FromRoute, Required] Guid userId,
  299. [FromBody] UpdateUserEasyPassword request)
  300. {
  301. if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, userId, true))
  302. {
  303. return Forbid("User is not allowed to update the easy password.");
  304. }
  305. var user = _userManager.GetUserById(userId);
  306. if (user == null)
  307. {
  308. return NotFound("User not found");
  309. }
  310. if (request.ResetPassword)
  311. {
  312. _userManager.ResetEasyPassword(user);
  313. }
  314. else
  315. {
  316. _userManager.ChangeEasyPassword(user, request.NewPw, request.NewPassword);
  317. }
  318. return NoContent();
  319. }
  320. /// <summary>
  321. /// Updates a user.
  322. /// </summary>
  323. /// <param name="userId">The user id.</param>
  324. /// <param name="updateUser">The updated user model.</param>
  325. /// <response code="204">User updated.</response>
  326. /// <response code="400">User information was not supplied.</response>
  327. /// <response code="403">User update forbidden.</response>
  328. /// <returns>A <see cref="NoContentResult"/> indicating success or a <see cref="BadRequestResult"/> or a <see cref="ForbidResult"/> on failure.</returns>
  329. [HttpPost("{userId}")]
  330. [Authorize(Policy = Policies.DefaultAuthorization)]
  331. [ProducesResponseType(StatusCodes.Status204NoContent)]
  332. [ProducesResponseType(StatusCodes.Status400BadRequest)]
  333. [ProducesResponseType(StatusCodes.Status403Forbidden)]
  334. public async Task<ActionResult> UpdateUser(
  335. [FromRoute, Required] Guid userId,
  336. [FromBody] UserDto updateUser)
  337. {
  338. if (updateUser == null)
  339. {
  340. return BadRequest();
  341. }
  342. if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, userId, false))
  343. {
  344. return Forbid("User update not allowed.");
  345. }
  346. var user = _userManager.GetUserById(userId);
  347. if (!string.Equals(user.Username, updateUser.Name, StringComparison.Ordinal))
  348. {
  349. await _userManager.RenameUser(user, updateUser.Name).ConfigureAwait(false);
  350. }
  351. await _userManager.UpdateConfigurationAsync(user.Id, updateUser.Configuration).ConfigureAwait(false);
  352. return NoContent();
  353. }
  354. /// <summary>
  355. /// Updates a user policy.
  356. /// </summary>
  357. /// <param name="userId">The user id.</param>
  358. /// <param name="newPolicy">The new user policy.</param>
  359. /// <response code="204">User policy updated.</response>
  360. /// <response code="400">User policy was not supplied.</response>
  361. /// <response code="403">User policy update forbidden.</response>
  362. /// <returns>A <see cref="NoContentResult"/> indicating success or a <see cref="BadRequestResult"/> or a <see cref="ForbidResult"/> on failure..</returns>
  363. [HttpPost("{userId}/Policy")]
  364. [Authorize(Policy = Policies.RequiresElevation)]
  365. [ProducesResponseType(StatusCodes.Status204NoContent)]
  366. [ProducesResponseType(StatusCodes.Status400BadRequest)]
  367. [ProducesResponseType(StatusCodes.Status403Forbidden)]
  368. public async Task<ActionResult> UpdateUserPolicy(
  369. [FromRoute, Required] Guid userId,
  370. [FromBody] UserPolicy newPolicy)
  371. {
  372. if (newPolicy == null)
  373. {
  374. return BadRequest();
  375. }
  376. var user = _userManager.GetUserById(userId);
  377. // If removing admin access
  378. if (!newPolicy.IsAdministrator && user.HasPermission(PermissionKind.IsAdministrator))
  379. {
  380. if (_userManager.Users.Count(i => i.HasPermission(PermissionKind.IsAdministrator)) == 1)
  381. {
  382. return Forbid("There must be at least one user in the system with administrative access.");
  383. }
  384. }
  385. // If disabling
  386. if (newPolicy.IsDisabled && user.HasPermission(PermissionKind.IsAdministrator))
  387. {
  388. return Forbid("Administrators cannot be disabled.");
  389. }
  390. // If disabling
  391. if (newPolicy.IsDisabled && !user.HasPermission(PermissionKind.IsDisabled))
  392. {
  393. if (_userManager.Users.Count(i => !i.HasPermission(PermissionKind.IsDisabled)) == 1)
  394. {
  395. return Forbid("There must be at least one enabled user in the system.");
  396. }
  397. var currentToken = _authContext.GetAuthorizationInfo(Request).Token;
  398. _sessionManager.RevokeUserTokens(user.Id, currentToken);
  399. }
  400. await _userManager.UpdatePolicyAsync(userId, newPolicy).ConfigureAwait(false);
  401. return NoContent();
  402. }
  403. /// <summary>
  404. /// Updates a user configuration.
  405. /// </summary>
  406. /// <param name="userId">The user id.</param>
  407. /// <param name="userConfig">The new user configuration.</param>
  408. /// <response code="204">User configuration updated.</response>
  409. /// <response code="403">User configuration update forbidden.</response>
  410. /// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
  411. [HttpPost("{userId}/Configuration")]
  412. [Authorize(Policy = Policies.DefaultAuthorization)]
  413. [ProducesResponseType(StatusCodes.Status204NoContent)]
  414. [ProducesResponseType(StatusCodes.Status403Forbidden)]
  415. public async Task<ActionResult> UpdateUserConfiguration(
  416. [FromRoute, Required] Guid userId,
  417. [FromBody] UserConfiguration userConfig)
  418. {
  419. if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, userId, false))
  420. {
  421. return Forbid("User configuration update not allowed");
  422. }
  423. await _userManager.UpdateConfigurationAsync(userId, userConfig).ConfigureAwait(false);
  424. return NoContent();
  425. }
  426. /// <summary>
  427. /// Creates a user.
  428. /// </summary>
  429. /// <param name="request">The create user by name request body.</param>
  430. /// <response code="200">User created.</response>
  431. /// <returns>An <see cref="UserDto"/> of the new user.</returns>
  432. [HttpPost("New")]
  433. [Authorize(Policy = Policies.RequiresElevation)]
  434. [ProducesResponseType(StatusCodes.Status200OK)]
  435. public async Task<ActionResult<UserDto>> CreateUserByName([FromBody] CreateUserByName request)
  436. {
  437. var newUser = await _userManager.CreateUserAsync(request.Name).ConfigureAwait(false);
  438. // no need to authenticate password for new user
  439. if (request.Password != null)
  440. {
  441. await _userManager.ChangePassword(newUser, request.Password).ConfigureAwait(false);
  442. }
  443. var result = _userManager.GetUserDto(newUser, HttpContext.GetNormalizedRemoteIp());
  444. return result;
  445. }
  446. /// <summary>
  447. /// Initiates the forgot password process for a local user.
  448. /// </summary>
  449. /// <param name="forgotPasswordRequest">The forgot password request containing the entered username.</param>
  450. /// <response code="200">Password reset process started.</response>
  451. /// <returns>A <see cref="Task"/> containing a <see cref="ForgotPasswordResult"/>.</returns>
  452. [HttpPost("ForgotPassword")]
  453. [ProducesResponseType(StatusCodes.Status200OK)]
  454. public async Task<ActionResult<ForgotPasswordResult>> ForgotPassword([FromBody, Required] ForgotPasswordDto forgotPasswordRequest)
  455. {
  456. var isLocal = HttpContext.IsLocal()
  457. || _networkManager.IsInLocalNetwork(HttpContext.GetNormalizedRemoteIp());
  458. var result = await _userManager.StartForgotPasswordProcess(forgotPasswordRequest.EnteredUsername, isLocal).ConfigureAwait(false);
  459. return result;
  460. }
  461. /// <summary>
  462. /// Redeems a forgot password pin.
  463. /// </summary>
  464. /// <param name="pin">The pin.</param>
  465. /// <response code="200">Pin reset process started.</response>
  466. /// <returns>A <see cref="Task"/> containing a <see cref="PinRedeemResult"/>.</returns>
  467. [HttpPost("ForgotPassword/Pin")]
  468. [ProducesResponseType(StatusCodes.Status200OK)]
  469. public async Task<ActionResult<PinRedeemResult>> ForgotPasswordPin([FromBody] string? pin)
  470. {
  471. var result = await _userManager.RedeemPasswordResetPin(pin).ConfigureAwait(false);
  472. return result;
  473. }
  474. private IEnumerable<UserDto> Get(bool? isHidden, bool? isDisabled, bool filterByDevice, bool filterByNetwork)
  475. {
  476. var users = _userManager.Users;
  477. if (isDisabled.HasValue)
  478. {
  479. users = users.Where(i => i.HasPermission(PermissionKind.IsDisabled) == isDisabled.Value);
  480. }
  481. if (isHidden.HasValue)
  482. {
  483. users = users.Where(i => i.HasPermission(PermissionKind.IsHidden) == isHidden.Value);
  484. }
  485. if (filterByDevice)
  486. {
  487. var deviceId = _authContext.GetAuthorizationInfo(Request).DeviceId;
  488. if (!string.IsNullOrWhiteSpace(deviceId))
  489. {
  490. users = users.Where(i => _deviceManager.CanAccessDevice(i, deviceId));
  491. }
  492. }
  493. if (filterByNetwork)
  494. {
  495. if (!_networkManager.IsInLocalNetwork(HttpContext.GetNormalizedRemoteIp()))
  496. {
  497. users = users.Where(i => i.HasPermission(PermissionKind.EnableRemoteAccess));
  498. }
  499. }
  500. var result = users
  501. .OrderBy(u => u.Username)
  502. .Select(i => _userManager.GetUserDto(i, HttpContext.GetNormalizedRemoteIp()));
  503. return result;
  504. }
  505. }
  506. }