import{r as m,l as f,k as e,B as d,ay as w}from"./index-BK4vUHaK.js";import{c as j}from"./auth-aTo4ljtG.js";import{F as t,R as g,a as h,e as y}from"./encrypt-BN2ZoURD.js";import{c as P,H as I,I as o}from"./head-reInfxhK.js";import"./http-B4QJq32f.js";const T=()=>{const{t:s}=P(),[n,a]=m.useState(""),i=f();m.useEffect(()=>{n&&setTimeout(()=>a(""),3e3)},[n]);function u(r){if(r.password!==r.password2){a(s("auth.differentPassword"));return}if(!c(r.username)){a(s("auth.illegalUsername"));return}if(!c(r.password)){a("auth.illegalPassword");return}const l=r.username,p=y(r.password);j(l,p).then(x=>{if(x.code!==0){a(s("auth.error"));return}w(),i("/auth/login",{replace:!0})}).catch(()=>{a(s("auth.error"))})}function c(r){return!/['"\\/]/.test(r)}return e.jsxs(e.Fragment,{children:[e.jsx(I,{title:s("head.changePassword")}),e.jsxs("div",{className:"flex h-screen w-screen flex-col items-center justify-center",children:[e.jsx("h2",{className:"text-xl font-semibold text-neutral-100",children:s("auth.changePassword")}),e.jsxs(t,{style:{minWidth:300,maxWidth:500},initialValues:{remember:!0},onFinish:u,children:[e.jsx(t.Item,{name:"username",rules:[{required:!0,message:s("auth.noEmptyUsername"),min:1}],children:e.jsx(o,{prefix:e.jsx(g,{}),placeholder:s("auth.placeholderUsername")})}),e.jsx(t.Item,{name:"password",rules:[{required:!0,message:s("auth.noEmptyPassword"),min:1}],children:e.jsx(o,{prefix:e.jsx(h,{}),type:"password",placeholder:s("auth.placeholderPassword")})}),e.jsx(t.Item,{name:"password2",rules:[{required:!0,message:s("auth.noEmptyPassword"),min:1}],children:e.jsx(o,{prefix:e.jsx(h,{}),type:"password",placeholder:s("auth.placeholderPassword2")})}),e.jsx("span",{className:"text-red-500",children:n}),e.jsx(t.Item,{children:e.jsxs("div",{className:"flex w-full space-x-2",children:[e.jsx(d,{type:"primary",htmlType:"submit",className:"w-1/2",children:s("auth.ok")}),e.jsx(d,{className:"w-1/2",onClick:()=>i("/"),children:s("auth.cancel")})]})})]})]})]})};export{T as Password};
