|
|
@@ -1,65 +1,84 @@
|
|
|
import { useIntl } from "react-intl";
|
|
|
import { ProForm, ProFormText } from "@ant-design/pro-components";
|
|
|
-import { message } from "antd";
|
|
|
+import { Alert, AlertProps } from "antd";
|
|
|
|
|
|
import { post } from "../../../request";
|
|
|
import { useState } from "react";
|
|
|
+import { get as getUiLang } from "../../../locales";
|
|
|
+import { fullUrl } from "../../../utils";
|
|
|
|
|
|
+interface IForgotPasswordRequest {
|
|
|
+ email: string;
|
|
|
+ lang: string;
|
|
|
+ dashboard: string;
|
|
|
+}
|
|
|
interface IFormData {
|
|
|
- email: string;
|
|
|
+ email: string;
|
|
|
}
|
|
|
interface IForgotPasswordResponse {
|
|
|
- ok: boolean;
|
|
|
- message: string;
|
|
|
- data: string;
|
|
|
+ ok: boolean;
|
|
|
+ message: string;
|
|
|
+ data: string;
|
|
|
}
|
|
|
const Widget = () => {
|
|
|
- const intl = useIntl();
|
|
|
- const [notify, setNotify] = useState(
|
|
|
- "系统将向您的注册邮箱发送包含重置密码所需信息的链接。请输入您的注册邮箱。并确保该邮箱可以接受邮件。"
|
|
|
- );
|
|
|
-
|
|
|
- return (
|
|
|
- <>
|
|
|
- <div>{notify}</div>
|
|
|
- <ProForm<IFormData>
|
|
|
- onFinish={async (values: IFormData) => {
|
|
|
- // TODO
|
|
|
- console.log(values);
|
|
|
- const user = {
|
|
|
- email: values.email,
|
|
|
- };
|
|
|
- const signin = await post<
|
|
|
- IFormData,
|
|
|
- IForgotPasswordResponse
|
|
|
- >("/v2/auth/forgotpassword", user);
|
|
|
- if (signin.ok) {
|
|
|
- console.log("token", signin.data);
|
|
|
- setNotify("重置密码的邮件已经发送到您的邮箱。");
|
|
|
- message.success(
|
|
|
- intl.formatMessage({ id: "flashes.success" })
|
|
|
- );
|
|
|
- } else {
|
|
|
- message.error(signin.message);
|
|
|
- }
|
|
|
- }}
|
|
|
- >
|
|
|
- <ProForm.Group>
|
|
|
- <ProFormText
|
|
|
- width="md"
|
|
|
- name="email"
|
|
|
- required
|
|
|
- label={intl.formatMessage({
|
|
|
- id: "forms.fields.email.label",
|
|
|
- })}
|
|
|
- rules={[
|
|
|
- { required: true, type: "email", max: 255, min: 6 },
|
|
|
- ]}
|
|
|
- />
|
|
|
- </ProForm.Group>
|
|
|
- </ProForm>
|
|
|
- </>
|
|
|
- );
|
|
|
+ const intl = useIntl();
|
|
|
+ const [notify, setNotify] = useState<string>(
|
|
|
+ intl.formatMessage({
|
|
|
+ id: "message.send.reset.email",
|
|
|
+ })
|
|
|
+ );
|
|
|
+ const [type, setType] = useState<AlertProps["type"]>("info");
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ {notify ? <Alert message={notify} type={type} showIcon /> : <></>}
|
|
|
+ <ProForm<IFormData>
|
|
|
+ onFinish={async (values: IFormData) => {
|
|
|
+ console.debug(values);
|
|
|
+ const user: IForgotPasswordRequest = {
|
|
|
+ email: values.email,
|
|
|
+ lang: getUiLang(),
|
|
|
+ dashboard: fullUrl(""),
|
|
|
+ };
|
|
|
+ const url = "/v2/auth/forgot-password";
|
|
|
+ console.info("forgot password url", url, user);
|
|
|
+ try {
|
|
|
+ const result = await post<
|
|
|
+ IForgotPasswordRequest,
|
|
|
+ IForgotPasswordResponse
|
|
|
+ >(url, user);
|
|
|
+ if (result.ok) {
|
|
|
+ console.debug("token", result.data);
|
|
|
+ setNotify(
|
|
|
+ intl.formatMessage({
|
|
|
+ id: "message.send.reset.email.successful",
|
|
|
+ })
|
|
|
+ );
|
|
|
+ setType("success");
|
|
|
+ } else {
|
|
|
+ setType("error");
|
|
|
+ setNotify(result.message);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ setType("error");
|
|
|
+ setNotify("服务器内部错误");
|
|
|
+ console.error(error);
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <ProForm.Group>
|
|
|
+ <ProFormText
|
|
|
+ width="md"
|
|
|
+ name="email"
|
|
|
+ required
|
|
|
+ label={intl.formatMessage({
|
|
|
+ id: "forms.fields.email.label",
|
|
|
+ })}
|
|
|
+ rules={[{ required: true, type: "email", max: 255, min: 6 }]}
|
|
|
+ />
|
|
|
+ </ProForm.Group>
|
|
|
+ </ProForm>
|
|
|
+ </>
|
|
|
+ );
|
|
|
};
|
|
|
|
|
|
export default Widget;
|