github-actions[bot] commited on
Commit
8e1e21b
·
1 Parent(s): 3f6e692

Update from GitHub Actions

Browse files
functions/api/mail/login.ts ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { authApiToken, authMiddleware } from "../../utils/auth.js";
2
+ import { addCorsHeaders } from "../../utils/cors.js";
3
+ import { AuthService } from "../../utils/authService.js";
4
+
5
+ export const onRequest = async (context: RouteContext): Promise<Response> => {
6
+ const request = context.request;
7
+ const env: Env = context.env;
8
+
9
+ const authResponse = await authMiddleware(request, env);
10
+ const apiResponse = await authApiToken(request, env);
11
+ if (authResponse && apiResponse) {
12
+ return addCorsHeaders(authResponse);
13
+ }
14
+
15
+ try {
16
+ const { email } = await request.json() as any;
17
+ if (!email) {
18
+ throw new Error("Email is required");
19
+ }
20
+
21
+ const authService = new AuthService(env);
22
+ const result = await authService.authenticateEmail(email);
23
+
24
+ if (!result.success) {
25
+ throw new Error(result.error);
26
+ }
27
+
28
+ return new Response(
29
+ JSON.stringify({
30
+ success: true,
31
+ message: "邮箱登录成功"
32
+ }),
33
+ {
34
+ status: 200,
35
+ headers: {
36
+ 'Content-Type': 'application/json',
37
+ 'Access-Control-Allow-Origin': '*'
38
+ }
39
+ }
40
+ );
41
+
42
+ } catch (error: any) {
43
+ return new Response(
44
+ JSON.stringify({ error: error.message }),
45
+ {
46
+ status: 500,
47
+ headers: {
48
+ 'Content-Type': 'application/json',
49
+ 'Access-Control-Allow-Origin': '*'
50
+ }
51
+ }
52
+ );
53
+ }
54
+ };
src/services/mailApi.ts CHANGED
@@ -78,5 +78,17 @@ export const mailApi = {
78
  }
79
  );
80
  return handleResponse(response);
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
82
  };
 
78
  }
79
  );
80
  return handleResponse(response);
81
+ },
82
+
83
+ async loginMail(email: string) {
84
+ const response = await fetch(
85
+ `${API_BASE_URL}/api/mail/login`,
86
+ {
87
+ headers: getHeaders(),
88
+ method: 'POST',
89
+ body: JSON.stringify({ email })
90
+ }
91
+ );
92
+ return handleResponse(response);
93
  }
94
  };
src/views/MailView.vue CHANGED
@@ -35,6 +35,7 @@ const actionOptions = (row: Account) => [
35
  { content: '最新邮件', value: 'latest', onClick: () => handleLatestMails(row) },
36
  { content: '所有邮件', value: 'all', onClick: () => handleAllMails(row) },
37
  { content: '发送邮件', value: 'send', onClick: () => handleSendMail(row) },
 
38
  ];
39
 
40
  // 实现处理函数
@@ -257,6 +258,19 @@ const handleCheckAuth = async (row: Account) => {
257
  }
258
  };
259
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
 
261
  </script>
262
 
@@ -281,6 +295,7 @@ const handleCheckAuth = async (row: Account) => {
281
  <t-button size="small" variant="outline" @click="handleLatestMails(row)">最新邮件</t-button>
282
  <t-button size="small" variant="outline" @click="handleAllMails(row)">所有邮件</t-button>
283
  <t-button size="small" variant="outline" @click="handleSendMail(row)">发送邮件</t-button>
 
284
  </div>
285
 
286
  <!-- 移动端显示 -->
 
35
  { content: '最新邮件', value: 'latest', onClick: () => handleLatestMails(row) },
36
  { content: '所有邮件', value: 'all', onClick: () => handleAllMails(row) },
37
  { content: '发送邮件', value: 'send', onClick: () => handleSendMail(row) },
38
+ { content: '登录邮箱', value: 'login', onClick: () => handleLoginMail(row) },
39
  ];
40
 
41
  // 实现处理函数
 
258
  }
259
  };
260
 
261
+ // 添加登录邮箱处理函数
262
+ const handleLoginMail = async (row: Account) => {
263
+ try {
264
+ loading.value = true;
265
+ const result = await mailApi.loginMail(row.email);
266
+ MessagePlugin.success(`登录成功: ${result.message}`);
267
+ } catch (error: any) {
268
+ MessagePlugin.error(`登录失败: ${error.message}`);
269
+ } finally {
270
+ loading.value = false;
271
+ }
272
+ };
273
+
274
 
275
  </script>
276
 
 
295
  <t-button size="small" variant="outline" @click="handleLatestMails(row)">最新邮件</t-button>
296
  <t-button size="small" variant="outline" @click="handleAllMails(row)">所有邮件</t-button>
297
  <t-button size="small" variant="outline" @click="handleSendMail(row)">发送邮件</t-button>
298
+ <t-button size="small" variant="outline" @click="handleLoginMail(row)">登录邮箱</t-button>
299
  </div>
300
 
301
  <!-- 移动端显示 -->