@syngrisi/syngrisi
Version:
Syngrisi - Visual Testing Tool
3 lines (2 loc) • 11.6 kB
JavaScript
var V=Object.defineProperty;var n=(t,s)=>V(t,"name",{value:s,configurable:!0});import{c as D,u as E,k as y,a as f,l as w,j as d,C as O,A as B,b as e,N as U,T as h,d as M,e as v,P as b,B as C,f as x,r as p,L as F,z as $,w as W,g as z,h as L,i as J,G as N,m as H,n as _,o as A,p as R,q,s as G,S as Q,t as Y,v as Z,Q as K,x as X,y as ee,D as re,E as se,F as te,M as oe,H as ne,I as ae}from"./use-form-CYJtOIAE.js";import{P as k}from"./PasswordInput-DBLgbJ8-.js";const ie=D(t=>({footer:{marginTop:120,borderTop:`1px solid ${t.colorScheme==="dark"?t.colors.dark[5]:t.colors.gray[2]}`},footerText:{color:"white",fontSize:"1rem"},footerLink:{margin:"8px",color:"white",fontSize:"1rem",":hover":{textDecoration:"underline",filter:"brightness(120%)"}}}));function le(){const{classes:t}=ie(),{isLoading:s,isError:a,data:o,error:c}=E(["version"],()=>y(`${f.baseUri}/v1/app/info`).then(m=>m.json()));if(a)return w.error(c),null;if(s)return null;const i=`https://github.com/syngrisi/syngrisi/releases/tag/v${o.version}`;return d(O,{children:[d(B,{href:"https://github.com/syngrisi/syngrisi/tree/main/packages/syngrisi",target:"_blank",className:t.footerLink,children:[e(U,{size:"1rem",stroke:1}),"GitHub"]}),e(h,{component:"span",className:t.footerText,children:"|"}),e(B,{className:t.footerLink,href:i,children:`v${o.version}`})]})}n(le,"AuthFooter");function ce(){const t=M(),{colorScheme:s}=t;return d(v,{style:{paddingTop:"50px",display:"flex",alignItems:"center"},children:[e(b,{style:{display:"flex",alignItems:"center",padding:"5px 8px",borderRadius:"2px 20px 2px 20px"},children:d("svg",{width:"54",viewBox:"0 0 64 67",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e("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("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(C,{style:{color:"white",fontSize:"3rem",paddingLeft:"8px",fontFamily:"Roboto, sans-serif",fontWeight:500},children:e(b,{style:{backgroundColor:"rgba(0, 0, 0, 0)"},children:e(h,{color:s==="dark"?"gray.4":"white",children:"Syngrisi"})})})]})}n(ce,"AuthLogo");function de(){x("Logout page"),p.useEffect(()=>{y(`${f.baseUri}/v1/auth/logout`)},[]);const t=E(["logout"],()=>y(`${f.baseUri}/v1/auth/logout`).then(o=>o.json()),{refetchOnWindowFocus:!1}),s=E(["current_user",t],()=>y(`${f.baseUri}/v1/users/current`).then(o=>o.json()),{refetchOnWindowFocus:!1});s.isError&&w.error(s.error);const a=!s.isLoading&&Object.keys(s.data).length===0;return d(v,{size:420,my:40,children:[e(F,{visible:s.isLoading,transitionDuration:300,overlayBlur:1,loaderProps:{color:"green"}}),d(b,{withBorder:!0,shadow:"md",p:30,mt:30,radius:"md",hidden:s.isLoading,children:[a?e(h,{align:"center",color:"green",children:e($,{size:"6rem"})}):e(h,{align:"center",color:"red",children:e(W,{size:"6rem"})}),e(z,{align:"center",children:a?"Success!":"Failed"}),e(h,{align:"center",size:16,mt:"md",children:a?"You have been successfully logged out. Click Sign In to login again.":"Something went wrong"}),e(L,{fullWidth:!0,id:"submit",mt:"xl",color:"green",type:"submit",component:"a",href:"/auth/",children:"Sign In"})]})]})}n(de,"LogoutForm");const I=[{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 ue({value:t}){function s(c){let i=c.length>5?0:1;return I.forEach(m=>{m.re.test(c)||(i+=1)}),Math.max(100-100/(I.length+1)*i,0)}n(s,"getStrength");const a=s(t),o=Array(4).fill(0).map((c,i)=>e(J,{styles:{bar:{transitionDuration:"0ms"}},value:t.length>0&&i===0||a>=(i+1)/4*100?100:0,color:a>80?"teal":a>50?"yellow":"red",size:4},i));return e(N,{spacing:5,grow:!0,mt:"xs",mb:"md",children:o})}n(ue,"Bars");function j({meets:t,label:s,id:a}){return e(h,{color:t?"teal":"red",mt:5,size:"sm",id:a,children:d(O,{inline:!0,children:[t?e(H,{size:14,stroke:1.5}):e(_,{size:14,stroke:1.5}),e(C,{ml:7,children:s})]})})}n(j,"PasswordRequirement");function he(){x("Change Password Page");const[t]=A(),s=!!t.get("first_run");let a;const o=R({initialValues:{currentPassword:"",newPassword:"",newPasswordConfirmation:""},validate:{currentPassword:n(r=>s||r!==""?null:"Old password is Empty","currentPassword"),newPassword:n(r=>a.some(g=>!g.meets)?"The password doesn't meet the requirements":null,"newPassword"),newPasswordConfirmation:n(r=>r===o.values.newPassword?null:"New password and password confirmation must be match","newPasswordConfirmation")}}),[c,i]=p.useState(""),[m,S]=p.useState(!1);a=I.map(r=>({key:r.id,id:r.id,label:r.label,meets:r.re.test(o.values.newPassword)}));const T=a.map(r=>e(j,{id:r.id,label:r.label,meets:r.meets},r.id));function l(r,g){o.setFieldValue(g,r.currentTarget.value)}n(l,"handleNewPasswordFields");async function P(r){try{i(""),S(!0);const g=s?`${f.baseUri}/v1/auth/change_first_run`:`${f.baseUri}/v1/auth/change`,u=await(await y(g,{throwHttpErrors:!1,method:"POST",credentials:"include",body:JSON.stringify({currentPassword:s?"":r.currentPassword,newPassword:r.newPassword,isFirstRun:s}),headers:{"content-type":"application/json"}})).json();return S(!1),console.log(u),u.message==="success"?window.location.assign("/auth/changeSuccess"):u.message?(w.error(typeof u=="object"?JSON.stringify(u):u.toString()),i(u.message)):(w.error(typeof u=="object"?JSON.stringify(u):u.toString()),i(u.message))}catch(g){w.error(g.stack||g.toString()),i("Connection error")}finally{S(!1)}}return n(P,"handleFormSubmissions"),e(v,{size:420,my:40,children:e(b,{withBorder:!0,shadow:"md",p:30,mt:30,radius:"md",children:d("form",{onSubmit:o.onSubmit(r=>P(r)),children:[e(z,{order:s?3:2,id:"title",children:s?"Change Password for default Administrator":"Change Password"}),e(k,{label:"Current Password",placeholder:"Enter current password",id:"current-password",value:s?"---------------":o.values.currentPassword,onChange:n(r=>o.setFieldValue("currentPassword",r.currentTarget.value),"onChange"),error:o.errors.currentPassword&&"Invalid password",disabled:s||!1,required:!0}),e(k,{value:o.values.newPassword,onChange:n(r=>l(r,"newPassword"),"onChange"),placeholder:"New Password",id:"new-password",label:"New Password",error:o.errors.newPassword,required:!0}),e(k,{value:o.values.newPasswordConfirmation,onChange:n(r=>l(r,"newPasswordConfirmation"),"onChange"),placeholder:"New Password",id:"new-password-confirmation",label:"New Password Confirmation",error:o.errors.newPasswordConfirmation,required:!0}),e(ue,{value:o.values.newPassword}),e(j,{label:"Has at least 6 characters",id:"include-six-chars",meets:o.values.newPassword.length>5}),T,c&&e(h,{size:"sm",color:"red",mt:"md",id:"error-message",hidden:!1,children:c}),e(L,{fullWidth:!0,id:"change-password",mt:"xl",color:"green",type:"submit",children:"Update password"}),e(F,{visible:m,transitionDuration:300,overlayBlur:1,loaderProps:{color:"green"}})]})})})}n(he,"ChangePasswordForm");function me(){x("Login Page");const t=R({initialValues:{email:"",password:"",rememberMe:!0},validate:{email:n(l=>l==="Test"||l==="Administrator"||/^\S+@\S+$/.test(l)?null:"Invalid email","email")}}),[s,a]=p.useState(""),[o,c]=A(),[i,m]=p.useState(!1),S=o.get("origin")||"/";async function T(l){try{a(""),m(!0);const r=await(await y(`${f.baseUri}/v1/auth/login`,{throwHttpErrors:!1,method:"POST",credentials:"include",body:JSON.stringify({username:l.email,password:l.password,rememberMe:l.rememberMe}),headers:{"content-type":"application/json"}})).json();if(m(!1),r.message==="success")return window.location.assign(S);if(r.message)return w.error(typeof r=="object"?JSON.stringify(r):r.toString()),a(r.message);w.error(typeof r=="object"?JSON.stringify(r):r.toString()),a("Connection error")}catch(P){w.error(P.stack||P.toString()),a("Connection error")}finally{m(!1)}}return n(T,"handleFormSubmissions"),e(v,{size:420,my:40,children:e(b,{withBorder:!0,shadow:"md",p:30,mt:30,radius:"md",children:d("form",{onSubmit:t.onSubmit(l=>T(l)),children:[e(z,{children:"Sign in"}),e(q,{label:"Email",id:"email",placeholder:"username@domain.com",value:t.values.email,onChange:n(l=>t.setFieldValue("email",l.currentTarget.value),"onChange"),error:t.errors.email&&"Invalid email",required:!0}),e(k,{label:"Password",id:"password",placeholder:"Your password",value:t.values.password,onChange:n(l=>t.setFieldValue("password",l.currentTarget.value),"onChange"),required:!0,mt:"md"}),e(N,{position:"apart",mt:"md",children:e(G,{label:"Remember me",onChange:n(l=>t.setFieldValue("rememberMe",l.currentTarget.checked),"onChange")})}),s&&e(h,{size:"sm",color:"red",mt:"md",id:"error-message",hidden:!1,children:s}),e(L,{fullWidth:!0,id:"submit",mt:"xl",color:"green",type:"submit",children:"Sign in"}),e(F,{visible:i,transitionDuration:300,overlayBlur:1,loaderProps:{color:"green"}})]})})})}n(me,"LoginForm");function ge(){return x("Success"),e(v,{size:420,my:40,children:d(b,{withBorder:!0,shadow:"md",p:30,mt:30,radius:"md",children:[e(h,{align:"center",color:"green",children:e($,{size:"6rem"})}),e(z,{align:"center",children:"Success!"}),e(h,{align:"center",size:16,mt:"md",children:"Your Password has been changed. Please use your new password to login!"}),e(L,{fullWidth:!0,id:"submit",mt:"xl",color:"green",type:"submit",component:"a",href:"/auth/",children:"Sign In"})]})})}n(ge,"ChangePasswordSuccessForm");const we=[{path:"/auth/logout",element:e(de,{})},{path:"/auth/change",element:e(he,{})},{path:"/auth/changeSuccess",element:e(ge,{})},{path:"/auth/",element:e(me,{})}];function fe({colorScheme:t,toggleColorScheme:s}){const a=t==="dark",o=M();return e(N,{mr:28,position:"right",title:`Switch to ${a?"light":"dark"} theme`,children:e(Q,{"data-test":"theme-button",size:"md",styles:n(()=>({track:{backgroundColor:o.colors.gray[8],borderColor:o.colors.gray[8]}}),"styles"),color:"gray.8",checked:t==="light",onChange:n(()=>{s()},"onChange"),onLabel:e(Y,{size:16,stroke:2.5,color:o.colors.yellow[4]}),offLabel:e(Z,{size:16,stroke:2.5,color:o.colors.blue[6]})})})}n(fe,"ToggleThemeButton");const pe=new K;function ye(){const t=X(we),[s,a]=ee({key:"mantine-color-scheme",defaultValue:"light",getInitialValueInEffect:!0}),o=n(()=>s==="dark","isDark");p.useEffect(n(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=n(i=>{a(i||(o()?"light":"dark"))},"toggleColorScheme");return re([["mod+J",()=>c()]]),e(se,{client:pe,children:d(te,{colorScheme:s,toggleColorScheme:c,children:[e(fe,{colorScheme:s,toggleColorScheme:c}),d(oe,{withGlobalStyles:!0,withNormalizeCSS:!0,theme:{fontSizes:{md:24},colorScheme:s},children:[e(C,{sx:n(()=>({display:"flex",justifyContent:"center"}),"sx"),children:e(ce,{})}),e(C,{children:t}),e(C,{children:e(le,{})})]})]})})}n(ye,"App");ne.createRoot(document.getElementById("root")).render(e(p.StrictMode,{children:e(ae,{children:e(ye,{})})}));
//# sourceMappingURL=auth-n7FClG30.js.map