2019-07-01 05:39:25 +02:00
|
|
|
using System.Threading.Tasks;
|
2020-11-17 13:46:23 +01:00
|
|
|
using BTCPayServer.Abstractions.Constants;
|
2020-03-19 19:11:15 +09:00
|
|
|
using BTCPayServer.Client;
|
2019-07-01 05:39:25 +02:00
|
|
|
using BTCPayServer.Data;
|
|
|
|
using BTCPayServer.Security;
|
|
|
|
using BTCPayServer.Services.Stores;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
2020-03-27 12:58:45 +09:00
|
|
|
namespace BTCPayServer.Controllers.GreenField
|
2019-07-01 05:39:25 +02:00
|
|
|
{
|
|
|
|
/// <summary>
|
2020-02-24 14:36:15 +01:00
|
|
|
/// this controller serves as a testing endpoint for our api key unit tests
|
2019-07-01 05:39:25 +02:00
|
|
|
/// </summary>
|
2020-02-24 14:36:15 +01:00
|
|
|
[Route("api/test/apikey")]
|
2019-07-01 05:39:25 +02:00
|
|
|
[ApiController]
|
2020-03-23 14:23:23 +01:00
|
|
|
[Authorize(AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
2020-02-24 14:36:15 +01:00
|
|
|
public class TestApiKeyController : ControllerBase
|
2019-07-01 05:39:25 +02:00
|
|
|
{
|
|
|
|
private readonly UserManager<ApplicationUser> _userManager;
|
|
|
|
private readonly StoreRepository _storeRepository;
|
|
|
|
|
2020-02-24 14:36:15 +01:00
|
|
|
public TestApiKeyController(UserManager<ApplicationUser> userManager, StoreRepository storeRepository)
|
2019-07-01 05:39:25 +02:00
|
|
|
{
|
|
|
|
_userManager = userManager;
|
|
|
|
_storeRepository = storeRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("me/id")]
|
2020-03-23 14:23:23 +01:00
|
|
|
[Authorize(Policy = Policies.CanViewProfile, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
2019-07-01 05:39:25 +02:00
|
|
|
public string GetCurrentUserId()
|
|
|
|
{
|
|
|
|
return _userManager.GetUserId(User);
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("me")]
|
2020-03-23 14:23:23 +01:00
|
|
|
[Authorize(Policy = Policies.CanViewProfile, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
2019-07-01 05:39:25 +02:00
|
|
|
public async Task<ApplicationUser> GetCurrentUser()
|
|
|
|
{
|
|
|
|
return await _userManager.GetUserAsync(User);
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("me/is-admin")]
|
2020-03-23 14:23:23 +01:00
|
|
|
[Authorize(Policy = Policies.CanModifyServerSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
2019-07-01 05:39:25 +02:00
|
|
|
public bool AmIAnAdmin()
|
2019-09-29 09:23:31 +02:00
|
|
|
{
|
2019-10-12 20:35:30 +09:00
|
|
|
return true;
|
2019-07-01 05:39:25 +02:00
|
|
|
}
|
2019-09-29 09:23:31 +02:00
|
|
|
|
2019-07-01 05:39:25 +02:00
|
|
|
[HttpGet("me/stores")]
|
2020-03-23 14:23:23 +01:00
|
|
|
[Authorize(Policy = Policies.CanViewStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
2020-03-19 19:11:15 +09:00
|
|
|
public StoreData[] GetCurrentUserStores()
|
2019-07-01 05:39:25 +02:00
|
|
|
{
|
2020-03-19 19:11:15 +09:00
|
|
|
return this.HttpContext.GetStoresData();
|
2020-02-24 14:36:15 +01:00
|
|
|
}
|
2020-03-19 19:11:15 +09:00
|
|
|
|
|
|
|
[HttpGet("me/stores/{storeId}/can-view")]
|
2020-03-20 13:41:47 +09:00
|
|
|
[Authorize(Policy = Policies.CanViewStoreSettings,
|
2020-03-23 14:23:23 +01:00
|
|
|
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
2020-03-19 19:11:15 +09:00
|
|
|
public bool CanViewStore(string storeId)
|
2020-02-24 14:36:15 +01:00
|
|
|
{
|
|
|
|
return true;
|
2019-07-01 05:39:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("me/stores/{storeId}/can-edit")]
|
2020-03-20 13:41:47 +09:00
|
|
|
[Authorize(Policy = Policies.CanModifyStoreSettings,
|
2020-03-23 14:23:23 +01:00
|
|
|
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
2020-03-19 19:11:15 +09:00
|
|
|
public bool CanEditStore(string storeId)
|
2019-07-01 05:39:25 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|