validation.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 { useAp2iRequestService } from '~/composables/data/useAp2iRequestService'
  51. import { useAp2iErrorHandler } from '~/composables/utils/useAp2iErrorHandler'
  52. import UrlUtils from '~/services/utils/urlUtils'
  53. const route = useRoute()
  54. const { ap2iRequestService } = useAp2iRequestService(false)
  55. const runtimeConfig = useRuntimeConfig()
  56. const { processApiError } = useAp2iErrorHandler()
  57. const loading = ref(true)
  58. const validationSuccess: Ref<boolean | null> = ref(null)
  59. const errorMsg: Ref<string | null> = ref(null)
  60. // UUID validation regex
  61. const uuidRegex =
  62. /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
  63. // Get token from query parameters
  64. const token = computed(() => {
  65. const queryToken = route.query.token
  66. return typeof queryToken === 'string' ? queryToken : ''
  67. })
  68. const validate = async () => {
  69. try {
  70. // Check if token is present
  71. if (!token.value) {
  72. errorMsg.value = "Aucun jeton de validation n'a été fourni."
  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. return
  79. }
  80. // Make API request to validate token
  81. await ap2iRequestService.get(
  82. UrlUtils.join(
  83. runtimeConfig.public.ap2iBaseUrl,
  84. '/api/public/shop/validate/',
  85. token.value
  86. )
  87. )
  88. // If we get here, the validation was successful
  89. validationSuccess.value = true
  90. } catch (error) {
  91. console.error('Error validating token:', error)
  92. validationSuccess.value = false
  93. errorMsg.value = processApiError(error)
  94. }
  95. }
  96. onMounted(async () => {
  97. await validate()
  98. loading.value = false
  99. })
  100. </script>
  101. <style scoped lang="scss">
  102. .v-card {
  103. margin: 4rem 20%;
  104. padding: 2rem;
  105. }
  106. .v-card-title {
  107. font-size: 1.8rem;
  108. font-weight: 700;
  109. color: var(--primary-color);
  110. }
  111. .v-card-text {
  112. font-size: 1.1rem;
  113. line-height: 1.6;
  114. p {
  115. margin-bottom: 1rem;
  116. }
  117. }
  118. .error-message {
  119. color: var(--warning-color);
  120. font-weight: 500;
  121. }
  122. </style>