MCPcopy Create free account
hub / github.com/PIKACHUIM/CFWorkerACME / sendMailCode

Function sendMailCode

frontend/src/api/auth.ts:19–54  ·  view source on GitHub ↗
(
  email: string,
  authyToken: string,
  mode: 'register' | 'reset',
  inviteCode?: string,
)

Source from the content-addressed store, hash-verified

17 * @param inviteCode 仅在注册路径使用,当 REGISTER_CODE 非空时必填
18 */
19export async function sendMailCode(
20 email: string,
21 authyToken: string,
22 mode: 'register' | 'reset',
23 inviteCode?: string,
24): Promise<string> {
25 const params = new URLSearchParams();
26 params.set('email', email);
27 params.set('authy', authyToken);
28 if (mode === 'register') {
29 params.set('setup', '1');
30 if (inviteCode) params.set('invite', inviteCode);
31 } else {
32 params.set('reset', '1');
33 }
34
35 const url = `/nonce/?${params.toString()}`;
36 const res = await http.get<NonceResp>(url);
37
38 // 识别失败:
39 // 1) 后端明确返回 flags === 1 表示业务失败(邮件发送失败 / 未配置等)
40 // 2) 兜底:nonce 文案以"失败/异常/错误/未配置/已经被注册/请先完成验证"等字样出现时也抛错,
41 // 避免后端漏设 flags 时前端误判成功
42 const data: any = res.data || {};
43 if (data.flags === 1) {
44 throw new Error(data.nonce || data.texts || '发送验证码失败');
45 }
46 if (data.flags !== 0 && data.flags !== undefined) {
47 throw new Error(data.texts || data.nonce || '发送验证码失败');
48 }
49 const nonceText: string = String(data.nonce ?? '');
50 if (/(失败|异常|错误|未配置|已经被注册|请先完成验证|请等|未开放|邀请码)/.test(nonceText)) {
51 throw new Error(nonceText);
52 }
53 return nonceText;
54}
55
56/**
57 * 登录:返回 true 表示成功(后端会写入 Cookie)

Callers 1

handleSendCodeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected