UNPKG

@syngrisi/syngrisi

Version:
3 lines (2 loc) 14.4 kB
var A=Object.defineProperty;var t=(r,s)=>A(r,"name",{value:s,configurable:!0});import{c as W,u as z,a as q,b as I,l as h,j as e,A as E,I as H,T as m,d as x,C,P as y,B as j,e as k,L as $,f as U,g as v,h as S,i as _,G as O,k as D,m as G,n as N,o as V,r as p,p as Q,D as K,q as X,s as Y,S as Z,t as ee,v as se,Q as re,w as te,x as oe,y as ae,z as ne,M as ie,E as le,F as ce,H as de}from"./http-CC8JzV-G.js";import{C as J}from"./Center-CHBiBbZO.js";import{P}from"./PasswordInput-DaqYfuPs.js";const ue=[["path",{d:"M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0",key:"svg-0"}],["path",{d:"M10 10l4 4m0 -4l-4 4",key:"svg-1"}]],me=W("outline","circle-x","CircleX",ue);function he(r,s){return{footer:{marginTop:120,borderTop:`1px solid ${s==="dark"?r.colors.dark[5]:r.colors.gray[2]}`},footerText:{color:"white",fontSize:"1rem"},footerLink:{margin:"8px",color:"white",fontSize:"1rem"}}}t(he,"getCommonStyles");function ge(){const r=z(),s=q("light"),n=he(r,s),{isLoading:o,isError:c,data:l,error:d}=I({queryKey:["version"],queryFn:t(async()=>{const w=await fetch(`${x.baseUri}/v1/app/info`);if(!w.ok)throw new Error(`[AuthFooter] Failed to fetch app info: ${w.status}`);return w.json()},"queryFn")});if(c)return h.error(d),null;if(o)return null;const u=`https://github.com/syngrisi/syngrisi/releases/tag/v${l.version}`,g=l.commitHash?`https://github.com/syngrisi/syngrisi/commit/${l.commitHash}`:null;return e.jsxs(J,{"data-test":"auth-footer",children:[e.jsxs(E,{href:"https://github.com/syngrisi/syngrisi/tree/main/packages/syngrisi",target:"_blank",style:n.footerLink,"data-test":"auth-footer-github",children:[e.jsx(H,{size:"1rem",stroke:1}),"GitHub"]}),e.jsx(m,{component:"span",style:n.footerText,children:"|"}),e.jsx(E,{style:n.footerLink,href:u,"data-test":"auth-footer-version",children:`v${l.version}`}),l.commitHash&&e.jsxs(e.Fragment,{children:[e.jsx(m,{component:"span",style:n.footerText,children:"|"}),e.jsx(E,{style:n.footerLink,href:g,target:"_blank","data-test":"auth-footer-commit",children:l.commitHash})]})]})}t(ge,"AuthFooter");function fe(){const r=z(),{colorScheme:s}=r;return e.jsxs(C,{style:{paddingTop:"50px",display:"flex",alignItems:"center"},children:[e.jsx(y,{style:{display:"flex",alignItems:"center",padding:"5px 8px",borderRadius:"2px 20px 2px 20px"},children:e.jsxs("svg",{width:"54",viewBox:"0 0 64 67",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M62.245 64.6094L7.36118 36.1968C6.98858 36.0039 6.98859 35.471 7.36118 35.2781L62.245 6.86548C62.5893 6.68725 63 6.93713 63 7.32482V64.1501C63 64.5378 62.5893 64.7876 62.245 64.6094Z",fill:"#2B8A3E",fillOpacity:"0.38",stroke:"#2B8A3E",strokeOpacity:"0.6",strokeWidth:"1.63692"}),e.jsx("path",{d:"M1.74625 59.1348L56.63 30.7222C57.0026 30.5293 57.0026 29.9964 56.63 29.8035L1.74625 1.39087C1.40196 1.21264 0.991211 1.46252 0.991211 1.85021V58.6755C0.991211 59.0631 1.40196 59.313 1.74625 59.1348Z",fill:"#1C7ED6",fillOpacity:"0.4",stroke:"#1C7ED6",strokeOpacity:"0.6",strokeWidth:"1.63692"})]})}),e.jsx(j,{style:{color:"white",fontSize:"3rem",paddingLeft:"8px",fontFamily:"Roboto, sans-serif",fontWeight:500},children:e.jsx(y,{style:{backgroundColor:"rgba(0, 0, 0, 0)"},children:e.jsx(m,{c:s==="dark"?"gray.4":"white",style:{fontSize:"inherit",lineHeight:"inherit",fontWeight:"inherit"},children:"Syngrisi"})})})]})}t(fe,"AuthLogo");const B=t(async(r,s)=>{const n=await fetch(r),c=(n.headers.get("content-type")||"").includes("application/json");let l=null;if(c)try{l=await n.json()}catch(d){h.error(`[${s}] Failed to parse JSON:`,d),l=null}return{ok:n.ok,status:n.status,data:l,isJson:c}},"fetchWithContentTypeCheck");function pe(){k("Logout page");const r=I({queryKey:["logout"],queryFn:t(()=>B(`${x.baseUri}/v1/auth/logout`,"LogoutForm.logout"),"queryFn"),refetchOnWindowFocus:!1}),s=I({queryKey:["current_user",r.data?.status],queryFn:t(()=>B(`${x.baseUri}/v1/users/current`,"LogoutForm.userInfo"),"queryFn"),refetchOnWindowFocus:!1,enabled:r.isSuccess});r.isError&&h.error(r.error),s.isError&&h.error(s.error);const n=!!(s.data?.isJson&&s.data?.data&&typeof s.data.data=="object"),o=n?s.data?.data:{},c=r.isLoading||s.isLoading,l=!!r.data?.ok,d=!s.data?.isJson||n&&Object.keys(o).length===0,u=!!(l&&s.isSuccess&&d),g=(()=>{if(r.data&&!r.data.isJson)return"Unexpected response format during logout";if(r.data&&!r.data.ok)return r.data.data?.message||`Logout failed with status ${r.data.status}`;if(!u){if(s.data&&!s.data.isJson)return"Unexpected response format while loading user info";if(s.data&&!s.data.ok)return`Failed to load user info (${s.data.status})`;if(r.error instanceof Error)return r.error.message;if(s.error instanceof Error)return s.error.message}})();return e.jsxs(C,{size:420,my:40,children:[e.jsx($,{visible:c,overlayProps:{blur:1},loaderProps:{color:"green"}}),e.jsxs(y,{withBorder:!0,shadow:"md",p:30,mt:30,radius:"md",hidden:c,children:[u?e.jsx(m,{ta:"center",c:"green",children:e.jsx(U,{size:"6rem"})}):e.jsx(m,{ta:"center",c:"red",children:e.jsx(me,{size:"6rem"})}),e.jsx(v,{ta:"center",children:u?"Success!":"Failed"}),e.jsx(m,{ta:"center",fz:16,mt:"md",children:u?"You have been successfully logged out. Click Sign In to login again.":g||"Something went wrong"}),e.jsx(S,{fullWidth:!0,id:"submit",mt:"xl",color:"green",type:"submit",component:"a",href:"/auth/",children:"Sign In"})]})]})}t(pe,"LogoutForm");const T=[{re:/[0-9]/,label:"Includes number",id:"include-numbers"},{re:/[a-z]/,label:"Includes lowercase letter",id:"include-lowercase"},{re:/[A-Z]/,label:"Includes uppercase letter",id:"include-uppercase"},{re:/[$&+,:;=?@#|'<>.^*()%!-]/,label:"Includes special symbol",id:"include-special"}];function we({value:r}){function s(c){let l=c.length>5?0:1;return T.forEach(d=>{d.re.test(c)||(l+=1)}),Math.max(100-100/(T.length+1)*l,0)}t(s,"getStrength");const n=s(r),o=Array(4).fill(0).map((c,l)=>e.jsx(_,{styles:{bar:{transitionDuration:"0ms"}},value:r.length>0&&l===0||n>=(l+1)/4*100?100:0,color:n>80?"teal":n>50?"yellow":"red",size:4},l));return e.jsx(O,{gap:5,grow:!0,mt:"xs",mb:"md",children:o})}t(we,"Bars");function R({meets:r,label:s,id:n}){return e.jsx(m,{c:r?"teal":"red",mt:5,size:"sm",id:n,children:e.jsxs(J,{inline:!0,children:[r?e.jsx(D,{size:14,stroke:1.5}):e.jsx(G,{size:14,stroke:1.5}),e.jsx(j,{ml:7,children:s})]})})}t(R,"PasswordRequirement");function xe(){k("Change Password Page");const[r]=N(),s=!!r.get("first_run");let n;const o=V({initialValues:{currentPassword:"",newPassword:"",newPasswordConfirmation:""},validate:{currentPassword:t(a=>s||a!==""?null:"Old password is Empty","currentPassword"),newPassword:t(a=>n.some(f=>!f.meets)?"The password doesn't meet the requirements":null,"newPassword"),newPasswordConfirmation:t(a=>a===o.values.newPassword?null:"New password and password confirmation must be match","newPasswordConfirmation")}}),[c,l]=p.useState(""),[d,u]=p.useState(!1);n=T.map(a=>({key:a.id,id:a.id,label:a.label,meets:a.re.test(o.values.newPassword)}));const g=n.map(a=>e.jsx(R,{id:a.id,label:a.label,meets:a.meets},a.id));function w(a,f){o.setFieldValue(f,a.currentTarget.value)}t(w,"handleNewPasswordFields");async function F(a){try{l(""),u(!0);const f=s?`${x.baseUri}/v1/auth/change_first_run`:`${x.baseUri}/v1/auth/change`,i=await(await fetch(f,{method:"POST",credentials:"include",body:JSON.stringify({currentPassword:s?"":a.currentPassword,newPassword:a.newPassword,isFirstRun:s}),headers:{"Content-Type":"application/json"}})).json();return u(!1),console.log(i),i.message==="success"?window.location.assign("/auth/changeSuccess"):i.message?(h.error(`[ChangePasswordForm] ${JSON.stringify(i)}`),l(i.message)):(h.error(`[ChangePasswordForm] ${JSON.stringify(i)}`),l(i.message))}catch(f){h.error(`[ChangePasswordForm] ${f.stack||f.toString()}`),l("Connection error")}finally{u(!1)}}return t(F,"handleFormSubmissions"),e.jsx(C,{size:420,my:40,children:e.jsx(y,{withBorder:!0,shadow:"md",p:30,mt:30,radius:"md",children:e.jsxs("form",{onSubmit:o.onSubmit(a=>F(a)),children:[e.jsx(v,{order:s?3:2,id:"title",children:s?"Change Password for default Administrator":"Change Password"}),e.jsx(P,{label:"Current Password",placeholder:"Enter current password",id:"current-password",value:s?"---------------":o.values.currentPassword,onChange:t(a=>o.setFieldValue("currentPassword",a.currentTarget.value),"onChange"),error:o.errors.currentPassword&&"Invalid password",disabled:s||!1,required:!0}),e.jsx(P,{value:o.values.newPassword,onChange:t(a=>w(a,"newPassword"),"onChange"),placeholder:"New Password",id:"new-password",label:"New Password",error:o.errors.newPassword,required:!0}),e.jsx(P,{value:o.values.newPasswordConfirmation,onChange:t(a=>w(a,"newPasswordConfirmation"),"onChange"),placeholder:"New Password",id:"new-password-confirmation",label:"New Password Confirmation",error:o.errors.newPasswordConfirmation,required:!0}),e.jsx(we,{value:o.values.newPassword}),e.jsx(R,{label:"Has at least 6 characters",id:"include-six-chars",meets:o.values.newPassword.length>5}),g,c&&e.jsx(m,{size:"sm",c:"red",mt:"md",id:"error-message",hidden:!1,children:c}),e.jsx(S,{fullWidth:!0,id:"change-password",mt:"xl",c:"green",type:"submit",children:"Update password"}),e.jsx($,{visible:d,overlayProps:{blur:1},loaderProps:{color:"green"}})]})})})}t(xe,"ChangePasswordForm");function ye(){k("Login Page");const[r,s]=p.useState(!1),[n,o]=p.useState(!1),[c,l]=p.useState(!0);p.useEffect(()=>{l(!0),Q.get(`${x.baseUri}/v1/auth/sso/status`,{retry:2,timeout:5e3,throwHttpErrors:!1},"LoginForm.ssoStatus").then(i=>i.json()).then(i=>{s(i.ssoEnabled),o(!1)}).catch(i=>{h.error("[LoginForm] Failed to check SSO status:",i),o(!0),s(!1)}).finally(()=>l(!1))},[]);const d=V({initialValues:{email:"",password:"",rememberMe:!0},validate:{email:t(i=>i==="Test"||i==="Administrator"||i==="Guest"||/^\S+@\S+$/.test(i)?null:"Invalid email","email")}}),[u,g]=p.useState(""),[w]=N(),[F,a]=p.useState(!1),f=w.get("origin")||"/";async function M(i){try{g(""),a(!0);const b=await(await fetch(`${x.baseUri}/v1/auth/login`,{method:"POST",credentials:"include",body:JSON.stringify({username:i.email,password:i.password,rememberMe:i.rememberMe}),headers:{"Content-Type":"application/json"}})).json();if(a(!1),b.message==="success")return window.location.assign(f);if(b.message)return h.error(`[LoginForm] ${JSON.stringify(b)}`),g(b.message);h.error(`[LoginForm] ${JSON.stringify(b)}`),g("Connection error")}catch(L){h.error(`[LoginForm] ${L.stack||L.toString()}`),g("Connection error")}finally{a(!1)}}return t(M,"handleFormSubmissions"),e.jsx(C,{size:420,my:40,children:e.jsx(y,{withBorder:!0,shadow:"md",p:30,mt:30,radius:"md",children:e.jsxs("form",{onSubmit:d.onSubmit(i=>M(i)),children:[e.jsx(v,{children:"Sign in"}),n&&e.jsx(m,{size:"xs",c:"orange",mb:"sm",children:"Could not check SSO availability"}),r&&!c&&e.jsxs(e.Fragment,{children:[e.jsx(S,{fullWidth:!0,component:"a",href:`${x.baseUri}/v1/auth/sso`,mt:"xl",mb:"lg",variant:"outline",color:"blue",children:"Sign in with SSO"}),e.jsx(K,{label:"OR",labelPosition:"center",my:"lg"})]}),e.jsx(X,{label:"Email",id:"email",placeholder:"username@domain.com",value:d.values.email,onChange:t(i=>d.setFieldValue("email",i.currentTarget.value),"onChange"),error:d.errors.email&&"Invalid email",required:!0,"aria-label":"Email","data-test":"login-email-input"}),e.jsx(P,{label:"Password",id:"password",placeholder:"Your password",value:d.values.password,onChange:t(i=>d.setFieldValue("password",i.currentTarget.value),"onChange"),required:!0,mt:"md","aria-label":"Password","data-test":"login-password-input"}),e.jsx(O,{justify:"space-between",mt:"md",children:e.jsx(Y,{label:"Remember me",onChange:t(i=>d.setFieldValue("rememberMe",i.currentTarget.checked),"onChange"),"aria-label":"Remember me","data-test":"login-remember-me"})}),u&&e.jsx(m,{size:"sm",c:"red",mt:"md",id:"error-message",hidden:!1,"aria-live":"assertive","data-test":"login-error-message",children:u}),e.jsx(S,{fullWidth:!0,id:"submit",mt:"xl",color:"green",type:"submit","aria-label":"Sign in","data-test":"login-submit",children:"Sign in"}),e.jsx($,{visible:F,overlayProps:{blur:1},loaderProps:{color:"green"}})]})})})}t(ye,"LoginForm");function be(){return k("Success"),e.jsx(C,{size:420,my:40,children:e.jsxs(y,{withBorder:!0,shadow:"md",p:30,mt:30,radius:"md",children:[e.jsx(m,{ta:"center",c:"green",children:e.jsx(U,{size:"6rem"})}),e.jsx(v,{ta:"center",children:"Success!"}),e.jsx(m,{ta:"center",fz:16,mt:"md",children:"Your Password has been changed. Please use your new password to login!"}),e.jsx(S,{fullWidth:!0,id:"submit",mt:"xl",color:"green",type:"submit",component:"a",href:"/auth/",children:"Sign In"})]})})}t(be,"ChangePasswordSuccessForm");const je=[{path:"/auth/logout",element:e.jsx(pe,{})},{path:"/auth/change",element:e.jsx(xe,{})},{path:"/auth/changeSuccess",element:e.jsx(be,{})},{path:"/auth/",element:e.jsx(ye,{})}];function Se({colorScheme:r,toggleColorScheme:s}){const n=r==="dark",o=z();return e.jsx(O,{mr:28,justify:"flex-end",title:`Switch to ${n?"light":"dark"} theme`,children:e.jsx(Z,{"data-test":"theme-button",size:"md",styles:{track:{backgroundColor:o.colors.gray[8],borderColor:o.colors.gray[8]}},color:"gray.8",checked:n,onChange:t(()=>{s()},"onChange"),onLabel:e.jsx(se,{size:16,stroke:2.5,color:o.colors.yellow[4]}),offLabel:e.jsx(ee,{size:16,stroke:2.5,color:o.colors.blue[6]})})})}t(Se,"ToggleThemeButton");const Ce=new re;function Pe(){const r=te(je),[s,n]=oe({key:"mantine-color-scheme",defaultValue:"light",getInitialValueInEffect:!0}),o=t(()=>s==="dark","isDark");p.useEffect(t(function(){if(!o()){document.body.style.backgroundColor="#1e1e1e",document.body.style.setProperty("--before-opacity","0.7");return}document.body.style.backgroundColor="#000000",document.body.style.setProperty("--before-opacity","0.7")},"onColorSchemeChange"),[s]);const c=t(()=>{n(o()?"light":"dark")},"toggleColorScheme");return ae([["mod+J",()=>c()]]),e.jsx(ne,{client:Ce,children:e.jsxs(ie,{defaultColorScheme:"light",cssVariablesResolver:le,forceColorScheme:s,theme:{fontSizes:{md:"24px"},components:{Text:{defaultProps:{component:"div"}}}},children:[e.jsx(Se,{colorScheme:s,toggleColorScheme:c}),e.jsx(j,{style:{display:"flex",justifyContent:"center"},children:e.jsx(fe,{})}),e.jsx(j,{children:r}),e.jsx(j,{children:e.jsx(ge,{})})]})})}t(Pe,"App");ce.createRoot(document.getElementById("root")).render(e.jsx(p.StrictMode,{children:e.jsx(de,{children:e.jsx(Pe,{})})})); //# sourceMappingURL=auth-BHXFhIYP.js.map