Apply branding to custom forms (#4697)

This commit is contained in:
d11n 2023-02-23 14:35:29 +01:00 committed by GitHub
parent 022a077726
commit d14dafc871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View File

@ -4,19 +4,13 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Form;
using BTCPayServer.Client.Models;
using BTCPayServer.Data;
using BTCPayServer.Models;
using BTCPayServer.Services.Stores;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Forms;

View File

@ -25,14 +25,16 @@ public class UIFormsController : Controller
{
private readonly FormDataService _formDataService;
private readonly IAuthorizationService _authorizationService;
private readonly StoreRepository _storeRepository;
private FormComponentProviders FormProviders { get; }
public UIFormsController(FormComponentProviders formProviders, FormDataService formDataService,
IAuthorizationService authorizationService)
StoreRepository storeRepository, IAuthorizationService authorizationService)
{
FormProviders = formProviders;
_formDataService = formDataService;
_authorizationService = authorizationService;
_storeRepository = storeRepository;
}
[HttpGet("~/stores/{storeId}/forms")]
@ -141,14 +143,14 @@ public class UIFormsController : Controller
return NotFound();
}
return GetFormView(formData);
return await GetFormView(formData);
}
ViewResult GetFormView(FormData formData, Form? form = null)
async Task<ViewResult> GetFormView(FormData formData, Form? form = null)
{
form ??= Form.Parse(formData.Config);
form.ApplyValuesFromForm(Request.Query);
var store = formData.Store;
var store = formData.Store ?? await _storeRepository.FindStore(formData.StoreId);
var storeBlob = store?.GetStoreBlob();
return View("View", new FormViewModel
@ -181,13 +183,13 @@ public class UIFormsController : Controller
}
if (!Request.HasFormContentType)
return GetFormView(formData);
return await GetFormView(formData);
var form = Form.Parse(formData.Config);
form.ApplyValuesFromForm(Request.Form);
if (!_formDataService.Validate(form, ModelState))
return GetFormView(formData, form);
return await GetFormView(formData, form);
// Create invoice after public form has been filled
var store = await storeRepository.FindStore(formData.StoreId);