mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 02:28:31 +01:00
74 lines
2.5 KiB
C#
74 lines
2.5 KiB
C#
using System.Threading.Tasks;
|
|
using BTCPayServer.Client;
|
|
using BTCPayServer.Data;
|
|
using BTCPayServer.Security;
|
|
using BTCPayServer.Services.Stores;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace BTCPayServer.Controllers.GreenField
|
|
{
|
|
/// <summary>
|
|
/// this controller serves as a testing endpoint for our api key unit tests
|
|
/// </summary>
|
|
[Route("api/test/apikey")]
|
|
[ApiController]
|
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
public class TestApiKeyController : ControllerBase
|
|
{
|
|
private readonly UserManager<ApplicationUser> _userManager;
|
|
private readonly StoreRepository _storeRepository;
|
|
|
|
public TestApiKeyController(UserManager<ApplicationUser> userManager, StoreRepository storeRepository)
|
|
{
|
|
_userManager = userManager;
|
|
_storeRepository = storeRepository;
|
|
}
|
|
|
|
[HttpGet("me/id")]
|
|
[Authorize(Policy = Policies.CanViewProfile, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
public string GetCurrentUserId()
|
|
{
|
|
return _userManager.GetUserId(User);
|
|
}
|
|
|
|
[HttpGet("me")]
|
|
[Authorize(Policy = Policies.CanViewProfile, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
public async Task<ApplicationUser> GetCurrentUser()
|
|
{
|
|
return await _userManager.GetUserAsync(User);
|
|
}
|
|
|
|
[HttpGet("me/is-admin")]
|
|
[Authorize(Policy = Policies.CanModifyServerSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
public bool AmIAnAdmin()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
[HttpGet("me/stores")]
|
|
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
public StoreData[] GetCurrentUserStores()
|
|
{
|
|
return this.HttpContext.GetStoresData();
|
|
}
|
|
|
|
[HttpGet("me/stores/{storeId}/can-view")]
|
|
[Authorize(Policy = Policies.CanViewStoreSettings,
|
|
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
public bool CanViewStore(string storeId)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
[HttpGet("me/stores/{storeId}/can-edit")]
|
|
[Authorize(Policy = Policies.CanModifyStoreSettings,
|
|
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
|
public bool CanEditStore(string storeId)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|