v1.0.0提交

This commit is contained in:
2026-03-31 15:54:32 +08:00
parent 79bfeb0e18
commit 314e53bf9c
16 changed files with 2110 additions and 1 deletions

123
profile.php Normal file
View File

@@ -0,0 +1,123 @@
<?php
/**
* PerToolBox Front - 个人中心
*
* Copyright (C) 2024 Sea Network Technology Studio
* Author: Canglan <admin@sea-studio.top>
* License: AGPL v3
*/
require_once 'config.php';
include_once 'header.php';
include_once 'sidebar.php';
// 检查登录状态(前端 JS 会处理跳转)
?>
<div class="main-content">
<div class="max-w-2xl mx-auto">
<div class="card">
<h1 class="text-2xl font-bold mb-6">👤 个人中心</h1>
<div id="userProfile">
<div class="text-center py-8">
<div class="loading mx-auto"></div>
<p class="mt-2 text-gray-500">加载中...</p>
</div>
</div>
</div>
<div class="card mt-4">
<h2 class="text-xl font-bold mb-4">修改密码</h2>
<div class="mb-4">
<label class="form-label">原密码</label>
<input type="password" id="oldPassword" class="form-input">
</div>
<div class="mb-4">
<label class="form-label">新密码</label>
<input type="password" id="newPassword" class="form-input">
</div>
<div class="mb-4">
<label class="form-label">确认新密码</label>
<input type="password" id="confirmPassword" class="form-input">
</div>
<button id="changePasswordBtn" class="btn btn-primary">修改密码</button>
</div>
</div>
</div>
<script>
// 加载用户信息
async function loadProfile() {
try {
const user = await apiRequest('/user/profile');
const profileHtml = `
<div class="space-y-3">
<div class="flex items-center gap-4">
<div class="text-4xl">${user.avatar ? `<img src="${user.avatar}" class="w-16 h-16 rounded-full">` : '👤'}</div>
<div>
<div class="text-sm text-gray-500">用户名</div>
<div class="font-medium">${escapeHtml(user.username || '未设置')}</div>
</div>
</div>
<div>
<div class="text-sm text-gray-500">手机号</div>
<div class="font-medium">${escapeHtml(user.phone || '未绑定')}</div>
</div>
<div>
<div class="text-sm text-gray-500">邮箱</div>
<div class="font-medium">${escapeHtml(user.email || '未绑定')}</div>
</div>
<div>
<div class="text-sm text-gray-500">注册时间</div>
<div class="font-medium">${new Date(user.created_at).toLocaleString()}</div>
</div>
</div>
`;
document.getElementById('userProfile').innerHTML = profileHtml;
} catch (error) {
if (error.message.includes('401')) {
window.location.href = '/login.php';
} else {
document.getElementById('userProfile').innerHTML = `<div class="text-center text-red-500">加载失败: ${error.message}</div>`;
}
}
}
// 修改密码
document.getElementById('changePasswordBtn').addEventListener('click', async () => {
const oldPassword = document.getElementById('oldPassword').value;
const newPassword = document.getElementById('newPassword').value;
const confirmPassword = document.getElementById('confirmPassword').value;
if (!oldPassword || !newPassword) {
showToast('请填写完整信息', 'error');
return;
}
if (newPassword !== confirmPassword) {
showToast('两次输入的密码不一致', 'error');
return;
}
if (newPassword.length < 6) {
showToast('新密码长度至少6位', 'error');
return;
}
try {
await apiRequest('/user/change-password', {
method: 'POST',
body: JSON.stringify({ old_password: oldPassword, new_password: newPassword })
});
showToast('密码修改成功');
document.getElementById('oldPassword').value = '';
document.getElementById('newPassword').value = '';
document.getElementById('confirmPassword').value = '';
} catch (error) {
showToast(error.message, 'error');
}
});
loadProfile();
</script>
<?php include_once 'footer.php'; ?>