{"version":3,"sources":["login.beb18b98.js"],"names":["turnstileTokenReady","onTurnstileSuccess","$","prop","onTurnstileExpired","onTurnstileError","form","fields","username","password","on","e","preventDefault","modal","hasClass","toast","position","class","message","val","cf","addClass","fetch","location","protocol","concat","window","host","method","headers","body","JSON","stringify","credentials","then","response","json","data","success","text","replace","turnstile","reset","catch","error","console","finally","removeClass","title","content","actions"],"mappings":"AAMA,IAAIA,qBAAsB,EAE1B,SAASC,qBACPD,qBAAsB,EACtBE,EAAE,kBAAkBC,KAAK,YAAY,EACvC,CAEA,SAASC,qBACPJ,qBAAsB,EACtBE,EAAE,kBAAkBC,KAAK,YAAY,EACvC,CAEA,SAASE,mBACPL,qBAAsB,EACtBE,EAAE,kBAAkBC,KAAK,YAAY,EACvC,CAEAD,EAAE,KACAA,EAAE,YAAYI,KAAK,CACjBC,OAAQ,CACNC,SAAU,CAAC,QAAS,SACpBC,SAAU,aAKhBP,EAAE,mBAAmBQ,GAAG,QAAUC,IAChCA,EAAEC,iBAEFV,EAAE,yBAAyBW,MAAM,UAGnCX,EAAE,iBAAiBQ,GAAG,QAAUC,IAC9BA,EAAEC,iBAEFV,EAAE,uBAAuBW,MAAM,UAGjCX,EAAE,SAASQ,GAAG,SAAWC,IAGvB,GAFAA,EAAEC,iBAEEV,EAAE,SAASY,SAAS,WAAY,OAAO,EAC3C,IAAKZ,EAAE,SAASI,KAAK,YAAa,OAAO,EAEzC,IAAKN,oBAMH,OALAE,EAAEa,MAAM,CACNC,SAAU,eACVC,MAAO,QACPC,QAAS,yDAEJ,EAGT,MAAMV,EAAWN,EAAE,0BAA0BiB,MACvCV,EAAWP,EAAE,0BAA0BiB,MACvCC,EAAKlB,EAAE,uCAAuCiB,MAEpDjB,EAAE,SAASmB,SAAS,WAEpBC,MACE,GAAGC,SAASC,SAASC,OAAO,MAAMA,OAAOC,OAAOH,SAASI,cACzD,CACEC,OAAQ,OACRC,QAAS,CACP,eAAgB,oBAElBC,KAAMC,KAAKC,UAAU,CAAExB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GAAUC,QAAQD,MAAMA,IAC/BE,QAAQ,KACP5C,EAAE,SAAS6C,YAAY,YAE7B,MACE7C,EAAEa,MAAM,CACNC,SAAU,eACVC,MAAO,QACPC,QAAS,mDApEXhB,EAAEa,MAAM,CACNC,SAAU,eACVC,MAAO,QACPC,QAAS","file":"login.beb18b98.js","sourcesContent":["/* globals turnstile */\n\n// Turnstile tokens expire 5 minutes after issuance and are single-use.\n// Gate the submit button (and recovery link) on this instead of trusting\n// whatever's currently sitting in the hidden response input, so a stale\n// token never reaches the server as a \"wrong password\" look-alike failure.\nlet turnstileTokenReady = false;\n\nfunction onTurnstileSuccess() {\n  turnstileTokenReady = true;\n  $('.submit.button').prop('disabled', false);\n}\n\nfunction onTurnstileExpired() {\n  turnstileTokenReady = false;\n  $('.submit.button').prop('disabled', true);\n}\n\nfunction onTurnstileError() {\n  turnstileTokenReady = false;\n  $('.submit.button').prop('disabled', true);\n}\n\n$(() => {\n  $('.ui.form').form({\n    fields: {\n      username: ['empty', 'email'],\n      password: 'empty',\n    },\n  });\n});\n\n$('#privacy-policy').on('click', (e) => {\n  e.preventDefault();\n\n  $('#modal-privacy-policy').modal('show');\n});\n\n$('#terms-policy').on('click', (e) => {\n  e.preventDefault();\n\n  $('#modal-terms-policy').modal('show');\n});\n\n$('.form').on('submit', (e) => {\n  e.preventDefault();\n\n  if ($('.form').hasClass('loading')) return false;\n  if (!$('.form').form('is valid')) return false;\n\n  if (!turnstileTokenReady) {\n    $.toast({\n      position: 'top attached',\n      class: 'error',\n      message: 'Still verifying, please wait a moment and try again',\n    });\n    return false;\n  }\n\n  const username = $('input[name=\"username\"]').val();\n  const password = $('input[name=\"password\"]').val();\n  const cf = $('input[name=\"cf-turnstile-response\"]').val();\n\n  $('.form').addClass('loading');\n\n  fetch(\n    `${location.protocol.concat('//').concat(window.location.host)}/login`,\n    {\n      method: 'POST',\n      headers: {\n        'Content-Type': 'application/json',\n      },\n      body: JSON.stringify({ username, password, 'cf-turnstile-response': cf }),\n      credentials: 'include',\n    }\n  )\n    .then((response) => response.json())\n    .then((data) => {\n      if (data.success) {\n        // Handle successful login\n        $.toast({\n          position: 'top attached',\n          class: 'success',\n          message: 'Login successful',\n        });\n\n        $('.form').text('Loading dashboard ...');\n        $('.ui.basic.message').addClass('hidden');\n\n        window.location.replace('/');\n      } else {\n        // if (data?.cft_error) turnstile.reset();\n        turnstileTokenReady = false;\n        $('.submit.button').prop('disabled', true);\n        turnstile.reset();\n\n        $.toast({\n          position: 'top attached',\n          class: 'error',\n          message: 'Authentication failed',\n        });\n      }\n    })\n    .catch((error) => console.error(error))\n    .finally(() => {\n      $('.form').removeClass('loading');\n    });\n});\n\n$('#reset-it').on('click', (e) => {\n  e.preventDefault();\n\n  if ($('.form').hasClass('loading')) return;\n\n  if (!turnstileTokenReady) {\n    $.toast({\n      position: 'top attached',\n      class: 'error',\n      message: 'Still verifying, please wait a moment and try again',\n    });\n    return;\n  }\n\n  if ($('.ui.form').form('is valid', 'username')) {\n    $.toast({\n      position: 'top attached',\n      class: 'blue',\n      message: 'Initiating recovery...',\n    });\n\n    $('.form').addClass('loading');\n\n    const username = $('input[name=\"username\"]').val();\n    const cf = $('input[name=\"cf-turnstile-response\"]').val();\n\n    fetch(\n      `${location.protocol\n        .concat('//')\n        .concat(window.location.host)}/login/recovery`,\n      {\n        method: 'POST',\n        headers: {\n          'Content-Type': 'application/json',\n        },\n        body: JSON.stringify({ username, 'cf-turnstile-response': cf }),\n        credentials: 'include',\n      }\n    )\n      .then((response) => response.json())\n      .then((data) => {\n        if (data.success) {\n          $.modal({\n            title: 'Account Recovery',\n            class: 'small',\n            content:\n              'Recovery initiated successfully. You will receive an email with further instructions momentarily.',\n            actions: [\n              {\n                text: 'Close',\n              },\n            ],\n          }).modal('show');\n        } else {\n          // if (data?.cft_error) turnstile.reset();\n          turnstileTokenReady = false;\n          $('.submit.button').prop('disabled', true);\n          turnstile.reset();\n\n          $.toast({\n            position: 'top attached',\n            class: 'error',\n            message: 'Account recovery failed',\n          });\n        }\n      })\n      .catch((error) => console.error(error))\n      .finally(() => {\n        $('.form').removeClass('loading');\n      });\n  } else {\n    $.toast({\n      position: 'top attached',\n      class: 'error',\n      message: 'An email is required for account recovery',\n    });\n  }\n});\n"]}