整合資料庫、完成登入註冊忘記密碼功能
This commit is contained in:
79
scripts/test-role-display.js
Normal file
79
scripts/test-role-display.js
Normal file
@@ -0,0 +1,79 @@
|
||||
async function testRoleDisplay() {
|
||||
console.log('🧪 測試密碼重設頁面的角色顯示...\n');
|
||||
|
||||
try {
|
||||
// 1. 測試忘記密碼 API
|
||||
console.log('1. 測試忘記密碼 API...');
|
||||
const response = await fetch('http://localhost:3000/api/auth/forgot-password', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
email: 'admin@ai-platform.com'
|
||||
})
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
console.log('✅ 忘記密碼 API 測試成功');
|
||||
console.log('生成的重設連結:', data.resetUrl);
|
||||
|
||||
// 解析 URL 參數
|
||||
const url = new URL(data.resetUrl);
|
||||
const token = url.searchParams.get('token');
|
||||
const email = url.searchParams.get('email');
|
||||
const mode = url.searchParams.get('mode');
|
||||
const name = url.searchParams.get('name');
|
||||
const department = url.searchParams.get('department');
|
||||
const role = url.searchParams.get('role');
|
||||
|
||||
console.log('\n📋 URL 參數解析:');
|
||||
console.log('- token:', token);
|
||||
console.log('- email:', email);
|
||||
console.log('- mode:', mode);
|
||||
console.log('- name:', name);
|
||||
console.log('- department:', department);
|
||||
console.log('- role:', role);
|
||||
|
||||
// 2. 測試註冊頁面載入
|
||||
console.log('\n2. 測試註冊頁面載入...');
|
||||
const registerResponse = await fetch(data.resetUrl);
|
||||
|
||||
if (registerResponse.ok) {
|
||||
console.log('✅ 註冊頁面載入成功');
|
||||
console.log('狀態碼:', registerResponse.status);
|
||||
|
||||
// 檢查頁面內容是否包含正確的角色資訊
|
||||
const pageContent = await registerResponse.text();
|
||||
if (pageContent.includes('管理員') && role === 'admin') {
|
||||
console.log('✅ 角色顯示正確:管理員');
|
||||
} else if (pageContent.includes('一般用戶') && role === 'user') {
|
||||
console.log('✅ 角色顯示正確:一般用戶');
|
||||
} else if (pageContent.includes('開發者') && role === 'developer') {
|
||||
console.log('✅ 角色顯示正確:開發者');
|
||||
} else {
|
||||
console.log('❌ 角色顯示可能有問題');
|
||||
console.log('頁面包含的角色文字:', pageContent.match(/管理員|一般用戶|開發者/g));
|
||||
}
|
||||
} else {
|
||||
console.log('❌ 註冊頁面載入失敗:', registerResponse.status);
|
||||
}
|
||||
|
||||
} else {
|
||||
const errorData = await response.text();
|
||||
console.log('❌ 忘記密碼 API 測試失敗:', response.status, errorData);
|
||||
}
|
||||
|
||||
console.log('\n🎉 角色顯示測試完成!');
|
||||
console.log('\n📋 修復內容:');
|
||||
console.log('✅ 忘記密碼 API 現在包含用戶角色資訊');
|
||||
console.log('✅ 註冊頁面從 URL 參數獲取正確角色');
|
||||
console.log('✅ 角色顯示基於資料庫中的實際角色');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 測試過程中發生錯誤:', error);
|
||||
}
|
||||
}
|
||||
|
||||
testRoleDisplay();
|
Reference in New Issue
Block a user