-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
310 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import Avatar from '@mui/material/Avatar'; | ||
import Button from '@mui/material/Button'; | ||
import CssBaseline from '@mui/material/CssBaseline'; | ||
import Grid from '@mui/material/Grid'; | ||
import Box from '@mui/material/Box'; | ||
import LockOutlinedIcon from '@mui/icons-material/LockOutlined'; | ||
import Typography from '@mui/material/Typography'; | ||
import Container from '@mui/material/Container'; | ||
import TextField from '@mui/material/TextField'; | ||
import { useTitle } from 'ahooks'; | ||
import { useEffect, useState } from 'react'; | ||
import Snackbar from '@mui/material/Snackbar'; | ||
import Alert from '@mui/material/Alert'; | ||
import Loading from '@/components/Loading'; | ||
import { produce } from 'immer'; | ||
import { forgotPassWord } from '@/apis/apis'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
export default function Forgot() { | ||
const [err, setErr] = useState("") | ||
useTitle("找回密码") | ||
const [passerr, setPasserr] = useState("") | ||
const [pass, setPass] = useState({ | ||
pass1: "", | ||
pass2: "", | ||
}) | ||
const [load, setLoad] = useState(false) | ||
const [email, setEmail] = useState("") | ||
const [code, setCode] = useState("") | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
if (pass.pass1 != pass.pass2 && pass.pass2 != "") { | ||
setPasserr("密码不相等") | ||
return | ||
} | ||
setPasserr("") | ||
}, [pass.pass1, pass.pass2]) | ||
|
||
const u = new URL(location.href) | ||
|
||
useEffect(() => { | ||
setEmail(u.searchParams.get("email") ?? "") | ||
setCode(u.searchParams.get("code") ?? "") | ||
}, [u.searchParams]) | ||
|
||
|
||
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault() | ||
setLoad(true) | ||
forgotPassWord(email, code, pass.pass1).then(() => { | ||
navigate("/") | ||
}).catch(e => { | ||
setErr(String(e)) | ||
}).finally(() => { setLoad(false) }) | ||
} | ||
|
||
|
||
return ( | ||
<Container component="main" maxWidth="xs"> | ||
<CssBaseline /> | ||
<Box | ||
sx={{ | ||
marginTop: 8, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Avatar sx={{ m: 1, bgcolor: 'secondary.main' }}> | ||
<LockOutlinedIcon /> | ||
</Avatar> | ||
<Typography component="h1" variant="h5"> | ||
找回密码 | ||
</Typography> | ||
<Box component="form" noValidate onSubmit={onSubmit} sx={{ mt: 3 }}> | ||
<Grid container spacing={2}> | ||
<Grid item xs={12}> | ||
<TextField | ||
margin='dense' | ||
fullWidth | ||
label="新密码" | ||
type="password" | ||
required | ||
onChange={p => setPass(produce(v => { v.pass1 = p.target.value }))} | ||
autoComplete="new-password" | ||
/> | ||
</Grid> | ||
<Grid item xs={12}> | ||
<TextField | ||
margin='dense' | ||
fullWidth | ||
label="确认新密码" | ||
type="password" | ||
required | ||
error={passerr != ""} | ||
helperText={passerr} | ||
onChange={p => setPass(produce(v => { v.pass2 = p.target.value }))} | ||
autoComplete="new-password" | ||
/> | ||
</Grid> | ||
</Grid> | ||
<Button | ||
type="submit" | ||
fullWidth | ||
variant="contained" | ||
sx={{ mt: 3, mb: 2 }} | ||
> | ||
提交 | ||
</Button> | ||
</Box> | ||
</Box> | ||
<Snackbar anchorOrigin={{ vertical: 'top', horizontal: 'center' }} open={err !== ""}> | ||
<Alert onClose={() => setErr("")} severity="error">{err}</Alert> | ||
</Snackbar> | ||
|
||
{load && <Loading />} | ||
</Container> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.