今天先實作註冊登入登出功能的流程與架構
router.post('/register', async (req, res) => {
// 獲取用戶輸入
const { email, password } = req.body;
// TODO: 密碼加密
// TODO: 儲存到數據庫
// TODO: 發送驗證郵件
res.status(201).json({ message: 'User registered. Please check your email for verification.' });
});
router.post('/login', async (req, res) => {
const { email, password } = req.body;
// TODO: 驗證用戶名和密碼
// TODO: 創建JWT token或session
res.json({ message: 'Logged in successfully.' });
});
router.get('/profile', async (req, res) => {
// TODO: 獲取用戶資料
res.json({ message: 'User data', data: {} });
});
router.put('/profile', async (req, res) => {
// TODO: 更新用戶資料
res.json({ message: 'User data updated.' });
});
router.post('/reset-password', async (req, res) => {
const { oldPassword, newPassword } = req.body;
// TODO: 驗證舊密碼並更新新密碼
res.json({ message: 'Password reset successfully.' });
});
router.post('/logout', async (req, res) => {
// TODO: 清除session或token
res.json({ message: 'Logged out successfully.' });
});