verify.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  8. <link rel="stylesheet" as="style" onload="this.rel='stylesheet'"
  9. href="https://fonts.googleapis.com/css2?display=swap&family=Noto+Sans:wght@400;500;700;900&family=Spline+Sans:wght@400;500;700">
  10. <script src="https://cdn.tailwindcss.com?plugins=forms,container-queries"></script>
  11. <script>
  12. tailwind.config = {
  13. theme: {
  14. extend: {
  15. colors: {
  16. 'custom-dark': '#101419',
  17. 'custom-dark-hover': '#37404a',
  18. 'gray-50': '#f9fafb',
  19. 'gray-100': '#f3f4f6',
  20. }
  21. }
  22. }
  23. }
  24. </script>
  25. </head>
  26. <body class="h-[100vh] bg-gray-50 flex items-center justify-center p-4" style='font-family:"Spline Sans","Noto Sans",sans-serif;'>
  27. <div class="w-full max-w-md">
  28. <!-- Header -->
  29. <div class="text-center mb-8">
  30. <h1 class="text-[26px] font-bold text-[#101419] tracking-tight mb-2">
  31. Biergarten Klein
  32. </h1>
  33. <p class="text-[#58728d] text-sm">
  34. Crea tu PIN de seguridad
  35. </p>
  36. </div>
  37. <!-- Formulario -->
  38. <form id="pinForm" class="bg-white rounded-xl shadow-sm border border-gray-200 p-8 space-y-6">
  39. <div class="text-center">
  40. <h2 class="text-[19px] font-bold text-[#101419] mb-2">Crear tu PIN</h2>
  41. <p class="text-sm text-[#58728d]">
  42. Elige un PIN de 4 dígitos que usarás para acceder a tu cuenta
  43. </p>
  44. </div>
  45. <div class="space-y-4">
  46. <div>
  47. <label for="pinInput" class="block text-sm font-medium text-[#101419] mb-2">
  48. Nuevo PIN (4 dígitos)
  49. </label>
  50. <input
  51. id="pinInput"
  52. name="pin"
  53. type="password"
  54. maxlength="4"
  55. pattern="[0-9]{4}"
  56. 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"
  57. placeholder="••••"
  58. required
  59. autocomplete="new-password"
  60. />
  61. </div>
  62. <div>
  63. <label for="confirmPinInput" class="block text-sm font-medium text-[#101419] mb-2">
  64. Confirmar PIN
  65. </label>
  66. <input
  67. id="confirmPinInput"
  68. name="confirmPin"
  69. type="password"
  70. maxlength="4"
  71. pattern="[0-9]{4}"
  72. 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"
  73. placeholder="••••"
  74. required
  75. autocomplete="new-password"
  76. />
  77. </div>
  78. <!-- Mensaje de error -->
  79. <div id="errorMessage" class="hidden text-red-500 text-sm text-center"></div>
  80. <!-- Mensaje de éxito -->
  81. <div id="successMessage" class="hidden text-green-600 text-sm text-center">
  82. ✓ PIN creado correctamente
  83. </div>
  84. <!-- Indicador de fuerza del PIN -->
  85. <div class="text-xs text-[#58728d] text-center">
  86. 💡 Consejo: Evita usar PINs obvios como 1234 o 0000
  87. </div>
  88. </div>
  89. <button
  90. id="submitBtn"
  91. type="submit"
  92. 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]"
  93. >
  94. Crear PIN
  95. </button>
  96. </form>
  97. </div>
  98. <script>
  99. const pinForm = document.getElementById('pinForm');
  100. const pinInput = document.getElementById('pinInput');
  101. const confirmPinInput = document.getElementById('confirmPinInput');
  102. const submitBtn = document.getElementById('submitBtn');
  103. const errorMessage = document.getElementById('errorMessage');
  104. const successMessage = document.getElementById('successMessage');
  105. // Auto-focus en el primer input al cargar
  106. pinInput.focus();
  107. // Solo permitir números en ambos inputs
  108. [pinInput, confirmPinInput].forEach(input => {
  109. input.addEventListener('input', function(e) {
  110. e.target.value = e.target.value.replace(/[^0-9]/g, '');
  111. // Ocultar mensajes cuando el usuario empiece a escribir
  112. errorMessage.classList.add('hidden');
  113. successMessage.classList.add('hidden');
  114. resetInputStyles();
  115. });
  116. });
  117. // Envío del formulario
  118. pinForm.addEventListener('submit', function(e) {
  119. e.preventDefault();
  120. const pin = pinInput.value.trim();
  121. const confirmPin = confirmPinInput.value.trim();
  122. // Validar que ambos campos tengan 4 dígitos
  123. if (pin.length !== 4) {
  124. showError('El PIN debe tener exactamente 4 dígitos');
  125. pinInput.focus();
  126. return;
  127. }
  128. if (confirmPin.length !== 4) {
  129. showError('Debes confirmar tu PIN con 4 dígitos');
  130. confirmPinInput.focus();
  131. return;
  132. }
  133. // Validar que los PINs coincidan
  134. if (pin !== confirmPin) {
  135. showError('Los PINs no coinciden. Inténtalo de nuevo.');
  136. confirmPinInput.value = '';
  137. confirmPinInput.focus();
  138. return;
  139. }
  140. // Validar que no sea un PIN muy obvio
  141. const obviousPins = ['1234', '0000', '1111', '2222', '3333', '4444', '5555', '6666', '7777', '8888', '9999'];
  142. if (obviousPins.includes(pin)) {
  143. showError('Por seguridad, elige un PIN menos obvio');
  144. pinInput.focus();
  145. return;
  146. }
  147. //get q url query
  148. const urlParams = new URLSearchParams(window.location.search);
  149. const q = urlParams.get('q');
  150. // PIN válido - simular guardado
  151. showSuccess();
  152. fetch(`/api/users/create-user?q=${q}`, {
  153. method: 'POST',
  154. headers: {
  155. 'Content-Type': 'application/json'
  156. },
  157. body: JSON.stringify({
  158. pin: pin
  159. })
  160. }).catch(error => {
  161. console.error('Error al crear el PIN:', error);
  162. showError('Ocurrió un error al crear el PIN. Inténtalo de nuevo más tarde.');
  163. }).then(response => {
  164. if (response.status === 201){
  165. alert("Bienvenido a Biergarten Klein, tu PIN ha sido creado exitosamente.");
  166. window.location.href = '/';
  167. }else{
  168. response.json().then(data => {
  169. showError(data.message || 'Ocurrió un error al crear el PIN. Inténtalo de nuevo más tarde.');
  170. });
  171. }
  172. })
  173. });
  174. function showError(message) {
  175. errorMessage.textContent = message;
  176. errorMessage.classList.remove('hidden');
  177. successMessage.classList.add('hidden');
  178. }
  179. function showSuccess() {
  180. successMessage.classList.remove('hidden');
  181. errorMessage.classList.add('hidden');
  182. submitBtn.disabled = true;
  183. submitBtn.textContent = 'PIN Creado ✓';
  184. pinInput.classList.add('border-green-300');
  185. confirmPinInput.classList.add('border-green-300');
  186. }
  187. function resetInputStyles() {
  188. pinInput.classList.remove('border-red-300', 'border-green-300');
  189. confirmPinInput.classList.remove('border-red-300', 'border-green-300');
  190. pinInput.classList.add('border-gray-300');
  191. confirmPinInput.classList.add('border-gray-300');
  192. submitBtn.disabled = false;
  193. submitBtn.textContent = 'Crear PIN';
  194. }
  195. // Avanzar al siguiente campo automáticamente
  196. pinInput.addEventListener('input', function() {
  197. if (this.value.length === 4) {
  198. confirmPinInput.focus();
  199. }
  200. });
  201. </script>
  202. </body>
  203. </html>