validation.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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
  21. variant="elevated"
  22. prepend-icon="fas fa-arrow-left"
  23. color="secondary"
  24. to="/opentalent-artist"
  25. >
  26. Retour à la page Opentalent Artist
  27. </v-btn>
  28. </v-card-actions>
  29. </div>
  30. <div v-else class="text-center pa-8">
  31. <v-card-title class="text-center">
  32. <v-icon
  33. icon="fas fa-exclamation-triangle mr-2"
  34. color="warning"
  35. max-height="48"
  36. />
  37. Erreur de validation
  38. </v-card-title>
  39. <v-card-text class="text-center">
  40. <p class="error-message">
  41. {{ errorMsg }}
  42. </p>
  43. <p class="mt-4">
  44. Si le problème persiste, n'hésitez pas à nous contacter.
  45. </p>
  46. </v-card-text>
  47. <v-card-actions class="justify-center">
  48. <v-btn color="primary" to="/nous-contacter">Nous contacter</v-btn>
  49. </v-card-actions>
  50. </div>
  51. </v-card>
  52. </template>
  53. <script setup lang="ts">
  54. import { useRoute } from 'vue-router'
  55. import { useAp2iRequestService } from '~/composables/data/useAp2iRequestService'
  56. import { useAp2iErrorHandler } from '~/composables/utils/useAp2iErrorHandler'
  57. import UrlUtils from '~/services/utils/urlUtils'
  58. const route = useRoute()
  59. const { ap2iRequestService } = useAp2iRequestService(false)
  60. const runtimeConfig = useRuntimeConfig()
  61. const { processApiError } = useAp2iErrorHandler()
  62. const loading = ref(true)
  63. const validationSuccess: Ref<boolean | null> = ref(null)
  64. const errorMsg: Ref<string | null> = ref(null)
  65. // UUID validation regex
  66. const uuidRegex =
  67. /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
  68. // Get token from query parameters
  69. const token = computed(() => {
  70. const queryToken = route.query.token
  71. return typeof queryToken === 'string' ? queryToken : ''
  72. })
  73. const validate = async () => {
  74. try {
  75. // Check if token is present
  76. if (!token.value) {
  77. errorMsg.value = "Aucun jeton de validation n'a été fourni."
  78. return
  79. }
  80. // Validate token format (UUID)
  81. if (!uuidRegex.test(token.value)) {
  82. errorMsg.value = 'Le format du jeton de validation est invalide.'
  83. return
  84. }
  85. // Make API request to validate token
  86. await ap2iRequestService.get(
  87. UrlUtils.join(
  88. runtimeConfig.public.ap2iBaseUrl,
  89. '/api/public/shop/validate/',
  90. token.value
  91. )
  92. )
  93. // If we get here, the validation was successful
  94. validationSuccess.value = true
  95. } catch (error) {
  96. console.error('Error validating token:', error)
  97. validationSuccess.value = false
  98. errorMsg.value = processApiError(error)
  99. }
  100. }
  101. onMounted(async () => {
  102. await validate()
  103. loading.value = false
  104. })
  105. </script>
  106. <style scoped lang="scss">
  107. .v-card {
  108. margin: 4rem 20%;
  109. padding: 2rem;
  110. }
  111. .v-card-title {
  112. font-size: 1.8rem;
  113. font-weight: 700;
  114. color: var(--primary-color);
  115. }
  116. .v-card-text {
  117. font-size: 1.1rem;
  118. line-height: 1.6;
  119. p {
  120. margin-bottom: 1rem;
  121. }
  122. }
  123. .error-message {
  124. color: var(--warning-color);
  125. font-weight: 500;
  126. }
  127. </style>