ForgotPassword.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { useIntl } from "react-intl";
  2. import { ProForm, ProFormText } from "@ant-design/pro-components";
  3. import { message } from "antd";
  4. import { post } from "../../../request";
  5. import { useState } from "react";
  6. interface IFormData {
  7. email: string;
  8. }
  9. interface IForgotPasswordResponse {
  10. ok: boolean;
  11. message: string;
  12. data: string;
  13. }
  14. const Widget = () => {
  15. const intl = useIntl();
  16. const [notify, setNotify] = useState(
  17. "系统将向您的注册邮箱发送包含重置密码所需信息的链接。请输入您的注册邮箱。并确保该邮箱可以接受邮件。"
  18. );
  19. return (
  20. <>
  21. <div>{notify}</div>
  22. <ProForm<IFormData>
  23. onFinish={async (values: IFormData) => {
  24. // TODO
  25. console.log(values);
  26. const user = {
  27. email: values.email,
  28. };
  29. const signin = await post<
  30. IFormData,
  31. IForgotPasswordResponse
  32. >("/v2/auth/forgotpassword", user);
  33. if (signin.ok) {
  34. console.log("token", signin.data);
  35. setNotify("重置密码的邮件已经发送到您的邮箱。");
  36. message.success(
  37. intl.formatMessage({ id: "flashes.success" })
  38. );
  39. } else {
  40. message.error(signin.message);
  41. }
  42. }}
  43. >
  44. <ProForm.Group>
  45. <ProFormText
  46. width="md"
  47. name="email"
  48. required
  49. label={intl.formatMessage({
  50. id: "forms.fields.email.label",
  51. })}
  52. rules={[
  53. { required: true, type: "email", max: 255, min: 6 },
  54. ]}
  55. />
  56. </ProForm.Group>
  57. </ProForm>
  58. </>
  59. );
  60. };
  61. export default Widget;