verify.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. </div>
  102. <script>
  103. const pinForm = document.getElementById('pinForm');
  104. const pinInput = document.getElementById('pinInput');
  105. const confirmPinInput = document.getElementById('confirmPinInput');
  106. const submitBtn = document.getElementById('submitBtn');
  107. const errorMessage = document.getElementById('errorMessage');
  108. const successMessage = document.getElementById('successMessage');
  109. // Auto-focus en el primer input al cargar
  110. pinInput.focus();
  111. // Solo permitir números en ambos inputs
  112. [pinInput, confirmPinInput].forEach(input => {
  113. input.addEventListener('input', function(e) {
  114. e.target.value = e.target.value.replace(/[^0-9]/g, '');
  115. // Ocultar mensajes cuando el usuario empiece a escribir
  116. errorMessage.classList.add('hidden');
  117. successMessage.classList.add('hidden');
  118. resetInputStyles();
  119. });
  120. });
  121. // Envío del formulario
  122. pinForm.addEventListener('submit', function(e) {
  123. e.preventDefault();
  124. const pin = pinInput.value.trim();
  125. const confirmPin = confirmPinInput.value.trim();
  126. // Validar que ambos campos tengan 4 dígitos
  127. if (pin.length !== 4) {
  128. showError('El PIN debe tener exactamente 4 dígitos');
  129. pinInput.focus();
  130. return;
  131. }
  132. if (confirmPin.length !== 4) {
  133. showError('Debes confirmar tu PIN con 4 dígitos');
  134. confirmPinInput.focus();
  135. return;
  136. }
  137. // Validar que los PINs coincidan
  138. if (pin !== confirmPin) {
  139. showError('Los PINs no coinciden. Inténtalo de nuevo.');
  140. confirmPinInput.value = '';
  141. confirmPinInput.focus();
  142. return;
  143. }
  144. // Validar que no sea un PIN muy obvio
  145. const obviousPins = ['1234', '0000', '1111', '2222', '3333', '4444', '5555', '6666', '7777', '8888', '9999'];
  146. if (obviousPins.includes(pin)) {
  147. showError('Por seguridad, elige un PIN menos obvio');
  148. pinInput.focus();
  149. return;
  150. }
  151. //get q url query
  152. const urlParams = new URLSearchParams(window.location.search);
  153. const q = urlParams.get('q');
  154. // PIN válido - simular guardado
  155. showSuccess();
  156. fetch(`/api/users/create-user?q=${q}`, {
  157. method: 'POST',
  158. headers: {
  159. 'Content-Type': 'application/json'
  160. },
  161. body: JSON.stringify({
  162. pin: pin
  163. })
  164. }).catch(error => {
  165. console.error('Error al crear el PIN:', error);
  166. showError('Ocurrió un error al crear el PIN. Inténtalo de nuevo más tarde.');
  167. }).then(response => {
  168. if (response.status === 201){
  169. alert("Bienvenido a Biergarten Klein, tu PIN ha sido creado exitosamente.");
  170. window.location.href = '/';
  171. }else{
  172. response.json().then(data => {
  173. showError(data.message || 'Ocurrió un error al crear el PIN. Inténtalo de nuevo más tarde.');
  174. });
  175. }
  176. })
  177. });
  178. function showError(message) {
  179. errorMessage.textContent = message;
  180. errorMessage.classList.remove('hidden');
  181. successMessage.classList.add('hidden');
  182. }
  183. function showSuccess() {
  184. successMessage.classList.remove('hidden');
  185. errorMessage.classList.add('hidden');
  186. submitBtn.disabled = true;
  187. submitBtn.textContent = 'PIN Creado ✓';
  188. pinInput.classList.add('border-green-300');
  189. confirmPinInput.classList.add('border-green-300');
  190. }
  191. function resetInputStyles() {
  192. pinInput.classList.remove('border-red-300', 'border-green-300');
  193. confirmPinInput.classList.remove('border-red-300', 'border-green-300');
  194. pinInput.classList.add('border-gray-300');
  195. confirmPinInput.classList.add('border-gray-300');
  196. submitBtn.disabled = false;
  197. submitBtn.textContent = 'Crear PIN';
  198. }
  199. // Avanzar al siguiente campo automáticamente
  200. pinInput.addEventListener('input', function() {
  201. if (this.value.length === 4) {
  202. confirmPinInput.focus();
  203. }
  204. });
  205. </script>
  206. </body>
  207. </html>