mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
Cleanups (#4351)
This commit is contained in:
parent
887bea4328
commit
5c6db35c9b
6 changed files with 30 additions and 44 deletions
|
@ -24,7 +24,6 @@ using BTCPayServer.Services.Apps;
|
|||
using BTCPayServer.Services.Invoices;
|
||||
using BTCPayServer.Services.Invoices.Export;
|
||||
using BTCPayServer.Services.Rates;
|
||||
using BTCPayServer.Services.Stores;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -19,10 +18,8 @@ using BTCPayServer.Services.PaymentRequests;
|
|||
using BTCPayServer.Services.Rates;
|
||||
using BTCPayServer.Services.Stores;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using PaymentRequestData = BTCPayServer.Data.PaymentRequestData;
|
||||
using StoreData = BTCPayServer.Data.StoreData;
|
||||
|
@ -42,7 +39,7 @@ namespace BTCPayServer.Controllers
|
|||
private readonly InvoiceRepository _InvoiceRepository;
|
||||
private readonly StoreRepository _storeRepository;
|
||||
|
||||
public FormComponentProviders FormProviders { get; }
|
||||
private FormComponentProviders FormProviders { get; }
|
||||
|
||||
public UIPaymentRequestController(
|
||||
UIInvoiceController invoiceController,
|
||||
|
@ -207,8 +204,8 @@ namespace BTCPayServer.Controllers
|
|||
break;
|
||||
default:
|
||||
// POST case: Handle form submit
|
||||
var formData = Form.Parse(Forms.UIFormsController.GetFormData(prFormId).Config);
|
||||
formData.ApplyValuesFromForm(this.Request.Form);
|
||||
var formData = Form.Parse(UIFormsController.GetFormData(prFormId).Config);
|
||||
formData.ApplyValuesFromForm(Request.Form);
|
||||
if (FormProviders.Validate(formData, ModelState))
|
||||
{
|
||||
prBlob.FormResponse = JObject.FromObject(formData.GetValues());
|
||||
|
@ -224,13 +221,13 @@ namespace BTCPayServer.Controllers
|
|||
AspController = "UIForms",
|
||||
AspAction = "ViewPublicForm",
|
||||
RouteParameters =
|
||||
{
|
||||
{ "formId", prFormId }
|
||||
},
|
||||
{
|
||||
{ "formId", prFormId }
|
||||
},
|
||||
FormParameters =
|
||||
{
|
||||
{ "redirectUrl", Request.GetCurrentUrl() }
|
||||
}
|
||||
{
|
||||
{ "redirectUrl", Request.GetCurrentUrl() }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,40 +1,27 @@
|
|||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Abstractions.Constants;
|
||||
using BTCPayServer.Abstractions.Extensions;
|
||||
using BTCPayServer.Abstractions.Form;
|
||||
using BTCPayServer.Abstractions.Models;
|
||||
using BTCPayServer.Client;
|
||||
using BTCPayServer.Client.Models;
|
||||
using BTCPayServer.Controllers;
|
||||
using BTCPayServer.Data;
|
||||
using BTCPayServer.Data.Data;
|
||||
using BTCPayServer.Forms.Models;
|
||||
using BTCPayServer.Models;
|
||||
using BTCPayServer.Services.Stores;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace BTCPayServer.Forms;
|
||||
|
||||
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Cookie)]
|
||||
public class UIFormsController : Controller
|
||||
{
|
||||
public FormComponentProviders FormProviders { get; }
|
||||
private FormComponentProviders FormProviders { get; }
|
||||
|
||||
public UIFormsController(FormComponentProviders formProviders)
|
||||
{
|
||||
FormProviders = formProviders;
|
||||
}
|
||||
private bool IsValidRedirectUri(string? redirectUrl) =>
|
||||
!string.IsNullOrEmpty(redirectUrl) && Uri.TryCreate(redirectUrl, UriKind.RelativeOrAbsolute, out var uri) &&
|
||||
(Url.IsLocalUrl(redirectUrl) || uri.Host.Equals(Request.Host.Host.ToString()));
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpGet("~/forms/{formId}")]
|
||||
|
@ -43,6 +30,7 @@ public class UIFormsController : Controller
|
|||
{
|
||||
if (!IsValidRedirectUri(redirectUrl))
|
||||
return BadRequest();
|
||||
|
||||
FormData? formData = string.IsNullOrEmpty(formId) ? null : GetFormData(formId);
|
||||
if (formData == null)
|
||||
{
|
||||
|
@ -56,22 +44,19 @@ public class UIFormsController : Controller
|
|||
|
||||
ViewResult GetFormView(FormData formData, string? redirectUrl)
|
||||
{
|
||||
return View("View", new FormViewModel() { FormData = formData, RedirectUrl = redirectUrl });
|
||||
return View("View", new FormViewModel { FormData = formData, RedirectUrl = redirectUrl });
|
||||
}
|
||||
[AllowAnonymous]
|
||||
[HttpPost("~/forms/{formId}")]
|
||||
public IActionResult SubmitForm(
|
||||
string formId,
|
||||
string? redirectUrl,
|
||||
string? command,
|
||||
[FromServices] StoreRepository storeRepository,
|
||||
[FromServices] UIInvoiceController invoiceController)
|
||||
public IActionResult SubmitForm(string formId, string? redirectUrl, string? command)
|
||||
{
|
||||
if (!IsValidRedirectUri(redirectUrl))
|
||||
return BadRequest();
|
||||
|
||||
var formData = GetFormData(formId);
|
||||
if (formData?.Config is null)
|
||||
return NotFound();
|
||||
|
||||
if (command is not "Submit")
|
||||
return GetFormView(formData, redirectUrl);
|
||||
|
||||
|
@ -83,6 +68,7 @@ public class UIFormsController : Controller
|
|||
var form = new MultiValueDictionary<string, string>();
|
||||
foreach (var kv in Request.Form)
|
||||
form.Add(kv.Key, kv.Value);
|
||||
|
||||
// With redirect, the form comes from another entity that we need to send the data back to
|
||||
if (!string.IsNullOrEmpty(redirectUrl))
|
||||
{
|
||||
|
@ -116,4 +102,8 @@ public class UIFormsController : Controller
|
|||
};
|
||||
return form;
|
||||
}
|
||||
|
||||
private bool IsValidRedirectUri(string? redirectUrl) =>
|
||||
!string.IsNullOrEmpty(redirectUrl) && Uri.TryCreate(redirectUrl, UriKind.RelativeOrAbsolute, out var uri) &&
|
||||
(Url.IsLocalUrl(redirectUrl) || uri.Host.Equals(Request.Host.Host));
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
{
|
||||
if (FormComponentProviders.TypeToComponentProvider.TryGetValue(field.Type, out var partial))
|
||||
{
|
||||
<partial name="@partial.View" for="@field"></partial>
|
||||
<partial name="@partial.View" for="@field"></partial>
|
||||
}
|
||||
}
|
||||
</fieldset>
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
@foreach (var field in Model.Fields)
|
||||
{
|
||||
if (FormComponentProviders.TypeToComponentProvider.TryGetValue(field.Type, out var partial))
|
||||
{
|
||||
<partial name="@partial.View" for="@field"></partial>
|
||||
}
|
||||
if (FormComponentProviders.TypeToComponentProvider.TryGetValue(field.Type, out var partial))
|
||||
{
|
||||
<partial name="@partial.View" for="@field"></partial>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,7 +416,7 @@
|
|||
<h3 class="mb-3 mt-4">Webhooks</h3>
|
||||
<div class="table-responsive-xl">
|
||||
<table class="table table-hover table-responsive-md mb-5">
|
||||
<thead class="thead-inverse">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Status</th>
|
||||
<th>ID</th>
|
||||
|
@ -491,7 +491,7 @@
|
|||
<h3 class="mb-3 mt-4">Refunds</h3>
|
||||
<div class="table-responsive-xl">
|
||||
<table class="table table-hover table-responsive-md mb-5">
|
||||
<thead class="thead-inverse">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Pull Payment</th>
|
||||
<th>Amount</th>
|
||||
|
@ -526,9 +526,9 @@
|
|||
</table>
|
||||
</div>
|
||||
}
|
||||
<h3 class="mb-0">Events</h3>
|
||||
<table class="table table-hover">
|
||||
<thead class="thead-inverse">
|
||||
<h3 class="mb-0 mt-5">Events</h3>
|
||||
<table class="table table-hover mt-3 mb-4">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Message</th>
|
||||
|
|
Loading…
Add table
Reference in a new issue