File size: 9,402 Bytes
3392510
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Augment2Api - 登录</title>
    <link rel="icon" href="../static/augment.svg" type="image/svg+xml">
    <link rel="alternate icon" href="../static/augment.svg" type="image/x-icon">
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --success-color: #4caf50;
            --error-color: #f44336;
            --bg-color: #f8f9fa;
            --card-bg: #ffffff;
            --text-color: #333333;
            --border-color: #e0e0e0;
            --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            --radius: 12px;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'PingFang SC', 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
            background-color: var(--bg-color);
            color: var(--text-color);
            line-height: 1.6;
            padding: 20px;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            position: relative;
            overflow: hidden;
        }

        #bg-canvas {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: -1;
        }

        .login-container {
            width: 100%;
            max-width: 400px;
            background: var(--card-bg);
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            padding: 30px;
            margin-bottom: 20px;
        }

        h1 {
            font-size: 24px;
            font-weight: 600;
            color: black;
            text-align: center;
            margin-bottom: 20px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            text-align: center;
        }

        input[type="password"] {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid var(--border-color);
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        input[type="password"]:focus {
            border-color: var(--primary-color);
            outline: none;
        }

        button {
            display: block;
            width: 100%;
            padding: 12px;
            background-color: var(--primary-color);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        button:hover {
            background-color: var(--secondary-color);
        }

        .error-message {
            color: var(--error-color);
            margin-top: 15px;
            text-align: center;
            display: none;
        }

        footer {
            text-align: center;
            margin-top: 20px;
            color: #666;
            font-size: 14px;
        }

        footer a {
            color: var(--primary-color);
            text-decoration: none;
            transition: color 0.3s;
        }

        footer a:hover {
            color: var(--secondary-color);
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <canvas id="bg-canvas"></canvas>
    <div class="login-container">
        <h1>Augment面板登录</h1>
        <form id="login-form">
            <div class="form-group">
                <label for="password">访问密码</label>
                <input type="password" id="password" name="password" placeholder="请输入访问密码" required>
            </div>
            <button type="submit">登录</button>
            <div id="error-message" class="error-message">密码错误,请重试</div>
        </form>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const loginForm = document.getElementById('login-form');
            const errorMessage = document.getElementById('error-message');
            
            // 检查是否有错误消息参数
            const urlParams = new URLSearchParams(window.location.search);
            if (urlParams.get('error') === 'invalid_password') {
                errorMessage.style.display = 'block';
                errorMessage.textContent = '密码错误,请重试';
            } else if (urlParams.get('error') === 'token_expired') {
                errorMessage.style.display = 'block';
                errorMessage.textContent = '会话已过期,请重新登录';
            }
            
            // 背景动画
            const canvas = document.getElementById('bg-canvas');
            const ctx = canvas.getContext('2d');
            let width = window.innerWidth;
            let height = window.innerHeight;
            
            canvas.width = width;
            canvas.height = height;
            
            // 线条数量
            const lineCount = 15;
            const lines = [];
            
            // 创建线条
            for (let i = 0; i < lineCount; i++) {
                lines.push({
                    x: Math.random() * width,
                    y: Math.random() * height,
                    length: Math.random() * 100 + 50,
                    angle: Math.random() * Math.PI * 2,
                    speed: Math.random() * 0.5 + 0.1,
                    opacity: Math.random() * 0.2 + 0.1
                });
            }
            
            function drawLines() {
                ctx.clearRect(0, 0, width, height);
                
                for (let i = 0; i < lineCount; i++) {
                    const line = lines[i];
                    
                    ctx.beginPath();
                    ctx.moveTo(line.x, line.y);
                    ctx.lineTo(
                        line.x + Math.cos(line.angle) * line.length,
                        line.y + Math.sin(line.angle) * line.length
                    );
                    
                    ctx.strokeStyle = `rgba(67, 97, 238, ${line.opacity})`;
                    ctx.lineWidth = 1;
                    ctx.stroke();
                    
                    // 更新线条位置
                    line.x += Math.cos(line.angle) * line.speed;
                    line.y += Math.sin(line.angle) * line.speed;
                    
                    // 如果线条移出画布,重新放置
                    if (line.x < -line.length || line.x > width + line.length || 
                        line.y < -line.length || line.y > height + line.length) {
                        line.x = Math.random() * width;
                        line.y = Math.random() * height;
                        line.angle = Math.random() * Math.PI * 2;
                    }
                }
                
                requestAnimationFrame(drawLines);
            }
            
            drawLines();
            
            // 窗口大小变化时重新设置画布尺寸
            window.addEventListener('resize', function() {
                width = window.innerWidth;
                height = window.innerHeight;
                canvas.width = width;
                canvas.height = height;
            });
            
            loginForm.addEventListener('submit', function(e) {
                e.preventDefault();
                const password = document.getElementById('password').value;
                
                // 发送登录请求
                fetch('/api/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ password: password })
                })
                .then(response => response.json())
                .then(data => {
                    if (data.status === 'success') {
                        // 登录成功,保存会话到Cookie并跳转到管理页面
                        // 设置安全的Cookie,确保路径正确
                        document.cookie = "auth_token=" + data.token + "; path=/; max-age=86400;";
                        console.log("设置Cookie成功: auth_token=" + data.token);

                        setTimeout(() => {
                            window.location.href = '/admin';
                        }, 300);
                    } else {
                        // 显示错误消息
                        errorMessage.style.display = 'block';
                        errorMessage.textContent = data.error || '登录失败,请重试';
                    }
                })
                .catch(error => {
                    console.error('登录请求失败:', error);
                    errorMessage.style.display = 'block';
                    errorMessage.textContent = '网络错误,请重试';
                });
            });
        });
    </script>
</body>
</html>