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