* Added attribute filter to ensure a request is taking a minimum time to response * Added functionality to management api to send forgot password emails and verify these + do the actual reset using the token * Renamed UserKey to UserId and updated OpenApi.json * Update src/Umbraco.Core/Services/IUserService.cs Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Cleanup * Renaming param * Fixing send user username instead of email + wrong EmailTypes * Fixed issue with forgot password functionality after reusing other functionality * Rename prop * Adding docs and renaming param * Handle password validation return types * More cleanup --------- Co-authored-by: Elitsa <elm@umbraco.dk> Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com>
52 lines
2.3 KiB
C#
52 lines
2.3 KiB
C#
using System.Linq.Expressions;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Umbraco.Cms.Api.Common.Attributes;
|
|
using Umbraco.Cms.Api.Common.Filters;
|
|
using Umbraco.Cms.Api.Management.DependencyInjection;
|
|
using Umbraco.Cms.Core;
|
|
using Umbraco.Cms.Core.Security;
|
|
using Umbraco.Cms.Web.Common.Authorization;
|
|
|
|
namespace Umbraco.Cms.Api.Management.Controllers;
|
|
|
|
[Authorize(Policy = "New" + AuthorizationPolicies.BackOfficeAccess)]
|
|
[MapToApi(ManagementApiConfiguration.ApiName)]
|
|
[JsonOptionsName(Constants.JsonOptionsNames.BackOffice)]
|
|
public abstract class ManagementApiControllerBase : Controller
|
|
{
|
|
protected CreatedAtActionResult CreatedAtAction<T>(Expression<Func<T, string>> action, Guid id)
|
|
=> CreatedAtAction(action, new { id = id });
|
|
|
|
protected CreatedAtActionResult CreatedAtAction<T>(Expression<Func<T, string>> action, object routeValues)
|
|
{
|
|
if (action.Body is not ConstantExpression constantExpression)
|
|
{
|
|
throw new ArgumentException("Expression must be a constant expression.");
|
|
}
|
|
|
|
var controllerName = ManagementApiRegexes.ControllerTypeToNameRegex().Replace(typeof(T).Name, string.Empty);
|
|
var actionName = constantExpression.Value?.ToString() ?? throw new ArgumentException("Expression does not have a value.");
|
|
|
|
return base.CreatedAtAction(actionName, controllerName, routeValues, null);
|
|
}
|
|
|
|
protected CreatedAtActionResult CreatedAtAction<T>(Expression<Func<T, string>> action, string name)
|
|
{
|
|
if (action.Body is not ConstantExpression constantExpression)
|
|
{
|
|
throw new ArgumentException("Expression must be a constant expression.");
|
|
}
|
|
|
|
var controllerName = ManagementApiRegexes.ControllerTypeToNameRegex().Replace(typeof(T).Name, string.Empty);
|
|
var actionName = constantExpression.Value?.ToString() ?? throw new ArgumentException("Expression does not have a value.");
|
|
|
|
return base.CreatedAtAction(actionName, controllerName, new { name = name }, null);
|
|
}
|
|
|
|
protected static Guid CurrentUserKey(IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
|
|
{
|
|
return backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Key ?? throw new InvalidOperationException("No backoffice user found");
|
|
}
|
|
}
|