Fix error HTTP 500 happening on Point of Sale (Fix: #4355) (#4368)

This commit is contained in:
Nicolas Dorier 2022-11-28 20:50:09 +09:00 committed by GitHub
parent 08b239e87a
commit c0cec4716e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 13 deletions

View file

@ -194,17 +194,17 @@ namespace BTCPayServer.Controllers
var prBlob = result.GetBlob(); var prBlob = result.GetBlob();
var prFormId = prBlob.FormId; var prFormId = prBlob.FormId;
switch (prFormId) var formConfig = prFormId is null ? null : Forms.UIFormsController.GetFormData(prFormId)?.Config;
switch (formConfig)
{ {
case null: case null:
case { } when string.IsNullOrEmpty(prFormId): case { } when !this.Request.HasFormContentType && prBlob.FormResponse is not null:
case { } when Request.Method == "GET" && prBlob.FormResponse is not null:
return RedirectToAction("ViewPaymentRequest", new { payReqId }); return RedirectToAction("ViewPaymentRequest", new { payReqId });
case { } when Request.Method == "GET" && prBlob.FormResponse is null: case { } when !this.Request.HasFormContentType && prBlob.FormResponse is null:
break; break;
default: default:
// POST case: Handle form submit // POST case: Handle form submit
var formData = Form.Parse(UIFormsController.GetFormData(prFormId).Config); var formData = Form.Parse(formConfig);
formData.ApplyValuesFromForm(Request.Form); formData.ApplyValuesFromForm(Request.Form);
if (FormProviders.Validate(formData, ModelState)) if (FormProviders.Validate(formData, ModelState))
{ {

View file

@ -57,7 +57,7 @@ public class UIFormsController : Controller
if (formData?.Config is null) if (formData?.Config is null)
return NotFound(); return NotFound();
if (command is not "Submit") if (!Request.HasFormContentType)
return GetFormView(formData, redirectUrl); return GetFormView(formData, redirectUrl);
var conf = Form.Parse(formData.Config); var conf = Form.Parse(formData.Config);

View file

@ -225,16 +225,16 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers
var store = await _appService.GetStore(app); var store = await _appService.GetStore(app);
var posFormId = settings.FormId; var posFormId = settings.FormId;
var formConfig = posFormId is null ? null : Forms.UIFormsController.GetFormData(posFormId)?.Config;
JObject formResponse = null; JObject formResponse = null;
switch (posFormId) switch (formConfig)
{ {
case null: case null:
case { } when string.IsNullOrEmpty(posFormId): case { } when !this.Request.HasFormContentType:
break; break;
default: default:
// POST case: Handle form submit var formData = Form.Parse(formConfig);
var formData = Form.Parse(Forms.UIFormsController.GetFormData(posFormId).Config);
formData.ApplyValuesFromForm(this.Request.Form); formData.ApplyValuesFromForm(this.Request.Form);
if (FormProviders.Validate(formData, ModelState)) if (FormProviders.Validate(formData, ModelState))

View file

@ -36,5 +36,5 @@ public static class CheckoutFormSelectList
typeof(GenericFormOption).DisplayName(opt.ToString()); typeof(GenericFormOption).DisplayName(opt.ToString());
private static SelectListItem GenericOptionItem(GenericFormOption opt) => private static SelectListItem GenericOptionItem(GenericFormOption opt) =>
new() { Text = DisplayName(opt), Value = opt.ToString() }; new() { Text = DisplayName(opt), Value = opt == GenericFormOption.None ? null : opt.ToString() };
} }