Skip to content

Commit

Permalink
APIKeys: Distinguish authorize and confirm (reuse)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisreimann committed Sep 11, 2020
1 parent 7293c7f commit c3a9d8f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
12 changes: 8 additions & 4 deletions BTCPayServer/Controllers/ManageController.APIKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,17 @@ public async Task<IActionResult> AuthorizeAPIKey([FromForm] AuthorizeApiKeysView
return View(viewModel);
}

switch (viewModel.Command.ToLowerInvariant())
var command = viewModel.Command.ToLowerInvariant();
switch (command)
{
case "no":
case "cancel":
return RedirectToAction("APIKeys");

case "yes":
var key = await CreateKey(viewModel, (viewModel.ApplicationIdentifier, viewModel.RedirectUrl?.Authority));
case "authorize":
case "confirm":
var key = command == "authorize"
? await CreateKey(viewModel, (viewModel.ApplicationIdentifier, viewModel.RedirectUrl?.Authority))
: await _apiKeyRepository.GetKey(viewModel.Key);

if (viewModel.RedirectUrl != null)
{
Expand Down
4 changes: 2 additions & 2 deletions BTCPayServer/Views/Manage/AuthorizeAPIKey.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@
</div>
<div class="row my-4">
<div class="col-lg-12 text-center">
<button class="btn btn-primary mx-2" name="command" id="consent-yes" type="submit" value="Yes">Authorize app</button>
<button class="btn btn-secondary mx-2" name="command" id="consent-no" type="submit" value="No">Cancel</button>
<button class="btn btn-primary mx-2" name="command" id="consent-yes" type="submit" value="Authorize">Authorize app</button>
<button class="btn btn-secondary mx-2" name="command" id="consent-no" type="submit" value="Cancel">Cancel</button>
</div>
</div>
</div>
Expand Down
9 changes: 5 additions & 4 deletions BTCPayServer/Views/Manage/ConfirmAPIKey.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
</div>

<form method="post" class="modal-footer justify-content-center" asp-controller="Manage" asp-action="AuthorizeAPIKey">
<input type="hidden" asp-for="ApplicationName" value="@Model.ApplicationName"/>
<input type="hidden" asp-for="ApplicationIdentifier" value="@Model.ApplicationIdentifier"/>
<input type="hidden" asp-for="Key" value="@Model.Key"/>
<input type="hidden" asp-for="Strict" value="@Model.Strict"/>
<input type="hidden" asp-for="RedirectUrl" value="@Model.RedirectUrl"/>
<input type="hidden" asp-for="Permissions" value="@Model.Permissions"/>
<input type="hidden" asp-for="Strict" value="@Model.Strict"/>
<input type="hidden" asp-for="ApplicationName" value="@Model.ApplicationName"/>
<input type="hidden" asp-for="SelectiveStores" value="@Model.SelectiveStores"/>
<input type="hidden" asp-for="ApplicationIdentifier" value="@Model.ApplicationIdentifier"/>

<button type="submit" class="btn btn-primary w-25 mx-2" id="continue" name="command" value="Yes">Confirm</button>
<button type="submit" class="btn btn-primary w-25 mx-2" id="continue" name="command" value="Confirm">Confirm</button>
<button type="submit" class="btn btn-secondary w-25 mx-2" onclick="history.back(); return false;">Go back</button>
</form>
</div>
Expand Down

0 comments on commit c3a9d8f

Please sign in to comment.