2022-06-29 19:46:41 -04:00
|
|
|
|
using Bit.Api.Models.Request;
|
2021-12-14 15:05:07 +00:00
|
|
|
|
using Bit.Api.Models.Response;
|
2017-01-10 21:39:25 -05:00
|
|
|
|
using Bit.Core.Services;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Bit.Api.Controllers;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2017-01-10 21:39:25 -05:00
|
|
|
|
[Route("settings")]
|
|
|
|
|
|
[Authorize("Application")]
|
|
|
|
|
|
public class SettingsController : Controller
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly IUserService _userService;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
|
2017-01-10 21:39:25 -05:00
|
|
|
|
public SettingsController(
|
|
|
|
|
|
IUserService userService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_userService = userService;
|
2022-08-29 16:06:55 -04:00
|
|
|
|
}
|
2017-01-10 21:39:25 -05:00
|
|
|
|
|
|
|
|
|
|
[HttpGet("domains")]
|
|
|
|
|
|
public async Task<DomainsResponseModel> GetDomains(bool excluded = true)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2017-01-24 22:46:54 -05:00
|
|
|
|
var user = await _userService.GetUserByPrincipalAsync(User);
|
|
|
|
|
|
if (user == null)
|
2017-01-10 21:39:25 -05:00
|
|
|
|
{
|
|
|
|
|
|
throw new UnauthorizedAccessException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-24 22:46:54 -05:00
|
|
|
|
var response = new DomainsResponseModel(user, excluded);
|
|
|
|
|
|
return response;
|
2017-06-02 13:17:46 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-10 21:39:25 -05:00
|
|
|
|
[HttpPut("domains")]
|
|
|
|
|
|
[HttpPost("domains")]
|
2017-08-14 13:06:44 -04:00
|
|
|
|
public async Task<DomainsResponseModel> PutDomains([FromBody] UpdateDomainsRequestModel model)
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2017-08-14 13:06:44 -04:00
|
|
|
|
var user = await _userService.GetUserByPrincipalAsync(User);
|
2020-03-27 14:36:37 -04:00
|
|
|
|
if (user == null)
|
2022-08-29 15:53:48 -04:00
|
|
|
|
{
|
2017-01-10 21:39:25 -05:00
|
|
|
|
throw new UnauthorizedAccessException();
|
2022-08-29 15:53:48 -04:00
|
|
|
|
}
|
2017-01-10 21:39:25 -05:00
|
|
|
|
|
2017-01-24 22:46:54 -05:00
|
|
|
|
await _userService.SaveUserAsync(model.ToUser(user), true);
|
2022-08-29 15:53:48 -04:00
|
|
|
|
|
2017-01-24 22:46:54 -05:00
|
|
|
|
var response = new DomainsResponseModel(user);
|
2017-01-10 21:39:25 -05:00
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|