|
87 | 87 | ></v-text-field> |
88 | 88 | </v-col> |
89 | 89 | <v-col cols="4"> |
| 90 | + <div id="cloudflare-turnstile" class="d-none"></div> |
90 | 91 | <v-btn |
91 | 92 | :loading="loading" |
92 | 93 | :disabled="loading" |
@@ -294,6 +295,18 @@ import { |
294 | 295 | import { formatPhoneNumber } from '~/plugins/filters' |
295 | 296 | import { SearchMessagesRequest } from '~/models/message' |
296 | 297 |
|
| 298 | +interface Turnstile { |
| 299 | + ready(callback: () => void): void |
| 300 | + render( |
| 301 | + container: string | HTMLElement, |
| 302 | + params?: { |
| 303 | + sitekey: string |
| 304 | + callback?: (token: string) => void |
| 305 | + 'error-callback'?: ((error: string) => void) | undefined |
| 306 | + }, |
| 307 | + ): string | null | undefined |
| 308 | +} |
| 309 | +
|
297 | 310 | export default Vue.extend({ |
298 | 311 | name: 'SearchMessagesIndex', |
299 | 312 | middleware: ['auth'], |
@@ -386,6 +399,22 @@ export default Vue.extend({ |
386 | 399 | }, |
387 | 400 |
|
388 | 401 | methods: { |
| 402 | + getCaptcha(): Promise<string> { |
| 403 | + return new Promise<string>((resolve, reject) => { |
| 404 | + const turnstile = (window as any).turnstile as Turnstile |
| 405 | + turnstile.ready(() => { |
| 406 | + turnstile.render('#cloudflare-turnstile', { |
| 407 | + sitekey: this.$config.cloudflareTurnstileSiteKey, |
| 408 | + callback: (token) => { |
| 409 | + resolve(token) |
| 410 | + }, |
| 411 | + 'error-callback': (error: string) => { |
| 412 | + reject(error) |
| 413 | + }, |
| 414 | + }) |
| 415 | + }) |
| 416 | + }) |
| 417 | + }, |
389 | 418 | exportMessages() { |
390 | 419 | let csvContent = 'data:text/csv;charset=utf-8,' |
391 | 420 | csvContent += |
@@ -456,35 +485,38 @@ export default Vue.extend({ |
456 | 485 | this.options.page = 1 |
457 | 486 | } |
458 | 487 |
|
459 | | - this.$store |
460 | | - .dispatch('searchMessages', { |
461 | | - owners: this.formOwners, |
462 | | - types: this.formTypes, |
463 | | - statuses: this.formStatuses, |
464 | | - query: this.formQuery, |
465 | | - sort_by: this.options.sortBy[0], |
466 | | - sort_descending: this.options.sortDesc[0], |
467 | | - skip: (this.options.page - 1) * this.options.itemsPerPage, |
468 | | - limit: this.options.itemsPerPage, |
469 | | - } as SearchMessagesRequest) |
470 | | - .then((messages: EntitiesMessage[]) => { |
471 | | - this.messages = messages |
472 | | - this.totalMessages = |
473 | | - (this.options.page - 1) * this.options.itemsPerPage + |
474 | | - messages.length |
475 | | - if (messages.length === this.options.itemsPerPage) { |
476 | | - this.totalMessages = this.totalMessages + 1 |
477 | | - } |
478 | | - }) |
479 | | - .catch((error: AxiosError<ResponsesUnprocessableEntity>) => { |
480 | | - this.errorTitle = capitalize( |
481 | | - error.response?.data?.message ?? 'Error while searching messages', |
482 | | - ) |
483 | | - this.errorMessages = getErrorMessages(error) |
484 | | - }) |
485 | | - .finally(() => { |
486 | | - this.loading = false |
487 | | - }) |
| 488 | + this.getCaptcha().then((token: string) => { |
| 489 | + this.$store |
| 490 | + .dispatch('searchMessages', { |
| 491 | + token, |
| 492 | + owners: this.formOwners, |
| 493 | + types: this.formTypes, |
| 494 | + statuses: this.formStatuses, |
| 495 | + query: this.formQuery, |
| 496 | + sort_by: this.options.sortBy[0], |
| 497 | + sort_descending: this.options.sortDesc[0], |
| 498 | + skip: (this.options.page - 1) * this.options.itemsPerPage, |
| 499 | + limit: this.options.itemsPerPage, |
| 500 | + } as SearchMessagesRequest) |
| 501 | + .then((messages: EntitiesMessage[]) => { |
| 502 | + this.messages = messages |
| 503 | + this.totalMessages = |
| 504 | + (this.options.page - 1) * this.options.itemsPerPage + |
| 505 | + messages.length |
| 506 | + if (messages.length === this.options.itemsPerPage) { |
| 507 | + this.totalMessages = this.totalMessages + 1 |
| 508 | + } |
| 509 | + }) |
| 510 | + .catch((error: AxiosError<ResponsesUnprocessableEntity>) => { |
| 511 | + this.errorTitle = capitalize( |
| 512 | + error.response?.data?.message ?? 'Error while searching messages', |
| 513 | + ) |
| 514 | + this.errorMessages = getErrorMessages(error) |
| 515 | + }) |
| 516 | + .finally(() => { |
| 517 | + this.loading = false |
| 518 | + }) |
| 519 | + }) |
488 | 520 | }, |
489 | 521 | }, |
490 | 522 | }) |
|
0 commit comments