1import{r as i,b as $,u as k,j as e,B as h,E as j,t as n,s as m}from"./index-q_lmBneL.js";import{C as z,a as D,b as I,c as U,d as B}from"./card-DpDgnJCl.js";import{I as N}from"./input-dMEYRult.js";import{L as y}from"./label-CD3sLOd5.js";import{S as R}from"./shield-C_bqkhsJ.js";import{E as b}from"./eye-off-CCIGUIzt.js";const J=()=>{const[p,_]=i.useState(""),[r,L]=i.useState(""),[o,V]=i.useState(""),[w,q]=i.useState(!1),[x,O]=i.useState(!1),[f,A]=i.useState(!1),[C,g]=i.useState(!1),P=$(),{portalUser:t,signOut:S}=k(),E=s=>{const v=s.length>=8,d=/[A-Z]/.test(s),a=/[a-z]/.test(s),c=/\d/.test(s),u=/[!@#$%^&*(),.?":{}|<>]/.test(s);return{isValid:v&&d&&a&&c&&u,minLength:v,hasUpper:d,hasLower:a,hasNumber:c,hasSpecial:u}},F=async s=>{var d;if(s.preventDefault(),!p||!r||!o){n({title:"Validation Error",description:"All fields are required",variant:"destructive"});return}if(r!==o){n({title:"Validation Error",description:"New passwords do not match",variant:"destructive"});return}if(!E(r).isValid){n({title:"Password Requirements",description:"Password must meet all security requirements",variant:"destructive"});return}if(!(t!=null&&t.email)){n({title:"Error",description:"Unable to verify user email",variant:"destructive"});return}g(!0);try{const{error:a}=await m.auth.signInWithPassword({email:t.email,password:p});if(a){n({title:"Authentication Failed",description:"Current password is incorrect",variant:"destructive"}),g(!1);return}const{error:c}=await m.auth.updateUser({password:r});if(c)throw c;try{await m.rpc("log_security_event",{event_type:"password_changed",client_ip:null,user_agent:navigator.userAgent,details:{user_id:t.id,email:t.email},severity:"info"})}catch{}const{error:u}=await m.from("portal_users").update({force_password_change:!1,last_password_change:new Date().toISOString()}).eq("auth_user_id",(d=(await m.auth.getUser()).data.user)==null?void 0:d.id);if(u)throw u;n({title:"Password Changed Successfully",description:"Please log in again with your new password for security"}),await S(),P("/portal/login")}catch(a){console.error("Error changing password:",a),n({title:"Error",description:a.message||"Failed to change password",variant:"destructive"})}finally{g(!1)}},l=E(r);return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs(z,{className:"w-full max-w-md",children:[e.jsxs(D,{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-4 p-3 bg-primary/10 rounded-full w-fit",children:e.jsx(R,{className:"h-6 w-6 text-primary"})}),e.jsx(I,{className:"text-2xl",children:"Change Password"}),e.jsx(U,{children:t!=null&&t.force_password_change?"You must change your password before accessing the portal":"Update your password for better security"})]}),e.jsx(B,{children:e.jsxs("form",{onSubmit:F,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"current-password",children:"Current Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{id:"current-password",type:w?"text":"password",value:p,onChange:s=>_(s.target.value),placeholder:"Enter current password",required:!0}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>q(!w),children:w?e.jsx(b,{className:"h-4 w-4"}):e.jsx(j,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"new-password",children:"New Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{id:"new-password",type:x?"text":"password",value:r,onChange:s=>L(s.target.value),placeholder:"Enter new password",required:!0}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>O(!x),children:x?e.jsx(b,{className:"h-4 w-4"}):e.jsx(j,{className:"h-4 w-4"})})]}),r&&e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("div",{className:`flex items-center ${l.minLength?"text-green-600":"text-red-600"}`,children:"⢠At least 8 characters"}),e.jsx("div",{className:`flex items-center ${l.hasUpper?"text-green-600":"text-red-600"}`,children:"⢠One uppercase letter"}),e.jsx("div",{className:`flex items-center ${l.hasLower?"text-green-600":"text-red-600"}`,children:"⢠One lowercase letter"}),e.jsx("div",{className:`flex items-center ${l.hasNumber?"text-green-600":"text-red-600"}`,children:"⢠One number"}),e.jsx("div",{className:`flex items-center ${l.hasSpecial?"text-green-600":"text-red-600"}`,children:"⢠One special character"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"confirm-password",children:"Confirm New Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{id:"confirm-password",type:f?"text":"password",value:o,onChange:s=>V(s.target.value),placeholder:"Confirm new password",required:!0}),e.jsx(h,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>A(!f),children:f?e.jsx(b,{className:"h-4 w-4"}):e.jsx(j,{className:"h-4 w-4"})})]}),o&&r!==o&&e.jsx("p",{className:"text-xs text-red-600",children:"Passwords do not match"})]}),e.jsx(h,{type:"submit",className:"w-full",disabled:C||!l.isValid||r!==o,children:C?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-4 h-4 border-2 border-current border-t-transparent roun
1ded-full animate-spin mr-2"}),"Changing Password..."]}):"Change Password"}),e.jsx("div",{className:"text-center mt-4",children:e.jsx(h,{type:"button",variant:"ghost",onClick:async()=>{await S(),P("/portal/login")},className:"text-sm",children:"Login as Different User"})})]})})]})})};export{J as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.