2023-08-28 12:14:16 +02:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Umbraco.Cms.Api.Management.Routing;
|
|
|
|
|
using Umbraco.Cms.Core.Models.Membership;
|
|
|
|
|
using Umbraco.Cms.Core.Services.OperationStatus;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Api.Management.Controllers.Security;
|
|
|
|
|
|
|
|
|
|
[VersionedApiBackOfficeRoute("security")]
|
|
|
|
|
[ApiExplorerSettings(GroupName = "Security")]
|
|
|
|
|
public abstract class SecurityControllerBase : ManagementApiControllerBase
|
|
|
|
|
{
|
|
|
|
|
protected IActionResult UserOperationStatusResult(UserOperationStatus status, ErrorMessageResult? errorMessageResult = null) =>
|
2024-02-22 15:17:06 +01:00
|
|
|
OperationStatusResult(status, problemDetailsBuilder => status switch
|
2023-08-28 12:14:16 +02:00
|
|
|
{
|
2024-02-22 15:17:06 +01:00
|
|
|
UserOperationStatus.UserNotFound => NotFound(problemDetailsBuilder
|
2023-08-28 12:14:16 +02:00
|
|
|
.WithTitle("The user was not found")
|
|
|
|
|
.WithDetail("The specified user was not found.")
|
|
|
|
|
.Build()),
|
2024-02-22 15:17:06 +01:00
|
|
|
UserOperationStatus.InvalidPasswordResetToken => BadRequest(problemDetailsBuilder
|
2023-08-28 12:14:16 +02:00
|
|
|
.WithTitle("The password reset token was invalid")
|
|
|
|
|
.WithDetail("The specified password reset token was either used already or wrong.")
|
|
|
|
|
.Build()),
|
2024-02-22 15:17:06 +01:00
|
|
|
UserOperationStatus.UnknownFailure => BadRequest(problemDetailsBuilder
|
2023-08-28 12:14:16 +02:00
|
|
|
.WithTitle("Unknown failure")
|
|
|
|
|
.WithDetail(errorMessageResult?.Error?.ErrorMessage ?? "The error was unknown")
|
|
|
|
|
.Build()),
|
2024-02-22 15:17:06 +01:00
|
|
|
_ => StatusCode(StatusCodes.Status500InternalServerError, problemDetailsBuilder
|
2023-08-28 12:14:16 +02:00
|
|
|
.WithTitle("Unknown user operation status.")
|
|
|
|
|
.Build()),
|
2024-02-22 15:17:06 +01:00
|
|
|
});
|
2023-08-28 12:14:16 +02:00
|
|
|
}
|