mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-06 21:24:10 +00:00
Fix turnstile reload after auth tab switch
This commit is contained in:
parent
ae08f4a50f
commit
8a43a516ac
2 changed files with 45 additions and 1 deletions
|
|
@ -150,6 +150,7 @@
|
|||
<script>
|
||||
var turnstileToken = '';
|
||||
var turnstileWidgetId = null;
|
||||
var turnstileContainer = null;
|
||||
|
||||
const app = new Vue({
|
||||
delimiters: ['[[', ']]'],
|
||||
|
|
@ -231,7 +232,7 @@
|
|||
this.loadingStates.registerSpinning = false;
|
||||
},
|
||||
ensureTurnstileRendered(retries = 20) {
|
||||
if (!this.turnstileSiteKey || turnstileWidgetId !== null) {
|
||||
if (!this.turnstileSiteKey) {
|
||||
return;
|
||||
}
|
||||
var container = document.getElementById('turnstile-widget');
|
||||
|
|
@ -241,9 +242,24 @@
|
|||
}
|
||||
return;
|
||||
}
|
||||
if (
|
||||
turnstileWidgetId !== null &&
|
||||
(turnstileContainer !== container || container.childElementCount === 0)
|
||||
) {
|
||||
turnstile.remove(turnstileWidgetId);
|
||||
turnstileWidgetId = null;
|
||||
turnstileContainer = null;
|
||||
turnstileToken = '';
|
||||
}
|
||||
if (turnstileWidgetId !== null) {
|
||||
return;
|
||||
}
|
||||
turnstileContainer = container;
|
||||
turnstileWidgetId = turnstile.render(container, {
|
||||
sitekey: this.turnstileSiteKey,
|
||||
callback: function(token) { turnstileToken = token; },
|
||||
'expired-callback': function() { turnstileToken = ''; },
|
||||
'error-callback': function() { turnstileToken = ''; },
|
||||
size: this.turnstileSize,
|
||||
});
|
||||
},
|
||||
|
|
|
|||
28
web/login_template_test.go
Normal file
28
web/login_template_test.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoginTemplateRebuildsTurnstileAfterTabSwitch(t *testing.T) {
|
||||
content, err := htmlFS.ReadFile("html/login.html")
|
||||
if err != nil {
|
||||
t.Fatalf("read login template: %v", err)
|
||||
}
|
||||
|
||||
source := string(content)
|
||||
|
||||
checks := []string{
|
||||
"turnstileContainer = null;",
|
||||
"turnstile.remove(turnstileWidgetId);",
|
||||
"turnstileContainer !== container",
|
||||
"turnstileToken = '';",
|
||||
}
|
||||
|
||||
for _, check := range checks {
|
||||
if !strings.Contains(source, check) {
|
||||
t.Fatalf("expected login template to contain %q so turnstile can be rebuilt after tab switches", check)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue