From 38edbf8362aa37dce4d65f094a9f20aaeb9ba1be Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 31 Oct 2018 17:59:09 +0900 Subject: [PATCH] Improve token UX (Fix #353) --- BTCPayServer.Tests/docker-compose.yml | 2 +- BTCPayServer/BTCPayServer.csproj | 3 ++ BTCPayServer/Controllers/StoresController.cs | 54 ++++++++++++++------ BTCPayServer/Views/Stores/ListTokens.cshtml | 11 ++-- BTCPayServer/Views/Stores/ShowToken.cshtml | 29 +++++++++++ 5 files changed, 75 insertions(+), 24 deletions(-) create mode 100644 BTCPayServer/Views/Stores/ShowToken.cshtml diff --git a/BTCPayServer.Tests/docker-compose.yml b/BTCPayServer.Tests/docker-compose.yml index 8364fe01a..bb841d41e 100644 --- a/BTCPayServer.Tests/docker-compose.yml +++ b/BTCPayServer.Tests/docker-compose.yml @@ -69,7 +69,7 @@ services: nbxplorer: - image: nicolasdorier/nbxplorer:1.1.0.8 + image: nicolasdorier/nbxplorer:1.1.0.9 restart: unless-stopped ports: - "32838:32838" diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 1118b4e39..547836332 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -139,6 +139,9 @@ $(IncludeRazorContentInPack) + + $(IncludeRazorContentInPack) + $(IncludeRazorContentInPack) diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 0d1bd332a..3bd6615a5 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -570,6 +570,45 @@ namespace BTCPayServer.Controllers return View(model); } + [HttpGet] + [Route("{storeId}/tokens/{tokenId}/revoke")] + public async Task RevokeToken(string tokenId) + { + var token = await _TokenRepository.GetToken(tokenId); + if (token == null || token.StoreId != StoreData.Id) + return NotFound(); + return View("Confirm", new ConfirmModel() + { + Action = "Revoke the token", + Title = "Revoke the token", + Description = $"The access token with the label \"{token.Label}\" will be revoked, do you wish to continue?", + ButtonClass = "btn-danger" + }); + } + [HttpPost] + [Route("{storeId}/tokens/{tokenId}/revoke")] + public async Task RevokeTokenConfirm(string tokenId) + { + var token = await _TokenRepository.GetToken(tokenId); + if (token == null || + token.StoreId != StoreData.Id || + !await _TokenRepository.DeleteToken(tokenId)) + StatusMessage = "Failure to revoke this token"; + else + StatusMessage = "Token revoked"; + return RedirectToAction(nameof(ListTokens)); + } + + [HttpGet] + [Route("{storeId}/tokens/{tokenId}")] + public async Task ShowToken(string tokenId) + { + var token = await _TokenRepository.GetToken(tokenId); + if (token == null || token.StoreId != StoreData.Id) + return NotFound(); + return View(token); + } + [HttpPost] [Route("/api-tokens")] [Route("{storeId}/Tokens/Create")] @@ -671,21 +710,6 @@ namespace BTCPayServer.Controllers return View(model); } - - [HttpPost] - [Route("{storeId}/Tokens/Delete")] - public async Task DeleteToken(string tokenId) - { - var token = await _TokenRepository.GetToken(tokenId); - if (token == null || - token.StoreId != StoreData.Id || - !await _TokenRepository.DeleteToken(tokenId)) - StatusMessage = "Failure to revoke this token"; - else - StatusMessage = "Token revoked"; - return RedirectToAction(nameof(ListTokens)); - } - [HttpPost] [Route("{storeId}/tokens/apikey")] public async Task GenerateAPIKey() diff --git a/BTCPayServer/Views/Stores/ListTokens.cshtml b/BTCPayServer/Views/Stores/ListTokens.cshtml index 0da934552..a767c548c 100644 --- a/BTCPayServer/Views/Stores/ListTokens.cshtml +++ b/BTCPayServer/Views/Stores/ListTokens.cshtml @@ -18,9 +18,8 @@ Label - SIN Facade - Actions + Actions @@ -28,13 +27,9 @@ { @token.Label - @token.SIN @token.Facade - -
- - -
+ + See information - Revoke } diff --git a/BTCPayServer/Views/Stores/ShowToken.cshtml b/BTCPayServer/Views/Stores/ShowToken.cshtml new file mode 100644 index 000000000..cda7bdfdf --- /dev/null +++ b/BTCPayServer/Views/Stores/ShowToken.cshtml @@ -0,0 +1,29 @@ +@model BTCPayServer.Authentication.BitTokenEntity +@{ + Layout = "../Shared/_NavLayout.cshtml"; + ViewData.SetActivePageAndTitle(StoreNavPages.Tokens, "Access Tokens"); +} + +
+
+
Token information
+ + + + + + + + + + + + + + + + + +
Label@Model.Label
SIN@Model.SIN
Token@Model.Value
Facade@Model.Facade
+
+