allow string names for captcha field

This commit is contained in:
2026-03-10 14:26:56 +01:00
parent 21182f6539
commit 659cf6d75b
+12 -6
View File
@@ -1,14 +1,12 @@
using System.IO;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using zero.Security;
namespace zero.TagHelpers;
[HtmlTargetElement("app-captcha", Attributes = "for", TagStructure = TagStructure.NormalOrSelfClosing)]
[HtmlTargetElement("app-captcha", TagStructure = TagStructure.NormalOrSelfClosing)]
public class CaptchaTagHelper(IOptionsMonitor<CaptchaOptions> options) : TagHelper
{
[HtmlAttributeNotBound]
@@ -18,6 +16,9 @@ public class CaptchaTagHelper(IOptionsMonitor<CaptchaOptions> options) : TagHelp
[HtmlAttributeName("for")]
public ModelExpression For { get; set; }
[HtmlAttributeName("name")]
public string Name { get; set; }
[HtmlAttributeName("lang")]
public string Lang { get; set; }
@@ -32,12 +33,17 @@ public class CaptchaTagHelper(IOptionsMonitor<CaptchaOptions> options) : TagHelp
return;
}
string fullName = NameAndIdProviderCopy.GetFullHtmlFieldName(ViewContext, For.Name);
string fieldName = Name.Or("Captcha");
if (For != null)
{
fieldName = NameAndIdProviderCopy.GetFullHtmlFieldName(ViewContext, For.Name);
}
output.TagName = "cap-widget";
output.Attributes.SetAttribute("class", "cap-widget");
output.Attributes.SetAttribute("data-cap-api-endpoint", _options.Endpoint);
output.Attributes.SetAttribute("data-cap-hidden-field-name", fullName);
output.Attributes.SetAttribute("data-cap-hidden-field-name", fieldName);
string wasmFilePath =_options.Endpoint + "/cap.wasm";
string widgetFilePath =_options.Endpoint + "/cap.widget.js";