Blame view

美国版/Food Labeling Management Platform/src/services/passwordResetService.ts 1.45 KB
ef6b3255   杨鑫   修改BUG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  import { ApiError, createApiClient } from "../lib/apiClient";
  
  const api = createApiClient();
  
  /**
   * 发送忘记密码邮箱验证码。
   * 预留路径:`POST /api/app/account/send-password-reset-code`(后端接入后对齐方法名与 DTO 即可)
   */
  export async function sendPasswordResetCode(email: string, signal?: AbortSignal): Promise<void> {
    try {
      await api.requestJson<unknown>({
        path: "/account/send-password-reset-code",
        method: "POST",
        body: { email },
        signal,
      });
    } catch (e) {
      if (e instanceof ApiError && (e.status === 404 || e.status === 501)) {
        throw new Error("Password reset is not available on the server yet. Please contact an administrator.");
      }
      throw e;
    }
  }
  
  /**
   * 验证码 + 新密码完成重置。
   * 预留路径:`POST /api/app/account/confirm-password-reset`
   */
  export async function confirmPasswordReset(
    input: { email: string; code: string; newPassword: string },
    signal?: AbortSignal,
  ): Promise<void> {
    try {
      await api.requestJson<unknown>({
        path: "/account/confirm-password-reset",
        method: "POST",
        body: {
          email: input.email,
          code: input.code,
          newPassword: input.newPassword,
        },
        signal,
      });
    } catch (e) {
      if (e instanceof ApiError && (e.status === 404 || e.status === 501)) {
        throw new Error("Password reset is not available on the server yet. Please contact an administrator.");
      }
      throw e;
    }
  }