1import{c as P,d as M,r as d,s as t,j as e,I as j,T as B,B as h,v as k,t as m,k as N}from"./main-Ca248qiB.js";import{L as _}from"./label-xR9uAG65.js";import{n as D,a as F,b as R,r as T,w as q,s as I}from"./use-encryption-CprCbr3Y.js";import{K}from"./key-round-Bx1E-DhS.js";const Z=[["path",{d:"M22 13V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v12c0 1.1.9 2 2 2h8",key:"12jkf8"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}],["path",{d:"m16 19 2 2 4-4",key:"1b14m6"}]],A=P("mail-check",Z),W=N().trim().email().max(255),H=N().min(8).max(72);function G(){const w=M(),[i,c]=d.useState(!1),[S,x]=d.useState(!1),[u,f]=d.useState(null);d.useEffect(()=>{let r=!0;t.auth.getSession().then(({data:s})=>{r&&f(!!s.session)});const{data:n}=t.auth.onAuthStateChange((s,a)=>{f(!!a)});return()=>{r=!1,n.subscription.unsubscribe()}},[]);const E=async r=>{r.preventDefault();const n=new FormData(r.currentTarget);try{const s=W.parse(n.get("email"));c(!0);const{error:a}=await t.auth.resetPasswordForEmail(s,{redirectTo:`${window.location.origin}/recovery`});if(a)throw a;x(!0),m.success("E-Mail unterwegs â bitte Posteingang prüfen.")}catch(s){m.error(s instanceof Error&&s.message.includes("email")?"Bitte geben Sie eine gültige E-Mail-Adresse an.":"E-Mail konnte nicht gesendet werden. Bitte später erneut versuchen.")}finally{c(!1)}},z=async r=>{r.preventDefault();const n=new FormData(r.currentTarget);try{const s=H.parse(n.get("new_password")),a=String(n.get("recovery_code")??"").trim();c(!0);const{data:L}=await t.auth.getSession(),l=L.session?.user.id;if(!l)throw new Error("Sitzung abgelaufen. Bitte den Link erneut anfordern.");const{error:g}=await t.auth.updateUser({password:s});if(g)throw g;const{data:o}=await t.from("profiles").select("recovery_salt, recovery_wrapped_key, recovery_iv").eq("id",l).maybeSingle();if(a&&o?.recovery_wrapped_key&&o.recovery_iv&&o.recovery_salt){const C=D(a);let p;try{p=await F(o.recovery_wrapped_key,o.recovery_iv,C,o.recovery_salt)}catch{throw new Error("Recovery-Code ungültig. Passwort wurde geändert â bitte erneut versuchen.")}const y=R(T(16)),v=await q(p,s,y),{error:b}=await t.from("profiles").update({encryption_salt:y,password_wrapped_key:v.wrapped,password_iv:v.iv}).eq("id",l);if(b)throw b;await I(p)}else await t.from("profiles").update({encryption_salt:null,recovery_salt:null,recovery_wrapped_key:null,recovery_iv:null,password_wrapped_key:null,password_iv:null}).eq("id",l);m.success("Passwort geändert â willkommen zurück!"),w({to:"/dashboard"})}catch(s){m.error(s instanceof Error?s.message:"Zurücksetzen fehlgeschlagen")}finally{c(!1)}};return e.jsx("div",{className:"min-h-screen bg-gradient-soft flex items-center justify-center px-4 py-12",children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsxs("div",{className:"mb-8 text-center",children:[e.jsx("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-2xl bg-primary-soft text-primary",children:e.jsx(K,{className:"h-7 w-7"})}),e.jsx("h1",{className:"text-2xl font-bold",children:"Passwort vergessen"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:u?"Legen Sie jetzt Ihr neues Passwort fest.":"Wir senden Ihnen einen Link zum Zurücksetzen per E-Mail."})]}),e.jsx("div",{className:"rounded-2xl border border-border bg-card p-6 shadow-soft",children:u?e.jsxs("form",{onSubmit:z,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(_,{htmlFor:"new_password",children:"Neues Passwort"}),e.jsx(j,{id:"new_password",name:"new_password",type:"password",required:!0,minLength:8,autoComplete:"new-password"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Mind. 8 Zeichen."})]}),e.jsxs("details",{className:"rounded-lg border border-border bg-background p-3",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium",children:"Recovery-Code eingeben (optional)"}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"Nur nötig, wenn Sie noch gespeicherte Dokumente weiter lesen möchten. Ohne Code wird die Verschlüsselung neu aufgesetzt â ältere Dokumente sind dann nicht mehr lesbar (bei 7 Tagen Speicherdauer meist ohnehin gelöscht)."}),e.jsx(B,{name:"recovery_code",rows:3,placeholder:"wort1 wort2 wort3 â¦",className:"mt-2 font-mono text-sm"})]}),e.jsx(h,{type:"submit",className:"w-full",disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"})," Passwort speichernâ¦"]}):"Neues Passwort speichern"})]}):S?e.jsxs("div",{className:"text-center",children:[e.jsx(A,{className:"mx-auto h-8 w-8 text-primary"}),e.jsx("p",{className:"mt-3 text-sm",children:"Wenn ein Konto zu dieser Adresse existiert, haben wir einen Link zum Zurücksetzen gesendet. Bitte prüfen Sie auch den Spam-Ordner."}),e.jsx(h,{variant:"ghost",className:"mt-4",onClick:()=>x(!1),children:"Andere E-Mail verwenden"})]}):e.jsxs("form",{onSubmit:E,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(_,{htmlFor:"email",children:"E-Mail"}),e.jsx(j,{id:"email",name:"email",type:"email",required:!0,autoComplete:"email"})]}),e.jsx(h,{type:"submit",className:"w-full",disabled:i||u===null,children:i?e.jsxs(e.Fragment,{children:[e.jsx(k,{className:"mr-2 h-4 w-4 animate-spin"})," Link sendenâ¦"]}):"Link zum Zurücksetzen senden"}),e.jsx("button",{type:"button",onClick:()=>w({to:"/auth"}),className:"block w-full text-center text-xs text-muted-foreground underline hover:text-primary",children:"Zurück zur Anmeldung"})]})})]})})}export{G as component};
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.