@@ -10,38 +10,51 @@ public class reCAPTCHAV3ScriptJsTagHelper : TagHelper
10
10
11
11
public string Callback { get ; set ; }
12
12
13
+ public bool Execute { get ; set ; }
14
+
13
15
private readonly reCAPTCHAOptions _options ;
14
16
15
17
public reCAPTCHAV3ScriptJsTagHelper ( IOptionsSnapshot < reCAPTCHAOptions > optionsAccessor )
16
18
{
17
19
_options = optionsAccessor . Get ( reCAPTCHAConsts . V3 ) ;
20
+ Execute = true ;
18
21
}
19
22
20
23
public override void Process ( TagHelperContext context , TagHelperOutput output )
21
24
{
22
25
/*
23
- grecaptcha.ready(function() {
24
- grecaptcha.reExecute = function(){
25
- grecaptcha.execute('_reCAPTCHA_site_key_', {action: 'homepage'}).then(function(token) {
26
- ...
27
- })();
28
- }
26
+ myCallback is a user-defined method name or `(function(t){alert(t)})` when Execute = true
27
+ grecaptcha.ready(function () {
28
+ grecaptcha.reExecute = function () {
29
+ grecaptcha.execute('6LccrsMUAAAAANSAh_MCplqdS9AJVPihyzmbPqWa', {
30
+ action: 'login'
31
+ }).then(function (token) {
32
+ myCallback(token)
33
+ })
34
+ };
35
+ grecaptcha.reExecute()
29
36
});
30
- */
31
37
38
+ myCallback is a user-defined function when Execute = false
39
+ grecaptcha.ready(function () {
40
+ grecaptcha.reExecute = function (callback) {
41
+ grecaptcha.execute('6LccrsMUAAAAANSAh_MCplqdS9AJVPihyzmbPqWa', {
42
+ action: 'login'
43
+ }).then(myCallback)
44
+ };
45
+ });
46
+ */
32
47
output . TagName = "script" ;
33
48
output . TagMode = TagMode . StartTagAndEndTag ;
34
49
35
- var script = "grecaptcha.ready(function(){ " +
36
- "grecaptcha.reExecute = function(){" +
37
- "grecaptcha.execute('" + _options . SiteKey + "'" + ( string . IsNullOrWhiteSpace ( Action ) ? "" : ",{action:'" + Action + "'}" ) + ")" +
38
- ".then(function(token){" +
39
- Callback + "(token)" +
40
- "})" +
41
- "};" +
42
- "grecaptcha.reExecute()" +
43
- "});" ;
50
+ var script =
51
+ "grecaptcha.ready(function(){ " +
52
+ "grecaptcha.reExecute = function(" + ( Execute ? "" : "callback" ) + "){" +
53
+ "grecaptcha.execute('" + _options . SiteKey + "'" + ( string . IsNullOrWhiteSpace ( Action ) ? "" : ",{action:'" + Action + "'}" ) + ")" +
54
+ ( Execute ? ( ".then(function(token){" + Callback + "(token)" + "})" ) : ".then(callback)" ) + "};" +
55
+ ( Execute ? "grecaptcha.reExecute()" : "" ) +
56
+ "});" ;
44
57
output . Content . SetHtmlContent ( script ) ;
45
58
}
46
59
}
47
- }
60
+ }
0 commit comments