validation.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <v-card>
  3. <div v-if="loading" class="text-center pa-8">
  4. <v-progress-circular indeterminate color="primary" />
  5. <p class="mt-4">Validation en cours...</p>
  6. </div>
  7. <div v-else-if="validationSuccess">
  8. <v-card-title class="text-center">
  9. <v-icon icon="fas fa-check mr-2" color="success" max-height="48" />
  10. Félicitations !
  11. </v-card-title>
  12. <v-card-text class="text-center">
  13. <p>Merci d'avoir validé votre demande.</p>
  14. <p>Votre compte est en cours de création.</p>
  15. <p>
  16. Vous recevrez un email dès que votre compte sera prêt à être utilisé.
  17. </p>
  18. </v-card-text>
  19. <v-card-actions class="justify-center">
  20. <v-btn color="primary" to="/opentalent-artist">
  21. Retour à la page Opentalent Artist
  22. </v-btn>
  23. </v-card-actions>
  24. </div>
  25. <div v-else class="text-center pa-8">
  26. <v-card-title class="text-center">
  27. <v-icon
  28. icon="fas fa-exclamation-triangle mr-2"
  29. color="warning"
  30. max-height="48"
  31. />
  32. Erreur de validation
  33. </v-card-title>
  34. <v-card-text class="text-center">
  35. <p class="error-message">
  36. {{ errorMsg }}
  37. </p>
  38. <p class="mt-4">
  39. Si le problème persiste, n'hésitez pas à nous contacter.
  40. </p>
  41. </v-card-text>
  42. <v-card-actions class="justify-center">
  43. <v-btn color="primary" to="/nous-contacter">Nous contacter</v-btn>
  44. </v-card-actions>
  45. </div>
  46. </v-card>
  47. </template>
  48. <script setup lang="ts">
  49. import { useRoute } from 'vue-router'
  50. import { useNuxtApp } from '#app'
  51. import { useAp2iRequestService } from '~/composables/data/useAp2iRequestService'
  52. const route = useRoute()
  53. const { ap2iRequestService } = useAp2iRequestService()
  54. const loading = ref(true)
  55. const validationSuccess = ref(false)
  56. const errorMsg = ref(
  57. "Une erreur s'est produite lors de la validation de votre demande."
  58. )
  59. // UUID validation regex
  60. const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
  61. // Get token from query parameters
  62. const token = computed(() => {
  63. const queryToken = route.query.token
  64. return typeof queryToken === 'string' ? queryToken : ''
  65. })
  66. // Validate token and make API request
  67. onMounted(async () => {
  68. try {
  69. // Check if token is present
  70. if (!token.value) {
  71. errorMsg.value = "Aucun jeton de validation n'a été fourni."
  72. loading.value = false
  73. return
  74. }
  75. // Validate token format (UUID)
  76. if (!uuidRegex.test(token.value)) {
  77. errorMsg.value = 'Le format du jeton de validation est invalide.'
  78. loading.value = false
  79. return
  80. }
  81. // Make API request to validate token
  82. await ap2iRequestService.get('/api/public/shop/validate/' + token.value)
  83. // If we get here, the validation was successful
  84. validationSuccess.value = true
  85. loading.value = false
  86. } catch (error) {
  87. console.error('Error validating token:', error)
  88. // Try to extract the specific error message from the API response
  89. if (
  90. error &&
  91. typeof error === 'object' &&
  92. 'data' in error &&
  93. error.data &&
  94. typeof error.data === 'object'
  95. ) {
  96. const errorData = error.data as { detail?: string }
  97. if (errorData.detail) {
  98. const { $i18n } = useNuxtApp()
  99. // Use translation if available, otherwise use the original message
  100. errorMsg.value = $i18n.t(errorData.detail) || errorData.detail
  101. }
  102. }
  103. loading.value = false
  104. }
  105. })
  106. </script>
  107. <style scoped lang="scss">
  108. .v-card {
  109. margin: 4rem 20%;
  110. padding: 2rem;
  111. }
  112. .v-card-title {
  113. font-size: 1.8rem;
  114. font-weight: 700;
  115. color: var(--primary-color);
  116. }
  117. .v-card-text {
  118. font-size: 1.1rem;
  119. line-height: 1.6;
  120. p {
  121. margin-bottom: 1rem;
  122. }
  123. }
  124. .error-message {
  125. color: var(--warning-color);
  126. font-weight: 500;
  127. }
  128. </style>