From 94e9ab7f672e84e0a5d57525a304f861bd7077bc Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 18 Oct 2017 18:43:52 +0900 Subject: [PATCH] In server-initiated situation, the server can set the label --- BTCPayServer.Tests/UnitTest1.cs | 2 +- BTCPayServer/Controllers/AccessTokenController.cs | 6 ++++++ BTCPayServer/Controllers/StoresController.cs | 2 +- BTCPayServer/Models/StoreViewModels/TokensViewModel.cs | 2 +- BTCPayServer/Views/Stores/CreateToken.cshtml | 4 ++++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/BTCPayServer.Tests/UnitTest1.cs b/BTCPayServer.Tests/UnitTest1.cs index a629012fc..fe3bbcac2 100644 --- a/BTCPayServer.Tests/UnitTest1.cs +++ b/BTCPayServer.Tests/UnitTest1.cs @@ -118,7 +118,7 @@ namespace BTCPayServer.Tests var acc = tester.NewAccount(); acc.Register(); acc.CreateStore(); - + var controller = tester.PayTester.GetController(acc.UserId); var token = (RedirectToActionResult)controller.CreateToken(acc.StoreId, new Models.StoreViewModels.CreateTokenViewModel() { diff --git a/BTCPayServer/Controllers/AccessTokenController.cs b/BTCPayServer/Controllers/AccessTokenController.cs index 4e8601d92..b72c90a4c 100644 --- a/BTCPayServer/Controllers/AccessTokenController.cs +++ b/BTCPayServer/Controllers/AccessTokenController.cs @@ -58,6 +58,12 @@ namespace BTCPayServer.Controllers pairingEntity = await _TokenRepository.GetPairingAsync(request.PairingCode); pairingEntity.SIN = sin; + if(string.IsNullOrEmpty(pairingEntity.Label) && !string.IsNullOrEmpty(request.Label)) + { + pairingEntity.Label = request.Label; + await _TokenRepository.UpdatePairingCode(pairingEntity); + } + var result = await _TokenRepository.PairWithSINAsync(request.PairingCode, sin); if(result != PairingResult.Complete && result != PairingResult.Partial) throw new BitpayHttpException(400, $"Error while pairing ({result})"); diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 8827b83de..31d15eb08 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -230,7 +230,7 @@ namespace BTCPayServer.Controllers { return View(model); } - + model.Label = model.Label ?? String.Empty; if(storeId == null) // Permissions are not checked by Policy if the storeId is not passed by url { storeId = model.StoreId; diff --git a/BTCPayServer/Models/StoreViewModels/TokensViewModel.cs b/BTCPayServer/Models/StoreViewModels/TokensViewModel.cs index 8788d1ad2..f5dd739dc 100644 --- a/BTCPayServer/Models/StoreViewModels/TokensViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/TokensViewModel.cs @@ -15,7 +15,7 @@ namespace BTCPayServer.Models.StoreViewModels { get; set; } - [Required] + public string Label { get; set; diff --git a/BTCPayServer/Views/Stores/CreateToken.cshtml b/BTCPayServer/Views/Stores/CreateToken.cshtml index 46ec03af4..93a7ec8c1 100644 --- a/BTCPayServer/Views/Stores/CreateToken.cshtml +++ b/BTCPayServer/Views/Stores/CreateToken.cshtml @@ -14,6 +14,10 @@
+ @if(ViewBag.HidePublicKey) + { + optional + }