2 lines
6.1 KiB
JavaScript
2 lines
6.1 KiB
JavaScript
import{u as B,r as n,j as e,a as m,m as Q,W as R}from"./app-43FwoUKv.js";import{c as g}from"./index-C3aXnQRR.js";import{A as L}from"./Modal-Dl0HSC4q.js";import{D as N}from"./DialogModal-CM2pkQ7Q.js";import{T as A,I as D}from"./TextInput-CdoY_jBz.js";import{P as S}from"./PrimaryButton-Gixff4KF.js";import{S as j}from"./SecondaryButton-CKdOzt0Y.js";import{D as W}from"./DangerButton--OsE_WB2.js";import{I as Y}from"./InputLabel-Cl3yDvOx.js";import{u as q}from"./useTypedPage-_EZ6P4Xz.js";import"./SectionTitle-CmR6E75W.js";import"./transition-aKza8ZE9.js";function u({title:v="Confirm Password",content:b="For your security, please confirm your password to continue.",button:i="Confirm",onConfirm:h,children:c}){const f=B(),[y,p]=n.useState(!1),[o,l]=n.useState({password:"",error:"",processing:!1}),t=n.useRef(null);function x(){m.get(f("password.confirmation")).then(s=>{s.data.confirmed?h():(p(!0),setTimeout(()=>{var a;return(a=t.current)==null?void 0:a.focus()},250))})}function w(){l({...o,processing:!0}),m.post(f("password.confirm"),{password:o.password}).then(()=>{d(),setTimeout(()=>h(),250)}).catch(s=>{var a;l({...o,processing:!1,error:s.response.data.errors.password[0]}),(a=t.current)==null||a.focus()})}function d(){p(!1),l({processing:!1,password:"",error:""})}return e.jsxs("span",{children:[e.jsx("span",{onClick:x,children:c}),e.jsxs(N,{isOpen:y,onClose:d,children:[e.jsxs(N.Content,{title:v,children:[b,e.jsxs("div",{className:"mt-4",children:[e.jsx(A,{ref:t,type:"password",className:"mt-1 block w-3/4",placeholder:"Password",value:o.password,onChange:s=>l({...o,password:s.currentTarget.value})}),e.jsx(D,{message:o.error,className:"mt-2"})]})]}),e.jsxs(N.Footer,{children:[e.jsx(j,{onClick:d,children:"Cancel"}),e.jsx(S,{className:g("ml-2",{"opacity-25":o.processing}),onClick:w,disabled:o.processing,children:i})]})]})]})}function oe({requiresConfirmation:v}){var k,F,P;const b=q(),[i,h]=n.useState(!1),[c,f]=n.useState(!1),[y,p]=n.useState(null),[o,l]=n.useState([]),[t,x]=n.useState(!1),[w,d]=n.useState(null),s=Q({code:""}),a=!i&&((P=(F=(k=b.props)==null?void 0:k.auth)==null?void 0:F.user)==null?void 0:P.two_factor_enabled);function I(){h(!0),R.post("/user/two-factor-authentication",{},{preserveScroll:!0,onSuccess(){return Promise.all([K(),E(),C()])},onFinish(){h(!1),x(v)}})}function E(){return m.get("/user/two-factor-secret-key").then(r=>{d(r.data.secretKey)})}function _(){s.post("/user/confirmed-two-factor-authentication",{preserveScroll:!0,preserveState:!0,errorBag:"confirmTwoFactorAuthentication",onSuccess:()=>{x(!1),p(null),d(null)}})}function K(){return m.get("/user/two-factor-qr-code").then(r=>{p(r.data.svg)})}function C(){return m.get("/user/two-factor-recovery-codes").then(r=>{l(r.data)})}function M(){m.post("/user/two-factor-recovery-codes").then(()=>{C()})}function T(){f(!0),R.delete("/user/two-factor-authentication",{preserveScroll:!0,onSuccess(){f(!1),x(!1)}})}return e.jsxs(L,{title:"Two Factor Authentication",description:"Add additional security to your account using two factor authentication.",children:[a&&!t?e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100",children:"You have enabled two factor authentication."}):t?e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100",children:"Finish enabling two factor authentication."}):e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-gray-100",children:"You have not enabled two factor authentication."}),e.jsx("div",{className:"mt-3 max-w-xl text-sm text-gray-600 dark:text-gray-400",children:e.jsx("p",{children:"When two factor authentication is enabled, you will be prompted for a secure, random token during authentication. You may retrieve this token from your phone's Google Authenticator application."})}),a||t?e.jsxs("div",{children:[y?e.jsxs("div",{children:[e.jsx("div",{className:"mt-4 max-w-xl text-sm text-gray-600 dark:text-gray-400",children:t?e.jsx("p",{className:"font-semibold",children:"To finish enabling two factor authentication, scan the following QR code using your phone's authenticator application or enter the setup key and provide the generated OTP code."}):e.jsx("p",{children:"Two factor authentication is now enabled. Scan the following QR code using your phone's authenticator application or enter the setup key."})}),e.jsx("div",{className:"mt-4",dangerouslySetInnerHTML:{__html:y||""}}),w&&e.jsx("div",{className:"mt-4 max-w-xl text-sm text-gray-600 dark:text-gray-400",children:e.jsxs("p",{className:"font-semibold",children:["Setup Key:"," ",e.jsx("span",{dangerouslySetInnerHTML:{__html:w||""}})]})}),t&&e.jsxs("div",{className:"mt-4",children:[e.jsx(Y,{htmlFor:"code",value:"Code"}),e.jsx(A,{id:"code",type:"text",name:"code",className:"block mt-1 w-1/2",inputMode:"numeric",autoFocus:!0,autoComplete:"one-time-code",value:s.data.code,onChange:r=>s.setData("code",r.currentTarget.value)}),e.jsx(D,{message:s.errors.code,className:"mt-2"})]})]}):null,o.length>0&&!t?e.jsxs("div",{children:[e.jsx("div",{className:"mt-4 max-w-xl text-sm text-gray-600 dark:text-gray-400",children:e.jsx("p",{className:"font-semibold",children:"Store these recovery codes in a secure password manager. They can be used to recover access to your account if your two factor authentication device is lost."})}),e.jsx("div",{className:"grid gap-1 max-w-xl mt-4 px-4 py-4 font-mono text-sm bg-gray-100 dark:bg-gray-900 rounded-lg",children:o.map(r=>e.jsx("div",{children:r},r))})]}):null]}):null,e.jsx("div",{className:"mt-5",children:a||t?e.jsxs("div",{children:[t?e.jsx(u,{onConfirm:_,children:e.jsx(S,{className:g("mr-3",{"opacity-25":i}),disabled:i,children:"Confirm"})}):null,o.length>0&&!t?e.jsx(u,{onConfirm:M,children:e.jsx(j,{className:"mr-3",children:"Regenerate Recovery Codes"})}):null,o.length===0&&!t?e.jsx(u,{onConfirm:C,children:e.jsx(j,{className:"mr-3",children:"Show Recovery Codes"})}):null,t?e.jsx(u,{onConfirm:T,children:e.jsx(j,{className:g("mr-3",{"opacity-25":c}),disabled:c,children:"Cancel"})}):e.jsx(u,{onConfirm:T,children:e.jsx(W,{className:g({"opacity-25":c}),disabled:c,children:"Disable"})})]}):e.jsx("div",{children:e.jsx(u,{onConfirm:I,children:e.jsx(S,{type:"button",className:g({"opacity-25":i}),disabled:i,children:"Enable"})})})})]})}export{oe as default};
|