54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using Core.Enumerations;
|
|
using DomainResults.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using WeatherForecast.Models.Requests;
|
|
using WeatherForecast.Policies;
|
|
using WeatherForecast.Services;
|
|
|
|
namespace WeatherForecast.Controllers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class PasswordController : ControllerBase {
|
|
|
|
private readonly IAuthorizationService _authorizationService;
|
|
private readonly IPasswordService _passwordService;
|
|
|
|
private readonly WebapiControllers _webapiController = WebapiControllers.Password;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="passwordService"></param>
|
|
public PasswordController(
|
|
IAuthorizationService authorizationService,
|
|
IPasswordService passwordService
|
|
) {
|
|
_authorizationService = authorizationService;
|
|
_passwordService = passwordService;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="siteId"></param>
|
|
/// <param name="userId"></param>
|
|
/// <param name="requestData"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("{siteId}/{userId}")]
|
|
public async Task<IActionResult> Post([FromRoute] Guid siteId, [FromRoute] Guid userId, [FromBody] PasswordRequestModel requestData) {
|
|
if ((await _authorizationService.AuthorizeAsync(User, null, new CrudActionRequirement(_webapiController, CrudActions.Create))).Succeeded) {
|
|
var result = _passwordService.Post(siteId, userId, requestData);
|
|
return result.ToActionResult();
|
|
}
|
|
|
|
return Unauthorized();
|
|
}
|
|
}
|
|
|