/* * Copyright (C) 2023-2025. Gardel and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ import React from 'react'; import Button from '@mui/material/Button'; import { Box, Container, FilledInput, FormControl, IconButton, InputAdornment, InputLabel, Paper, TextField } from '@mui/material'; import {Visibility, VisibilityOff} from '@mui/icons-material'; import {AppState} from './types'; import './reset.css'; import {SubmitHandler, useForm} from 'react-hook-form'; import axios from 'axios'; import {useSnackbar} from 'notistack'; type Inputs = { username: string, profileName: string, password: string }; function PasswordReset(props: { appData: AppState, setAppData: React.Dispatch> }) { const {appData, setAppData} = props; const {enqueueSnackbar} = useSnackbar(); const {register, handleSubmit, formState: {errors}} = useForm(); const [submitting, setSubmitting] = React.useState(false); const onSubmit: SubmitHandler = data => { setSubmitting(true); const hash = window.location.hash; if (!hash) { setSubmitting(false); enqueueSnackbar('链接失效,请重新打开', {variant: 'error'}); return; } const params = new URLSearchParams(hash.substring(1)); axios.post('/authserver/resetPassword', { email: data.username, password: data.password, accessToken: params.get('passwordResetToken'), }) .then(() => { toLogin(); window.location.replace('/profile/') enqueueSnackbar("重置成功", {variant: 'success'}); }) .catch(e => { const response = e.response; if (response && response.status >= 400 && response.status < 500) { let errorMessage = response.data.errorMessage ?? response.data; enqueueSnackbar('重置失败: ' + errorMessage, {variant: 'error'}); } else { enqueueSnackbar('网络错误:' + e.message, {variant: 'error'}); } }) .finally(() => setSubmitting(false)) }; const [showPassword, setShowPassword] = React.useState(false); const handleClickShowPassword = () => setShowPassword((show) => !show); const handleMouseDownPassword = (event: React.MouseEvent) => { event.preventDefault(); }; const toLogin = () => { setAppData({ ...appData, passwordReset: false }); } return (

简陋重置密码页

新密码 {showPassword ? : } } inputProps={{ minLength: '6', ...register('password', {required: true, minLength: 6}) }} />
); } export default PasswordReset;