verify.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <!DOCTYPE html>
  2. <html lang="es">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>Crear PIN - Biergarten Klein</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <!-- Meta tags para evitar cache -->
  8. <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
  9. <meta http-equiv="Pragma" content="no-cache">
  10. <meta http-equiv="Expires" content="0">
  11. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  12. <link rel="stylesheet" as="style" onload="this.rel='stylesheet'"
  13. href="https://fonts.googleapis.com/css2?display=swap&family=Noto+Sans:wght@400;500;700;900&family=Spline+Sans:wght@400;500;700">
  14. <script src="https://cdn.tailwindcss.com?plugins=forms,container-queries"></script>
  15. <script>
  16. tailwind.config = {
  17. theme: {
  18. extend: {
  19. colors: {
  20. 'custom-dark': '#101419',
  21. 'custom-dark-hover': '#37404a',
  22. 'gray-50': '#f9fafb',
  23. 'gray-100': '#f3f4f6',
  24. }
  25. }
  26. }
  27. }
  28. </script>
  29. </head>
  30. <body class="h-[100vh] bg-gray-50 flex items-center justify-center p-4" style='font-family:"Spline Sans","Noto Sans",sans-serif;'>
  31. <div class="w-full max-w-md">
  32. <!-- Header -->
  33. <div class="text-center mb-8">
  34. <h1 class="text-[26px] font-bold text-[#101419] tracking-tight mb-2">
  35. Biergarten Klein
  36. </h1>
  37. <p class="text-[#58728d] text-sm">
  38. Crea tu PIN de seguridad
  39. </p>
  40. </div>
  41. <!-- Formulario -->
  42. <form id="pinForm" class="bg-white rounded-xl shadow-sm border border-gray-200 p-8 space-y-6">
  43. <div class="text-center">
  44. <h2 class="text-[19px] font-bold text-[#101419] mb-2">Crear tu PIN</h2>
  45. <p class="text-sm text-[#58728d]">
  46. Elige un PIN de 4 dígitos que usarás para acceder a tu cuenta
  47. </p>
  48. </div>
  49. <div class="space-y-4">
  50. <div>
  51. <label for="pinInput" class="block text-sm font-medium text-[#101419] mb-2">
  52. Nuevo PIN (4 dígitos)
  53. </label>
  54. <input
  55. id="pinInput"
  56. name="pin"
  57. type="password"
  58. maxlength="4"
  59. pattern="[0-9]{4}"
  60. class="w-full border border-gray-300 px-4 py-3 rounded-lg focus:ring-2 focus:ring-[#101419] focus:border-transparent outline-none transition-all text-center text-lg tracking-widest"
  61. placeholder="••••"
  62. required
  63. autocomplete="new-password"
  64. />
  65. </div>
  66. <div>
  67. <label for="confirmPinInput" class="block text-sm font-medium text-[#101419] mb-2">
  68. Confirmar PIN
  69. </label>
  70. <input
  71. id="confirmPinInput"
  72. name="confirmPin"
  73. type="password"
  74. maxlength="4"
  75. pattern="[0-9]{4}"
  76. class="w-full border border-gray-300 px-4 py-3 rounded-lg focus:ring-2 focus:ring-[#101419] focus:border-transparent outline-none transition-all text-center text-lg tracking-widest"
  77. placeholder="••••"
  78. required
  79. autocomplete="new-password"
  80. />
  81. </div>
  82. <!-- Mensaje de error -->
  83. <div id="errorMessage" class="hidden text-red-500 text-sm text-center"></div>
  84. <!-- Mensaje de éxito -->
  85. <div id="successMessage" class="hidden text-green-600 text-sm text-center">
  86. ✓ PIN creado correctamente
  87. </div>
  88. <!-- Indicador de fuerza del PIN -->
  89. <div class="text-xs text-[#58728d] text-center">
  90. 💡 Consejo: Evita usar PINs obvios como 1234 o 0000
  91. </div>
  92. </div>
  93. <button
  94. id="submitBtn"
  95. type="submit"
  96. class="w-full bg-[#101419] hover:bg-[#37404a] disabled:opacity-50 disabled:cursor-not-allowed text-white py-3 rounded-lg font-medium transition-colors duration-200 focus:ring-2 focus:ring-offset-2 focus:ring-[#101419]"
  97. >
  98. Crear PIN
  99. </button>
  100. </form>
  101. <!-- Pantalla de Éxito -->
  102. <div id="successScreen" class="hidden bg-white rounded-xl shadow-sm border border-gray-200 p-8 space-y-6">
  103. <div class="text-center">
  104. <!-- Ícono de éxito -->
  105. <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
  106. <svg class="w-8 h-8 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
  107. <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
  108. </svg>
  109. </div>
  110. <h2 class="text-[24px] font-bold text-[#101419] mb-2">¡Registro Exitoso!</h2>
  111. <p class="text-sm text-[#58728d] mb-6">
  112. Tu cuenta ha sido creada correctamente en Biergarten Klein
  113. </p>
  114. </div>
  115. <div class="bg-gray-50 rounded-lg p-4 space-y-3">
  116. <div class="text-center">
  117. <h3 class="text-sm font-medium text-[#101419] mb-1">Tu número de usuario es:</h3>
  118. <div class="text-2xl font-bold text-[#101419] tracking-wide" id="userId">
  119. #0000
  120. </div>
  121. <p class="text-xs text-[#58728d] mt-2">
  122. Es un gran placer tenerte con nosotros.
  123. </p>
  124. </div>
  125. </div>
  126. <div class="space-y-3">
  127. <a
  128. href="/"
  129. id="loginLink"
  130. class="block w-full bg-[#101419] hover:bg-[#37404a] text-white py-3 rounded-lg font-medium transition-colors duration-200 focus:ring-2 focus:ring-offset-2 focus:ring-[#101419] text-center"
  131. >
  132. Iniciar Sesión
  133. </a>
  134. <p class="text-xs text-[#58728d] text-center">
  135. Ya puedes usar tu número de usuario y PIN para acceder a tu cuenta
  136. </p>
  137. </div>
  138. </div>
  139. </div>
  140. <script>
  141. const pinForm = document.getElementById('pinForm');
  142. const pinInput = document.getElementById('pinInput');
  143. const confirmPinInput = document.getElementById('confirmPinInput');
  144. const submitBtn = document.getElementById('submitBtn');
  145. const errorMessage = document.getElementById('errorMessage');
  146. const successMessage = document.getElementById('successMessage');
  147. const successScreen = document.getElementById('successScreen');
  148. const userIdElement = document.getElementById('userId');
  149. const loginLink = document.getElementById('loginLink');
  150. // Auto-focus en el primer input al cargar
  151. pinInput.focus();
  152. // Solo permitir números en ambos inputs
  153. [pinInput, confirmPinInput].forEach(input => {
  154. input.addEventListener('input', function(e) {
  155. e.target.value = e.target.value.replace(/[^0-9]/g, '');
  156. // Ocultar mensajes cuando el usuario empiece a escribir
  157. errorMessage.classList.add('hidden');
  158. successMessage.classList.add('hidden');
  159. resetInputStyles();
  160. });
  161. });
  162. // Envío del formulario
  163. pinForm.addEventListener('submit', function(e) {
  164. e.preventDefault();
  165. const pin = pinInput.value.trim();
  166. const confirmPin = confirmPinInput.value.trim();
  167. // Validar que ambos campos tengan 4 dígitos
  168. if (pin.length !== 4) {
  169. showError('El PIN debe tener exactamente 4 dígitos');
  170. pinInput.focus();
  171. return;
  172. }
  173. if (confirmPin.length !== 4) {
  174. showError('Debes confirmar tu PIN con 4 dígitos');
  175. confirmPinInput.focus();
  176. return;
  177. }
  178. // Validar que los PINs coincidan
  179. if (pin !== confirmPin) {
  180. showError('Los PINs no coinciden. Inténtalo de nuevo.');
  181. confirmPinInput.value = '';
  182. confirmPinInput.focus();
  183. return;
  184. }
  185. // Deshabilitar el botón mientras se procesa
  186. submitBtn.disabled = true;
  187. submitBtn.textContent = 'Creando PIN...';
  188. //get q url query
  189. const urlParams = new URLSearchParams(window.location.search);
  190. const q = urlParams.get('q');
  191. // PIN válido - enviar al servidor
  192. fetch(`/api/users/create-user?q=${q}`, {
  193. method: 'POST',
  194. headers: {
  195. 'Content-Type': 'application/json'
  196. },
  197. body: JSON.stringify({
  198. pin: pin
  199. })
  200. })
  201. .then(response => {
  202. if (response.status === 201) {
  203. return response.json();
  204. } else {
  205. return response.json().then(data => {
  206. throw new Error(data.message || 'Ocurrió un error al crear el PIN. Inténtalo de nuevo más tarde.');
  207. });
  208. }
  209. })
  210. .then(data => {
  211. // Mostrar pantalla de éxito con el ID del usuario
  212. showSuccessScreen(data.data.user_id || data.data.id || 'N/A');
  213. })
  214. .catch(error => {
  215. console.error('Error al crear el PIN:', error);
  216. showError(error.message || 'Ocurrió un error al crear el PIN. Inténtalo de nuevo más tarde.');
  217. // Rehabilitar el botón en caso de error
  218. submitBtn.disabled = false;
  219. submitBtn.textContent = 'Crear PIN';
  220. });
  221. });
  222. function showError(message) {
  223. errorMessage.textContent = message;
  224. errorMessage.classList.remove('hidden');
  225. successMessage.classList.add('hidden');
  226. }
  227. function showSuccess() {
  228. successMessage.classList.remove('hidden');
  229. errorMessage.classList.add('hidden');
  230. submitBtn.disabled = true;
  231. submitBtn.textContent = 'PIN Creado ✓';
  232. pinInput.classList.add('border-green-300');
  233. confirmPinInput.classList.add('border-green-300');
  234. }
  235. function showSuccessScreen(userId) {
  236. // Ocultar el formulario
  237. pinForm.classList.add('hidden');
  238. // Mostrar la pantalla de éxito
  239. successScreen.classList.remove('hidden');
  240. // Actualizar el ID del usuario
  241. userIdElement.textContent = `#${userId}`;
  242. // Configurar el enlace de inicio de sesión con la URL base
  243. const currentUrl = window.location.origin; // Esto obtiene la URL base actual
  244. loginLink.href = currentUrl;
  245. }
  246. function resetInputStyles() {
  247. pinInput.classList.remove('border-red-300', 'border-green-300');
  248. confirmPinInput.classList.remove('border-red-300', 'border-green-300');
  249. pinInput.classList.add('border-gray-300');
  250. confirmPinInput.classList.add('border-gray-300');
  251. submitBtn.disabled = false;
  252. submitBtn.textContent = 'Crear PIN';
  253. }
  254. // Avanzar al siguiente campo automáticamente
  255. pinInput.addEventListener('input', function() {
  256. if (this.value.length === 4) {
  257. confirmPinInput.focus();
  258. }
  259. });
  260. </script>
  261. </body>
  262. </html>