@ian2018cs/agenthub 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/index-CwlbfX7i.js +154 -0
- package/dist/assets/{vendor-icons-CFcMTcKT.js → vendor-icons-_JvlqdUe.js} +71 -66
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/server/database/db.js +20 -0
- package/server/routes/admin.js +40 -0
- package/server/routes/auth.js +42 -0
- package/dist/assets/index-DHFbmwe2.js +0 -154
package/server/routes/auth.js
CHANGED
|
@@ -216,6 +216,48 @@ router.post('/logout', authenticateToken, (req, res) => {
|
|
|
216
216
|
res.json({ success: true, message: 'Logged out successfully' });
|
|
217
217
|
});
|
|
218
218
|
|
|
219
|
+
// Change password (for password-login users)
|
|
220
|
+
router.patch('/change-password', authenticateToken, async (req, res) => {
|
|
221
|
+
try {
|
|
222
|
+
const { current_password, new_password } = req.body;
|
|
223
|
+
|
|
224
|
+
// Validate parameters
|
|
225
|
+
if (!current_password || !new_password) {
|
|
226
|
+
return res.status(400).json({ error: '当前密码和新密码不能为空' });
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (new_password.length < 6) {
|
|
230
|
+
return res.status(400).json({ error: '新密码至少需要6个字符' });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Get user with password hash
|
|
234
|
+
const user = userDb.getUserByIdWithPassword(req.user.id);
|
|
235
|
+
|
|
236
|
+
// Verify this is a password-login user
|
|
237
|
+
if (!user || !user.password_hash) {
|
|
238
|
+
return res.status(400).json({ error: '您的账户不支持密码修改' });
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Verify current password
|
|
242
|
+
const isValid = await bcrypt.compare(current_password, user.password_hash);
|
|
243
|
+
if (!isValid) {
|
|
244
|
+
return res.status(401).json({ error: '当前密码错误' });
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Hash new password
|
|
248
|
+
const saltRounds = 12;
|
|
249
|
+
const passwordHash = await bcrypt.hash(new_password, saltRounds);
|
|
250
|
+
|
|
251
|
+
// Update database
|
|
252
|
+
userDb.updateUserPassword(user.id, passwordHash);
|
|
253
|
+
|
|
254
|
+
res.json({ success: true, message: '密码修改成功' });
|
|
255
|
+
} catch (error) {
|
|
256
|
+
console.error('Error changing password:', error);
|
|
257
|
+
res.status(500).json({ error: '修改密码失败' });
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
219
261
|
// Get current user's spending limit status
|
|
220
262
|
router.get('/limit-status', authenticateToken, (req, res) => {
|
|
221
263
|
try {
|