mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-06-03 21:54:26 -04:00
Add request body models
This commit is contained in:
parent
762eeb51e6
commit
77bea56708
@ -111,8 +111,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
/// <response code="404">User not found.</response>
|
/// <response code="404">User not found.</response>
|
||||||
/// <returns>An <see cref="UserDto"/> with information about the user or a <see cref="NotFoundResult"/> if the user was not found.</returns>
|
/// <returns>An <see cref="UserDto"/> with information about the user or a <see cref="NotFoundResult"/> if the user was not found.</returns>
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
// TODO: authorize escapeParentalControl
|
[Authorize(Policy = Policies.IgnoreSchedule)]
|
||||||
[Authorize]
|
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public ActionResult<UserDto> GetUserById([FromRoute] Guid id)
|
public ActionResult<UserDto> GetUserById([FromRoute] Guid id)
|
||||||
@ -185,7 +184,13 @@ namespace Jellyfin.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Password should always be null
|
// Password should always be null
|
||||||
return await AuthenticateUserByName(user.Username, pw, password).ConfigureAwait(false);
|
AuthenticateUserByName request = new AuthenticateUserByName
|
||||||
|
{
|
||||||
|
Username = user.Username,
|
||||||
|
Password = null,
|
||||||
|
Pw = pw
|
||||||
|
};
|
||||||
|
return await AuthenticateUserByName(request).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -227,10 +232,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
/// Updates a user's password.
|
/// Updates a user's password.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">The user id.</param>
|
/// <param name="id">The user id.</param>
|
||||||
/// <param name="currentPassword">The current password sha1-hash.</param>
|
/// <param name="request">The <see cref="UpdateUserPassword"/> request.</param>
|
||||||
/// <param name="currentPw">The current password as plain text.</param>
|
|
||||||
/// <param name="newPw">The new password in plain text.</param>
|
|
||||||
/// <param name="resetPassword">Whether to reset the password.</param>
|
|
||||||
/// <response code="200">Password successfully reset.</response>
|
/// <response code="200">Password successfully reset.</response>
|
||||||
/// <response code="403">User is not allowed to update the password.</response>
|
/// <response code="403">User is not allowed to update the password.</response>
|
||||||
/// <response code="404">User not found.</response>
|
/// <response code="404">User not found.</response>
|
||||||
@ -242,10 +244,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public async Task<ActionResult> UpdateUserPassword(
|
public async Task<ActionResult> UpdateUserPassword(
|
||||||
[FromRoute] Guid id,
|
[FromRoute] Guid id,
|
||||||
[FromBody] string currentPassword,
|
[FromBody] UpdateUserPassword request)
|
||||||
[FromBody] string currentPw,
|
|
||||||
[FromBody] string newPw,
|
|
||||||
[FromBody] bool resetPassword)
|
|
||||||
{
|
{
|
||||||
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, id, true))
|
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, id, true))
|
||||||
{
|
{
|
||||||
@ -259,7 +258,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
return NotFound("User not found");
|
return NotFound("User not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resetPassword)
|
if (request.ResetPassword)
|
||||||
{
|
{
|
||||||
await _userManager.ResetPassword(user).ConfigureAwait(false);
|
await _userManager.ResetPassword(user).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@ -267,8 +266,8 @@ namespace Jellyfin.Api.Controllers
|
|||||||
{
|
{
|
||||||
var success = await _userManager.AuthenticateUser(
|
var success = await _userManager.AuthenticateUser(
|
||||||
user.Username,
|
user.Username,
|
||||||
currentPw,
|
request.CurrentPw,
|
||||||
currentPassword,
|
request.CurrentPw,
|
||||||
HttpContext.Connection.RemoteIpAddress.ToString(),
|
HttpContext.Connection.RemoteIpAddress.ToString(),
|
||||||
false).ConfigureAwait(false);
|
false).ConfigureAwait(false);
|
||||||
|
|
||||||
@ -277,7 +276,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
return Forbid("Invalid user or password entered.");
|
return Forbid("Invalid user or password entered.");
|
||||||
}
|
}
|
||||||
|
|
||||||
await _userManager.ChangePassword(user, newPw).ConfigureAwait(false);
|
await _userManager.ChangePassword(user, request.NewPw).ConfigureAwait(false);
|
||||||
|
|
||||||
var currentToken = _authContext.GetAuthorizationInfo(Request).Token;
|
var currentToken = _authContext.GetAuthorizationInfo(Request).Token;
|
||||||
|
|
||||||
@ -291,9 +290,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
/// Updates a user's easy password.
|
/// Updates a user's easy password.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">The user id.</param>
|
/// <param name="id">The user id.</param>
|
||||||
/// <param name="newPassword">The new password sha1-hash.</param>
|
/// <param name="request">The <see cref="UpdateUserEasyPassword"/> request.</param>
|
||||||
/// <param name="newPw">The new password in plain text.</param>
|
|
||||||
/// <param name="resetPassword">Whether to reset the password.</param>
|
|
||||||
/// <response code="200">Password successfully reset.</response>
|
/// <response code="200">Password successfully reset.</response>
|
||||||
/// <response code="403">User is not allowed to update the password.</response>
|
/// <response code="403">User is not allowed to update the password.</response>
|
||||||
/// <response code="404">User not found.</response>
|
/// <response code="404">User not found.</response>
|
||||||
@ -305,9 +302,7 @@ namespace Jellyfin.Api.Controllers
|
|||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public ActionResult UpdateUserEasyPassword(
|
public ActionResult UpdateUserEasyPassword(
|
||||||
[FromRoute] Guid id,
|
[FromRoute] Guid id,
|
||||||
[FromBody] string newPassword,
|
[FromBody] UpdateUserEasyPassword request)
|
||||||
[FromBody] string newPw,
|
|
||||||
[FromBody] bool resetPassword)
|
|
||||||
{
|
{
|
||||||
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, id, true))
|
if (!RequestHelpers.AssertCanUpdateUser(_authContext, HttpContext.Request, id, true))
|
||||||
{
|
{
|
||||||
@ -321,13 +316,13 @@ namespace Jellyfin.Api.Controllers
|
|||||||
return NotFound("User not found");
|
return NotFound("User not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resetPassword)
|
if (request.ResetPassword)
|
||||||
{
|
{
|
||||||
_userManager.ResetEasyPassword(user);
|
_userManager.ResetEasyPassword(user);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_userManager.ChangeEasyPassword(user, newPw, newPassword);
|
_userManager.ChangeEasyPassword(user, request.NewPw, request.NewPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
@ -463,23 +458,20 @@ namespace Jellyfin.Api.Controllers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a user.
|
/// Creates a user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The username.</param>
|
/// <param name="request">The create user by name request body.</param>
|
||||||
/// <param name="password">The password.</param>
|
|
||||||
/// <response code="200">User created.</response>
|
/// <response code="200">User created.</response>
|
||||||
/// <returns>An <see cref="UserDto"/> of the new user.</returns>
|
/// <returns>An <see cref="UserDto"/> of the new user.</returns>
|
||||||
[HttpPost("/Users/New")]
|
[HttpPost("/Users/New")]
|
||||||
[Authorize(Policy = Policies.RequiresElevation)]
|
[Authorize(Policy = Policies.RequiresElevation)]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
public async Task<ActionResult<UserDto>> CreateUserByName(
|
public async Task<ActionResult<UserDto>> CreateUserByName([FromBody] CreateUserByName request)
|
||||||
[FromBody] string name,
|
|
||||||
[FromBody] string password)
|
|
||||||
{
|
{
|
||||||
var newUser = _userManager.CreateUser(name);
|
var newUser = _userManager.CreateUser(request.Name);
|
||||||
|
|
||||||
// no need to authenticate password for new user
|
// no need to authenticate password for new user
|
||||||
if (password != null)
|
if (request.Password != null)
|
||||||
{
|
{
|
||||||
await _userManager.ChangePassword(newUser, password).ConfigureAwait(false);
|
await _userManager.ChangePassword(newUser, request.Password).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = _userManager.GetUserDto(newUser, HttpContext.Connection.RemoteIpAddress.ToString());
|
var result = _userManager.GetUserDto(newUser, HttpContext.Connection.RemoteIpAddress.ToString());
|
||||||
|
@ -1,9 +1,23 @@
|
|||||||
namespace Jellyfin.Api.Models.UserDtos
|
namespace Jellyfin.Api.Models.UserDtos
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The authenticate user by name request body.
|
||||||
|
/// </summary>
|
||||||
public class AuthenticateUserByName
|
public class AuthenticateUserByName
|
||||||
{
|
{
|
||||||
public string Username { get; set; }
|
/// <summary>
|
||||||
public string Pw { get; set; }
|
/// Gets or sets the username.
|
||||||
public string Password { get; set; }
|
/// </summary>
|
||||||
|
public string? Username { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the plain text password.
|
||||||
|
/// </summary>
|
||||||
|
public string? Pw { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the sha1-hashed password.
|
||||||
|
/// </summary>
|
||||||
|
public string? Password { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
Jellyfin.Api/Models/UserDtos/CreateUserByName.cs
Normal file
18
Jellyfin.Api/Models/UserDtos/CreateUserByName.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
namespace Jellyfin.Api.Models.UserDtos
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The create user by name request body.
|
||||||
|
/// </summary>
|
||||||
|
public class CreateUserByName
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the username.
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the password.
|
||||||
|
/// </summary>
|
||||||
|
public string? Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
23
Jellyfin.Api/Models/UserDtos/UpdateUserEasyPassword.cs
Normal file
23
Jellyfin.Api/Models/UserDtos/UpdateUserEasyPassword.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
namespace Jellyfin.Api.Models.UserDtos
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The update user easy password request body.
|
||||||
|
/// </summary>
|
||||||
|
public class UpdateUserEasyPassword
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the new sha1-hashed password.
|
||||||
|
/// </summary>
|
||||||
|
public string? NewPassword { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the new password.
|
||||||
|
/// </summary>
|
||||||
|
public string? NewPw { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether to reset the password.
|
||||||
|
/// </summary>
|
||||||
|
public bool ResetPassword { get; set; }
|
||||||
|
}
|
||||||
|
}
|
28
Jellyfin.Api/Models/UserDtos/UpdateUserPassword.cs
Normal file
28
Jellyfin.Api/Models/UserDtos/UpdateUserPassword.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
namespace Jellyfin.Api.Models.UserDtos
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The update user password request body.
|
||||||
|
/// </summary>
|
||||||
|
public class UpdateUserPassword
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the current sha1-hashed password.
|
||||||
|
/// </summary>
|
||||||
|
public string? CurrentPassword { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the current plain text password.
|
||||||
|
/// </summary>
|
||||||
|
public string? CurrentPw { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the new plain text password.
|
||||||
|
/// </summary>
|
||||||
|
public string? NewPw { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether to reset the password.
|
||||||
|
/// </summary>
|
||||||
|
public bool ResetPassword { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user