File size: 9,059 Bytes
f1a0148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Verification Required - TTS Arena</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <script src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit" async defer></script>
    <style>
        :root {
            --primary-color: #5046e5;
            --secondary-color: #f0f0f0;
            --text-color: #333;
            --light-gray: #f5f5f5;
            --border-color: #e0e0e0;
            --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            --radius: 8px;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Inter', sans-serif;
        }

        body {
            color: var(--text-color);
            display: flex;
            min-height: 100vh;
            justify-content: center;
            align-items: center;
            background-color: var(--light-gray);
        }

        .verification-container {
            background-color: white;
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            padding: 32px;
            width: 100%;
            max-width: 450px;
            text-align: center;
        }

        .logo {
            font-size: 24px;
            font-weight: 700;
            margin-bottom: 24px;
            color: var(--primary-color);
        }

        h1 {
            font-size: 20px;
            margin-bottom: 16px;
            color: var(--text-color);
        }

        p {
            margin-bottom: 24px;
            color: #666;
            line-height: 1.5;
        }

        .turnstile-container {
            display: flex;
            justify-content: center;
            margin-bottom: 24px;
        }

        .btn {
            background-color: var(--primary-color);
            color: white;
            border: none;
            border-radius: var(--radius);
            padding: 12px 24px;
            font-weight: 500;
            cursor: pointer;
            font-size: 1rem;
            transition: background-color 0.2s;
            width: 100%;
        }

        .btn:hover {
            background-color: #4038c7;
        }

        .btn:disabled {
            background-color: #a8a4e0;
            cursor: not-allowed;
        }

        .loader {
            display: none;
            width: 24px;
            height: 24px;
            border: 3px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s ease infinite;
            margin: 0 auto;
        }

        @keyframes spin {
            to {
                transform: rotate(360deg);
            }
        }

        .btn.loading .btn-text {
            display: none;
            font-size: 1rem;
        }

        .btn.loading .loader {
            display: inline-block;
        }

        .status-message {
            margin-top: 16px;
            font-size: 14px;
            color: #666;
            display: none;
        }

        /* Dark mode styles */
        @media (prefers-color-scheme: dark) {
            :root {
                --primary-color: #6c63ff;
                --secondary-color: #2d2b38;
                --text-color: #e0e0e0;
                --light-gray: #1e1e24;
                --border-color: #3a3a45;
                --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
            }
            
            body {
                background-color: #121218;
            }
            
            .verification-container {
                background-color: var(--light-gray);
                border: 1px solid var(--border-color);
            }
            
            p {
                color: #aaa;
            }

            .status-message {
                color: #aaa;
            }
        }
    </style>
</head>
<body>
    <div class="verification-container">
        <div class="logo">TTS Arena</div>
        <h1>Verification Required</h1>
        <p>Please complete the verification below to access TTS Arena.</p>
        
        <div id="turnstile-form">
            <div class="turnstile-container">
                <div id="cf-turnstile" class="cf-turnstile"></div>
            </div>
            <button type="button" class="btn" id="submit-btn" disabled onclick="submitVerification()">
                <span class="btn-text">Continue to TTS Arena</span>
                <span class="loader"></span>
            </button>
            <div id="status-message" class="status-message"></div>
        </div>
    </div>

    <script>
        // Store the token and redirect URL
        let turnstileToken = '';
        const redirectUrl = '{{ redirect_url }}';
        // Make sure the redirect URL uses HTTPS for HuggingFace Spaces
        const secureRedirectUrl = redirectUrl.replace(/^http:\/\//i, 'https://');
        const verifyEndpoint = '{{ url_for("verify_turnstile") }}';
        const statusMessage = document.getElementById('status-message');
        const submitButton = document.getElementById('submit-btn');

        // Function to enable the button when verification is successful
        function onTurnstileSuccess(token) {
            turnstileToken = token;
            submitButton.disabled = false;
            console.log("Turnstile verification successful");
        }

        // Function to handle verification errors
        function onTurnstileError(error) {
            console.error("Turnstile error:", error);
            statusMessage.textContent = "Verification error. Please try again.";
            statusMessage.style.display = "block";
        }

        // Function to submit the verification via AJAX to handle iframe issues
        function submitVerification() {
            if (!turnstileToken) {
                statusMessage.textContent = "Please complete the verification first.";
                statusMessage.style.display = "block";
                return;
            }

            // Show loading state
            submitButton.classList.add('loading');
            submitButton.disabled = true;
            
            // Create form data
            const formData = new FormData();
            formData.append('cf-turnstile-response', turnstileToken);
            formData.append('redirect_url', secureRedirectUrl);
            
            // Send verification request
            fetch(verifyEndpoint, {
                method: 'POST',
                body: formData,
                credentials: 'same-origin', // Important for cookies
                headers: {
                    'X-Requested-With': 'XMLHttpRequest',
                    'Accept': 'application/json'
                }
            })
            .then(response => {
                if (response.redirected) {
                    // Handle redirect from the response
                    window.location.href = response.url;
                } else {
                    return response.json().then(data => {
                        if (data.success) {
                            // If we got a JSON success response, redirect
                            window.location.href = secureRedirectUrl;
                        } else {
                            throw new Error("Verification failed");
                        }
                    });
                }
            })
            .catch(error => {
                console.error("Verification error:", error);
                statusMessage.textContent = "Verification failed. Please try again.";
                statusMessage.style.display = "block";
                submitButton.classList.remove('loading');
                submitButton.disabled = false;
                
                // Reset Turnstile if something goes wrong
                if (typeof turnstile !== 'undefined') {
                    turnstile.reset('#cf-turnstile');
                }
            });
        }

        // Initialize Turnstile when the page is loaded
        document.addEventListener('DOMContentLoaded', function() {
            // Check for Turnstile script readiness
            function waitForTurnstile() {
                if (typeof turnstile !== 'undefined') {
                    // Render the Turnstile widget
                    turnstile.render('#cf-turnstile', {
                        sitekey: '{{ turnstile_site_key }}',
                        callback: onTurnstileSuccess,
                        'error-callback': onTurnstileError
                    });
                } else {
                    // If not ready yet, wait and try again
                    setTimeout(waitForTurnstile, 100);
                }
            }
            
            waitForTurnstile();
        });
    </script>
</body>
</html>