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+
4
+ <head>
5
+ <base href="/">
6
+ <meta charset="utf-8">
7
+ <meta name="viewport" content="width=device-width, viewport-fit=cover, initial-scale=1, maximum-scale=1.0, user-scalable=no, interactive-widget=resizes-content">
8
+ <meta name="apple-mobile-web-app-capable" content="yes">
9
+ <meta name="mobile-web-app-capable" content="yes">
10
+ <meta name="darkreader-lock">
11
+ <meta name="robots" content="noindex, nofollow" />
12
+ <style>
13
+ /* Put critical CSS here. The rest should go in stylesheets. */
14
+ body {
15
+ background-color: rgb(36, 36, 37);
16
+ }
17
+
18
+ /* 嵌入login.css */
19
+ body.login #shadow_popup {
20
+ opacity: 1;
21
+ display: flex;
22
+ }
23
+
24
+ body.login {
25
+ background-color: rgb(36, 36, 37);
26
+ background-size: cover;
27
+ background-position: center center;
28
+ background-repeat: no-repeat;
29
+ background-attachment: fixed;
30
+ position: relative;
31
+ }
32
+
33
+ /* 添加半透明黑色遮罩提高文本可读性 */
34
+ body.login::before {
35
+ content: '';
36
+ position: fixed;
37
+ top: 0;
38
+ left: 0;
39
+ width: 100%;
40
+ height: 100%;
41
+ background-color: rgba(0, 0, 0, 0.5);
42
+ z-index: 0;
43
+ pointer-events: none;
44
+ }
45
+
46
+ /* 确保登录窗口在遮罩层上方 */
47
+ body.login #shadow_popup {
48
+ position: relative;
49
+ z-index: 1;
50
+ }
51
+
52
+ body.login .logo {
53
+ max-width: 30px;
54
+ }
55
+
56
+ body.login #logoBlock {
57
+ align-items: center;
58
+ margin: 0 auto;
59
+ gap: 10px;
60
+ }
61
+
62
+ body.login .userSelect {
63
+ display: flex;
64
+ flex-direction: column;
65
+ color: var(--SmartThemeBodyColor);
66
+ border: 1px solid var(--SmartThemeBorderColor);
67
+ border-radius: 5px;
68
+ padding: 3px 5px;
69
+ width: 30%;
70
+ cursor: pointer;
71
+ margin: 5px 0;
72
+ transition: background-color 0.15s ease-in-out;
73
+ display: flex;
74
+ align-items: center;
75
+ justify-content: center;
76
+ text-align: center;
77
+ overflow: hidden;
78
+ }
79
+
80
+ body.login .userSelect .userName,
81
+ body.login .userSelect .userHandle {
82
+ width: 100%;
83
+ overflow: hidden;
84
+ text-overflow: ellipsis;
85
+ white-space: nowrap;
86
+ }
87
+
88
+ body.login .userSelect:hover {
89
+ background-color: var(--black30a);
90
+ }
91
+
92
+ body.login #handleEntryBlock,
93
+ body.login #passwordEntryBlock,
94
+ body.login #passwordRecoveryBlock {
95
+ margin: 2px;
96
+ }
97
+
98
+ /* 友联区样式 */
99
+ #friend-links-bar {
100
+ position: fixed;
101
+ left: 0;
102
+ right: 0;
103
+ bottom: 0;
104
+ background-color: rgba(25, 25, 25, 0.95);
105
+ box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.5);
106
+ padding: 8px 0;
107
+ z-index: 9999;
108
+ text-align: center;
109
+ width: 100%;
110
+ }
111
+
112
+ .friend-links-title {
113
+ color: #ddd;
114
+ font-size: 14px;
115
+ margin-bottom: 5px;
116
+ font-weight: bold;
117
+ text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
118
+ }
119
+
120
+ .friend-links-container {
121
+ display: flex;
122
+ overflow-x: auto;
123
+ white-space: nowrap;
124
+ padding: 0 15px;
125
+ scrollbar-width: none; /* Firefox */
126
+ -ms-overflow-style: none; /* IE 和 Edge */
127
+ justify-content: center;
128
+ }
129
+
130
+ .friend-links-container::-webkit-scrollbar {
131
+ display: none; /* Chrome, Safari 和 Opera */
132
+ }
133
+
134
+ .friend-link {
135
+ display: inline-block;
136
+ margin: 0 8px;
137
+ padding: 5px 15px;
138
+ background-color: rgba(50, 50, 50, 0.7);
139
+ color: #fff;
140
+ text-decoration: none;
141
+ border-radius: 20px;
142
+ font-size: 13px;
143
+ transition: all 0.2s ease;
144
+ flex-shrink: 0;
145
+ }
146
+
147
+ .friend-link:hover {
148
+ background-color: rgba(70, 70, 70, 0.9);
149
+ transform: translateY(-2px);
150
+ }
151
+
152
+ .mobile-hint {
153
+ font-size: 10px;
154
+ color: rgba(200, 200, 200, 0.5);
155
+ margin-top: 5px;
156
+ font-style: italic;
157
+ }
158
+
159
+ /* 确保页面底部有足够空间不被友联遮挡 */
160
+ body.login {
161
+ padding-bottom: 80px;
162
+ }
163
+
164
+ /* 公告滚动区域样式 */
165
+ .announcement-container {
166
+ width: 100%;
167
+ overflow: hidden;
168
+ margin: 8px 0;
169
+ position: relative;
170
+ border-radius: 4px;
171
+ background-color: rgba(50, 50, 50, 0.4);
172
+ padding: 6px 0;
173
+ }
174
+
175
+ .announcement-container marquee {
176
+ color: #ff3333;
177
+ font-size: 14px;
178
+ padding: 0 5px;
179
+ font-weight: bold;
180
+ text-transform: uppercase;
181
+ letter-spacing: 0.5px;
182
+ text-shadow: 0 0 2px rgba(255, 0, 0, 0.3);
183
+ }
184
+
185
+ @keyframes scroll-announcement {
186
+ 0% { transform: translateX(100%); }
187
+ 100% { transform: translateX(-100%); }
188
+ }
189
+
190
+ /* 暂停滚动当鼠标悬停 - 由marquee的onmouseover属性处理 */
191
+
192
+ /* 移动设备适配 */
193
+ @media (max-width: 768px) {
194
+ .friend-links-container {
195
+ justify-content: flex-start;
196
+ padding: 0 10px;
197
+ }
198
+
199
+ .friend-link {
200
+ margin: 0 5px;
201
+ padding: 4px 10px;
202
+ font-size: 12px;
203
+ }
204
+
205
+ .friend-links-title {
206
+ font-size: 12px;
207
+ margin-bottom: 3px;
208
+ }
209
+
210
+ #friend-links-bar {
211
+ padding: 5px 0;
212
+ }
213
+
214
+ body.login {
215
+ padding-bottom: 70px;
216
+ }
217
+ }
218
+
219
+ /* 小屏幕设备适配 */
220
+ @media (max-width: 480px) {
221
+ .friend-link {
222
+ margin: 0 3px;
223
+ padding: 3px 8px;
224
+ font-size: 11px;
225
+ }
226
+
227
+ .mobile-hint {
228
+ font-size: 9px;
229
+ }
230
+ }
231
+ </style>
232
+ <link rel="preload" as="style" href="style.css">
233
+ <link rel="apple-touch-icon" sizes="57x57" href="img/apple-icon-57x57.png" />
234
+ <link rel="apple-touch-icon" sizes="72x72" href="img/apple-icon-72x72.png" />
235
+ <link rel="apple-touch-icon" sizes="114x114" href="img/apple-icon-114x114.png" />
236
+ <link rel="apple-touch-icon" sizes="144x144" href="img/apple-icon-144x144.png" />
237
+ <link rel="icon" href="favicon.ico" type="image/x-icon">
238
+ <link rel="stylesheet" type="text/css" href="style.css">
239
+ <link rel="stylesheet" type="text/css" href="css/st-tailwind.css">
240
+ <!-- 移除 login.css 的引用,因为它已经内联到页面中 -->
241
+ <link rel="manifest" crossorigin="use-credentials" href="manifest.json">
242
+ <link href="webfonts/NotoSans/stylesheet.css" rel="stylesheet">
243
+ <link href="webfonts/NotoSansMono/stylesheet.css" rel="stylesheet">
244
+ <!-- fontawesome webfonts-->
245
+ <link href="css/fontawesome.min.css" rel="stylesheet">
246
+ <link href="css/solid.min.css" rel="stylesheet">
247
+ <link href="css/user.css" rel="stylesheet">
248
+ <title>[柒蓝-公益]云酒馆9号</title>
249
+ </head>
250
+
251
+ <body class="login">
252
+ <div id="shadow_popup" style="opacity: 0;">
253
+ <div id="dialogue_popup">
254
+ <div id="dialogue_popup_holder">
255
+ <div id="dialogue_popup_text">
256
+ <div id="userSelectBlock" class="flex-container flexFlowColumn alignItemsCenter">
257
+ <h2 id="logoBlock" class="flex-container">
258
+ <img src="img/logo.png" alt="SillyTavern" class="logo">
259
+ <span>[柒蓝-公益]云酒馆9号</span>
260
+ </h2>
261
+ <div class="announcement-container">
262
+ <marquee id="announcementText" scrollamount="4" behavior="scroll" direction="left" onmouseover="this.stop();" onmouseout="this.start();">
263
+ 本云酒馆由谷歌colab机子搭建时间到期会换机子接力运行| 请注意接力-时间段 | 防止过载最多支持200个用户注册 | 且用且珍惜吧
264
+ </marquee>
265
+ </div>
266
+ <div id="userListBlock" class="wide100p">
267
+ <div id="userList" class="flex-container justifySpaceEvenly"></div>
268
+ <div id="handleEntryBlock" style="display:none;" class="flex-container flexFlowColumn alignItemsCenter">
269
+ <input id="userHandle" class="text_pole" type="text" placeholder="QQ" autocomplete="username" >
270
+ </div>
271
+ <div id="passwordEntryBlock" style="display:none;"
272
+ class="flex-container flexFlowColumn alignItemsCenter">
273
+ <input id="userPassword" class="text_pole" type="password" placeholder="密码" autocomplete="current-password">
274
+ <a id="recoverPassword" href="#" onclick="return false;">忘记密码请联系管理员</a>
275
+ <div class="flex-container">
276
+ <div id="loginButton" class="menu_button" style="white-space: nowrap;">登录</div>
277
+ </div>
278
+ </div>
279
+ <div id="passwordRecoveryBlock" style="display:none;" class="flex-container flexFlowColumn alignItemsCenter">
280
+ <div id="recoverMessage">
281
+ Recovery code has been posted to the server console.
282
+ </div>
283
+ <input id="recoveryCode" class="text_pole" type="text" placeholder="Recovery code">
284
+ <input id="newPassword" class="text_pole" type="password" placeholder="New password" autocomplete="new-password">
285
+ <div class="flex-container flexGap10">
286
+ <div id="sendRecovery" class="menu_button">Send</div>
287
+ <div id="cancelRecovery" class="menu_button">Cancel</div>
288
+ </div>
289
+ </div>
290
+ <div id="registerBlock" style="display:none;" class="flex-container flexFlowColumn alignItemsCenter">
291
+ <input id="registerHandle" class="text_pole" type="text" placeholder="QQ" autocomplete="username">
292
+ <input id="registerPassword" class="text_pole" type="password" placeholder="密码" autocomplete="new-password">
293
+ <input id="registerConfirm" class="text_pole" type="password" placeholder="确认密码" autocomplete="new-password">
294
+ <div class="flex-container">
295
+ <div id="registerButton" class="menu_button" style="white-space: nowrap;">注册</div>
296
+ <div id="backToLogin" class="menu_button" style="white-space: nowrap;">返回登录</div>
297
+ </div>
298
+ </div>
299
+ <div class="flex-container justifySpaceEvenly" style="white-space: nowrap;">
300
+ <div id="showRegister" class="menu_button">注册账号</div>
301
+ </div>
302
+ <div id="serverUptime" style="color: #888; font-size: 13px; margin-top: 10px; text-align: center;">
303
+ </div>
304
+ </div>
305
+
306
+ <div class="neutral_warning" id="errorMessage">
307
+ </div>
308
+ <div id="userCount" class="neutral_warning" style="color: #888; font-size: 12px; margin-top: 5px; text-align: center;">
309
+ </div>
310
+
311
+ <div>
312
+ 接力时间[2025-08-09 11:45:54]
313
+ </div>
314
+ <div>
315
+ IP[35.185.53.73] 国家[美国] IPS[XX]
316
+ </div>
317
+
318
+ </div>
319
+ </div>
320
+ </div>
321
+ </div>
322
+ </div>
323
+
324
+ <!-- 友联导航区 - 页面底部固定位置 -->
325
+ <div id="friend-links-bar">
326
+ <div class="friend-links-title">所有公益酒馆</div>
327
+ <div class="friend-links-container">
328
+ <a href="http://st.ql66.ggff.net:7070" class="friend-link">1号酒馆</a>
329
+ <a href="http://st.ql66.ggff.net:7073" class="friend-link">2号酒馆</a>
330
+ <a href="https://ka.282820.xyz/" class="friend-link">角色卡分享</a>
331
+ <a href="http://st.ql66.ggff.net:7076" class="friend-link">3号酒馆</a>
332
+ <a href="http://st.ql66.ggff.net:7078" class="friend-link">4号酒馆</a>
333
+ <a href="http://st.ql66.ggff.net:7080" class="friend-link">5号酒馆</a>
334
+ <a href="http://st.ql66.ggff.net:7082" class="friend-link">6号酒馆</a>
335
+ <a href="http://st.ql66.ggff.net:7084" class="friend-link">7号酒馆</a>
336
+ <!-- <a href="#" class="friend-link">7号酒馆</a>
337
+ <a href="#" class="friend-link">8号酒馆</a> -->
338
+ </div>
339
+ <div class="mobile-hint">← 左右滑动查看更多 →</div>
340
+ </div>
341
+
342
+ <script src="lib/jquery-3.5.1.min.js"></script>
343
+ <!-- 嵌入login2.js -->
344
+ <script>
345
+ /**
346
+ * CRSF token for requests.
347
+ */
348
+ let csrfToken = '';
349
+ let discreetLogin = false;
350
+
351
+ /**
352
+ * Gets a CSRF token from the server.
353
+ * @returns {Promise<string>} CSRF token
354
+ */
355
+ async function getCsrfToken() {
356
+ const response = await fetch('/csrf-token');
357
+ const data = await response.json();
358
+ return data.token;
359
+ }
360
+
361
+ /**
362
+ * Gets a list of users from the server.
363
+ * @returns {Promise<object>} List of users
364
+ */
365
+ async function getUserList() {
366
+ const response = await fetch('/api/users/list', {
367
+ method: 'POST',
368
+ headers: {
369
+ 'Content-Type': 'application/json',
370
+ 'X-CSRF-Token': csrfToken,
371
+ },
372
+ });
373
+
374
+ if (!response.ok) {
375
+ const errorData = await response.json();
376
+ return displayError(errorData.error || '发生错误');
377
+ }
378
+
379
+ if (response.status === 204) {
380
+ discreetLogin = true;
381
+ return [];
382
+ }
383
+
384
+ const userListObj = await response.json();
385
+ console.log(userListObj);
386
+ return userListObj;
387
+ }
388
+
389
+ /**
390
+ * Requests a recovery code for the user.
391
+ * @param {string} handle User handle
392
+ * @returns {Promise<void>}
393
+ */
394
+ async function sendRecoveryPart1(handle) {
395
+ const response = await fetch('/api/users/recover-step1', {
396
+ method: 'POST',
397
+ headers: {
398
+ 'Content-Type': 'application/json',
399
+ 'X-CSRF-Token': csrfToken,
400
+ },
401
+ body: JSON.stringify({ handle }),
402
+ });
403
+
404
+ if (!response.ok) {
405
+ const errorData = await response.json();
406
+ return displayError(errorData.error || '发生错误');
407
+ }
408
+
409
+ showRecoveryBlock();
410
+ }
411
+
412
+ /**
413
+ * Sets a new password for the user using the recovery code.
414
+ * @param {string} handle User handle
415
+ * @param {string} code Recovery code
416
+ * @param {string} newPassword New password
417
+ * @returns {Promise<void>}
418
+ */
419
+ async function sendRecoveryPart2(handle, code, newPassword) {
420
+ const recoveryData = {
421
+ handle,
422
+ code,
423
+ newPassword,
424
+ };
425
+
426
+ const response = await fetch('/api/users/recover-step2', {
427
+ method: 'POST',
428
+ headers: {
429
+ 'Content-Type': 'application/json',
430
+ 'X-CSRF-Token': csrfToken,
431
+ },
432
+ body: JSON.stringify(recoveryData),
433
+ });
434
+
435
+ if (!response.ok) {
436
+ const errorData = await response.json();
437
+ return displayError(errorData.error || '发生错误');
438
+ }
439
+
440
+ console.log(`密码恢复成功: ${handle}!`);
441
+ await performLogin(handle, newPassword);
442
+ }
443
+
444
+ /**
445
+ * Attempts to log in the user.
446
+ * @param {string} handle User's handle
447
+ * @param {string} password User's password
448
+ * @returns {Promise<void>}
449
+ */
450
+ async function performLogin(handle, password) {
451
+ const userInfo = {
452
+ handle: handle,
453
+ password: password,
454
+ };
455
+
456
+ try {
457
+ const response = await fetch('/api/users/login', {
458
+ method: 'POST',
459
+ headers: {
460
+ 'Content-Type': 'application/json',
461
+ 'X-CSRF-Token': csrfToken,
462
+ },
463
+ body: JSON.stringify(userInfo),
464
+ });
465
+
466
+ if (!response.ok) {
467
+ const errorData = await response.json();
468
+ return displayError(errorData.error || '发生错误');
469
+ }
470
+
471
+ const data = await response.json();
472
+
473
+ if (data.handle) {
474
+ console.log(`登录成功: ${handle}!`);
475
+ redirectToHome();
476
+ }
477
+ } catch (error) {
478
+ console.error('登录失败:', error);
479
+ displayError(String(error));
480
+ }
481
+ }
482
+
483
+ /**
484
+ * 处理用户注册
485
+ * @param {string} handle 用户QQ号
486
+ * @param {string} password 密码
487
+ * @param {string} confirmPassword 确认密码
488
+ * @returns {Promise<void>}
489
+ */
490
+ async function performRegister(handle, password, confirmPassword) {
491
+
492
+ if (!handle) {
493
+ return displayError('QQ号不能为空');
494
+ }
495
+ // 验证用户名格式:只能是数字,长度6-13位
496
+ if (!/^\d{6,13}$/.test(handle)) {
497
+ return displayError('用户名只能是6-13位的数字');
498
+ }
499
+
500
+ if (!password) {
501
+ return displayError('密码不能为空');
502
+ }
503
+
504
+ if (password !== confirmPassword) {
505
+ return displayError('两次输入的密码不一致');
506
+ }
507
+
508
+ // 检查当前用户数量
509
+ try {
510
+ const countResponse = await fetch('/api/users-internal/count', {
511
+ headers: {
512
+ 'Content-Type': 'application/json',
513
+ 'X-CSRF-Token': csrfToken
514
+ }
515
+ });
516
+
517
+ if (countResponse.ok) {
518
+ const countData = await countResponse.json();
519
+ if (countData.totalCount >= 200) {
520
+ return displayError('系统已达到最大用户数限制(200),暂停注册');
521
+ }
522
+ }
523
+ } catch (error) {
524
+ console.error('检查用户数量失败:', error);
525
+ // 继续注册流程,因为这只是一个预检查
526
+ }
527
+
528
+ const userInfo = {
529
+ handle: handle,
530
+ name: handle, // 使用handle作为name
531
+ password: password
532
+ };
533
+
534
+ try {
535
+ const response = await fetch('/api/users-internal/create', {
536
+ method: 'POST',
537
+ headers: {
538
+ 'Content-Type': 'application/json',
539
+ 'X-CSRF-Token': csrfToken
540
+ },
541
+ body: JSON.stringify(userInfo)
542
+ });
543
+
544
+ if (!response.ok) {
545
+ const errorData = await response.json();
546
+ return displayError(errorData.error || '注册失败');
547
+ }
548
+
549
+ const data = await response.json();
550
+
551
+ if (data.handle) {
552
+ console.log(`注册成功: ${handle}!`);
553
+ // 注册成功后自动登录
554
+ await performLogin(handle, password);
555
+ }
556
+ } catch (error) {
557
+ console.error('注册失败:', error);
558
+ displayError(String(error));
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Handles the user selection event.
564
+ * @param {object} user User object
565
+ * @returns {Promise<void>}
566
+ */
567
+ async function onUserSelected(user) {
568
+ // No password, just log in
569
+ if (!user.password) {
570
+ return await performLogin(user.handle, '');
571
+ }
572
+
573
+ $('#passwordRecoveryBlock').hide();
574
+ $('#passwordEntryBlock').show();
575
+ $('#loginButton').off('click').on('click', async () => {
576
+ const password = String($('#userPassword').val());
577
+ await performLogin(user.handle, password);
578
+ });
579
+
580
+ $('#recoverPassword').off('click').on('click', async () => {
581
+ await sendRecoveryPart1(user.handle);
582
+ });
583
+
584
+ $('#sendRecovery').off('click').on('click', async () => {
585
+ const code = String($('#recoveryCode').val());
586
+ const newPassword = String($('#newPassword').val());
587
+ await sendRecoveryPart2(user.handle, code, newPassword);
588
+ });
589
+
590
+ displayError('');
591
+ }
592
+
593
+ /**
594
+ * Displays an error message to the user.
595
+ * @param {string} message Error message
596
+ */
597
+ function displayError(message) {
598
+ $('#errorMessage').text(message);
599
+ }
600
+
601
+ /**
602
+ * Redirects the user to the home page.
603
+ * Preserves the query string.
604
+ */
605
+ function redirectToHome() {
606
+ // After a login theres no need to preserve the
607
+ // noauto (if present)
608
+ const urlParams = new URLSearchParams(window.location.search);
609
+
610
+ urlParams.delete('noauto');
611
+
612
+ window.location.href = '/' + urlParams.toString();
613
+ }
614
+
615
+ /**
616
+ * Hides the password entry block and shows the password recovery block.
617
+ */
618
+ function showRecoveryBlock() {
619
+ $('#passwordEntryBlock').hide();
620
+ $('#passwordRecoveryBlock').show();
621
+ displayError('');
622
+ }
623
+
624
+ /**
625
+ * Hides the password recovery block and shows the password entry block.
626
+ */
627
+ function onCancelRecoveryClick() {
628
+ $('#passwordRecoveryBlock').hide();
629
+ $('#passwordEntryBlock').show();
630
+ displayError('');
631
+ }
632
+
633
+ /**
634
+ * 显示注册表单
635
+ */
636
+ async function showRegisterForm() {
637
+ // 检查用户数量,如果已达到500用户,则显示错误信息而不显示注册表单
638
+ try {
639
+ const countResponse = await fetch('/api/users-internal/count', {
640
+ headers: {
641
+ 'Content-Type': 'application/json',
642
+ 'X-CSRF-Token': csrfToken
643
+ }
644
+ });
645
+
646
+ if (countResponse.ok) {
647
+ const countData = await countResponse.json();
648
+ if (countData.totalCount >= 200) {
649
+ return displayError('系统已达到最大用户数限制(200),暂停注册');
650
+ }
651
+ }
652
+ } catch (error) {
653
+ console.error('检查用户数量失败:', error);
654
+ // 继续显示注册表单,因为这只是一个预检查
655
+ }
656
+
657
+ $('#registerBlock').show();
658
+ $('#userListBlock > div:not(#registerBlock)').hide();
659
+ displayError('');
660
+ }
661
+
662
+ /**
663
+ * 返回登录页面
664
+ */
665
+ function backToLoginForm() {
666
+ $('#registerBlock').hide();
667
+
668
+ if (discreetLogin) {
669
+ configureDiscreetLogin();
670
+ } else {
671
+ $('#userList').show();
672
+ $('#handleEntryBlock').hide();
673
+ $('#passwordEntryBlock').hide();
674
+ }
675
+
676
+ displayError('');
677
+ }
678
+
679
+ /**
680
+ * Configures the login page for normal login.
681
+ * @param {import('../../src/users').UserViewModel[]} userList List of users
682
+ */
683
+ function configureNormalLogin(userList) {
684
+ console.log('Discreet login is disabled');
685
+ $('#handleEntryBlock').hide();
686
+ $('#normalLoginPrompt').show();
687
+ $('#discreetLoginPrompt').hide();
688
+ $('#registerBlock').hide();
689
+ console.log(userList);
690
+ for (const user of userList) {
691
+ const userBlock = $('<div></div>').addClass('userSelect');
692
+ const avatarBlock = $('<div></div>').addClass('avatar');
693
+ avatarBlock.append($('<img>').attr('src', user.avatar || 'img/default-avatar.png'));
694
+ userBlock.append(avatarBlock);
695
+ userBlock.append($('<span></span>').addClass('userName').text(user.name));
696
+ userBlock.append($('<small></small>').addClass('userHandle').text(user.handle));
697
+ userBlock.on('click', () => onUserSelected(user));
698
+ $('#userList').append(userBlock);
699
+ }
700
+ }
701
+
702
+ /**
703
+ * Configures the login page for discreet login.
704
+ */
705
+ function configureDiscreetLogin() {
706
+ console.log('Discreet login is enabled');
707
+ $('#handleEntryBlock').show();
708
+ $('#normalLoginPrompt').hide();
709
+ $('#discreetLoginPrompt').show();
710
+ $('#userList').hide();
711
+ $('#passwordRecoveryBlock').hide();
712
+ $('#passwordEntryBlock').show();
713
+ $('#registerBlock').hide();
714
+ $('#loginButton').off('click').on('click', async () => {
715
+ const handle = String($('#userHandle').val());
716
+ const password = String($('#userPassword').val());
717
+ await performLogin(handle, password);
718
+ });
719
+
720
+ $('#recoverPassword').off('click').on('click', async () => {
721
+ const handle = String($('#userHandle').val());
722
+ await sendRecoveryPart1(handle);
723
+ });
724
+
725
+ $('#sendRecovery').off('click').on('click', async () => {
726
+ const handle = String($('#userHandle').val());
727
+ const code = String($('#recoveryCode').val());
728
+ const newPassword = String($('#newPassword').val());
729
+ await sendRecoveryPart2(handle, code, newPassword);
730
+ });
731
+ }
732
+
733
+ /**
734
+ * 初始化友联滑动功能
735
+ */
736
+ function initFriendLinks() {
737
+ try {
738
+ const container = document.querySelector('.friend-links-container');
739
+
740
+ if (!container) {
741
+ console.log('友联容器未找到');
742
+ return;
743
+ }
744
+
745
+ // 检测是否为移动设备
746
+ const isMobile = window.innerWidth <= 768;
747
+
748
+ // 如果不是移动设备,触发一次自动滚动以显示所有链接
749
+ if (!isMobile && container.scrollWidth > container.clientWidth) {
750
+ let scrollPos = 0;
751
+ const maxScroll = container.scrollWidth - container.clientWidth;
752
+ const scrollInterval = setInterval(() => {
753
+ scrollPos += 1;
754
+ container.scrollLeft = scrollPos;
755
+
756
+ if (scrollPos >= maxScroll) {
757
+ clearInterval(scrollInterval);
758
+ setTimeout(() => {
759
+ container.scrollTo({
760
+ left: 0,
761
+ behavior: 'smooth'
762
+ });
763
+ }, 500);
764
+ }
765
+ }, 15);
766
+
767
+ // 最多滚动3秒
768
+ setTimeout(() => {
769
+ clearInterval(scrollInterval);
770
+ }, 3000);
771
+ }
772
+
773
+ console.log('友联滑动功能初始化完成');
774
+ } catch (error) {
775
+ console.error('初始化友联滑动功能时出错:', error);
776
+ }
777
+ }
778
+
779
+ // 初始化函数
780
+ (async function () {
781
+ csrfToken = await getCsrfToken();
782
+ const userList = await getUserList();
783
+
784
+ if (discreetLogin) {
785
+ configureDiscreetLogin();
786
+ } else {
787
+ configureNormalLogin(userList);
788
+ }
789
+
790
+ // 显示页面
791
+ document.getElementById('shadow_popup').style.opacity = '';
792
+
793
+ // 绑定事件处理函数
794
+ $('#cancelRecovery').on('click', onCancelRecoveryClick);
795
+ $('#showRegister').on('click', async () => {
796
+ await showRegisterForm();
797
+ });
798
+ $('#backToLogin').on('click', backToLoginForm);
799
+
800
+ // 注册按钮点击事件
801
+ $('#registerButton').on('click', async () => {
802
+ const handle = String($('#registerHandle').val());
803
+ const password = String($('#registerPassword').val());
804
+ const confirmPassword = String($('#registerConfirm').val());
805
+ await performRegister(handle, password, confirmPassword);
806
+ });
807
+
808
+ // 键盘事件处理
809
+ $(document).on('keydown', (evt) => {
810
+ if (evt.key === 'Enter' && document.activeElement.tagName === 'INPUT') {
811
+ if ($('#passwordRecoveryBlock').is(':visible')) {
812
+ $('#sendRecovery').trigger('click');
813
+ } else if ($('#registerBlock').is(':visible')) {
814
+ $('#registerButton').trigger('click');
815
+ } else {
816
+ $('#loginButton').trigger('click');
817
+ }
818
+ }
819
+ });
820
+
821
+ // 查询总用户数量
822
+ try {
823
+ // console.log('正在获取用户总数...');
824
+
825
+ // 使用专门的API获取用户总数
826
+ const countResponse = await fetch('/api/users-internal/count', {
827
+ headers: {
828
+ 'Content-Type': 'application/json',
829
+ 'X-CSRF-Token': csrfToken
830
+ }
831
+ });
832
+
833
+ // console.log('用户总数API响应状态:', countResponse.status);
834
+
835
+ // 确保DOM元素存在
836
+ const userCountElement = document.getElementById('userCount');
837
+
838
+ if (countResponse.ok) {
839
+ // API成功
840
+ const countData = await countResponse.json();
841
+ // console.log('获取到的用户总数数据:', countData);
842
+ const totalUsers = countData.totalCount;
843
+ // console.log('总用户数:', totalUsers);
844
+
845
+ if (userCountElement) {
846
+ // 显示用户统计信息
847
+ userCountElement.textContent = `总用户数: ${totalUsers}/200`;
848
+
849
+ // 如果用户数量接近上限,添加警告样式
850
+ if (totalUsers >= 450) {
851
+ userCountElement.style.color = '#FF3333';
852
+ userCountElement.style.fontWeight = 'bold';
853
+
854
+ // 如果已达到500用户,隐藏注册按钮
855
+ if (totalUsers >= 200) {
856
+ $('#showRegister').hide();
857
+ displayError('已达到最大用户数限制(200),暂停注册');
858
+ }
859
+ }
860
+
861
+ // console.log('已更新用户数量显示');
862
+ } else {
863
+ console.error('找不到 userCount 元素');
864
+ }
865
+ } else {
866
+ console.warn('用户总数API访问受限,显示错误信息');
867
+ if (userCountElement) {
868
+ userCountElement.textContent = '无法获取用户总数';
869
+ }
870
+ }
871
+ } catch (error) {
872
+ console.error('获取用户数量失败:', error);
873
+ const userCountElement = document.getElementById('userCount');
874
+ if (userCountElement) {
875
+ userCountElement.textContent = '获取用户数量失败';
876
+ }
877
+ }
878
+
879
+ // 初始化友联滑动功能
880
+ initFriendLinks();
881
+ })();
882
+
883
+ // 确保DOM完全加载后初始化友联滑动功能
884
+ document.addEventListener('DOMContentLoaded', function() {
885
+ setTimeout(initFriendLinks, 1000);
886
+ });
887
+ </script>
888
+ <script>
889
+ /**
890
+ * 登录页面背景图片加载
891
+ */
892
+ document.addEventListener('DOMContentLoaded', function() {
893
+ // 已知存在的背景图片 - 从实际文件夹中找到的
894
+ const bgImages = [
895
+ 'img/bg/1.jpg',
896
+ 'img/bg/2.jpg',
897
+ 'img/bg/3.jpg',
898
+ 'img/bg/4.jpg',
899
+ 'img/bg/5.jpg',
900
+ 'img/bg/6.jpg',
901
+ 'img/bg/7.jpg',
902
+ 'img/bg/8.jpg',
903
+ 'img/bg/9.jpg',
904
+ 'img/bg/10.jpg',
905
+ 'img/bg/11.jpg',
906
+ 'img/bg/12.jpg',
907
+ 'img/bg/13.jpg',
908
+ 'img/bg/14.jpg',
909
+ 'img/bg/15.jpg',
910
+ 'img/bg/16.jpg',
911
+ 'img/bg/17.jpg',
912
+ 'img/bg/18.jpg'
913
+ ];
914
+
915
+ /**
916
+ * 设置随机背景图片
917
+ */
918
+ function setRandomBackground() {
919
+ if (bgImages.length === 0) return;
920
+
921
+ // 随机选择一张图片
922
+ const randomIndex = Math.floor(Math.random() * bgImages.length);
923
+ const selectedImage = bgImages[randomIndex];
924
+
925
+ // 加载图片并设置为背景
926
+ const img = new Image();
927
+ img.onload = function() {
928
+ document.body.style.backgroundImage = `url('${selectedImage}')`;
929
+ console.log(`背景图片已设置: ${selectedImage}`);
930
+ };
931
+
932
+ img.onerror = function() {
933
+ console.warn(`背景图片加载失败: ${selectedImage}`);
934
+
935
+ // 从列表中移除无效图片
936
+ bgImages.splice(randomIndex, 1);
937
+
938
+ if (bgImages.length > 0) {
939
+ // 尝试下一张图片
940
+ setRandomBackground();
941
+ } else {
942
+ console.error('所有背景图片加载失败');
943
+ document.body.style.backgroundImage = 'none';
944
+ }
945
+ };
946
+
947
+ img.src = selectedImage;
948
+ }
949
+
950
+ // 调用函数设置随机背景
951
+ setRandomBackground();
952
+ });
953
+ </script>
954
+ </body>
955
+
956
+ </html>