fix: external register verify token mismatch, add type validation
This commit is contained in:
@@ -28,10 +28,11 @@ router.post('/auth/register', async (req, res) => {
|
|||||||
if (await getRow('SELECT id FROM users WHERE email = ?', [email])) return res.status(400).json({ error: '邮箱已注册' });
|
if (await getRow('SELECT id FROM users WHERE email = ?', [email])) return res.status(400).json({ error: '邮箱已注册' });
|
||||||
|
|
||||||
const hashed = bcrypt.hashSync(password, 10);
|
const hashed = bcrypt.hashSync(password, 10);
|
||||||
await query('INSERT INTO users(username,password,email,game_name,game_uid,verify_token,verify_expires) VALUES (?,?,?,?,?,?,DATE_ADD(NOW(), INTERVAL 24 HOUR))', [username, hashed, email, game_name, game_uid, uuid()]);
|
const verifyToken = uuid();
|
||||||
|
await query('INSERT INTO users(username,password,email,game_name,game_uid,verify_token,verify_expires) VALUES (?,?,?,?,?,?,DATE_ADD(NOW(), INTERVAL 24 HOUR))', [username, hashed, email, game_name, game_uid, verifyToken]);
|
||||||
|
|
||||||
const site = await getRow("SELECT v FROM settings WHERE k='site_url'");
|
const site = await getRow("SELECT v FROM settings WHERE k='site_url'");
|
||||||
const sent = await sendEmail(email, 'verify_email', { username, game_name, game_uid, verify_link: `${site?.v||'http://localhost:3100'}#/verify?token=${uuid()}` });
|
const sent = await sendEmail(email, 'verify_email', { username, game_name, game_uid, verify_link: `${site?.v||'http://localhost:3100'}#/verify?token=${verifyToken}` });
|
||||||
|
|
||||||
if (!sent) {
|
if (!sent) {
|
||||||
await query('UPDATE users SET email_verified=1,active=1,verify_token=NULL WHERE username=?', [username]);
|
await query('UPDATE users SET email_verified=1,active=1,verify_token=NULL WHERE username=?', [username]);
|
||||||
@@ -74,6 +75,9 @@ router.post('/tickets', async (req, res) => {
|
|||||||
const { type, title, reporter_game_name, reporter_game_uid, target_game_name, target_game_uid, reason, description, is_admin_complaint } = req.body;
|
const { type, title, reporter_game_name, reporter_game_uid, target_game_name, target_game_uid, reason, description, is_admin_complaint } = req.body;
|
||||||
if (!type || !['report','suggestion','appeal'].includes(type)) return res.status(400).json({ error: '类型不正确' });
|
if (!type || !['report','suggestion','appeal'].includes(type)) return res.status(400).json({ error: '类型不正确' });
|
||||||
if (!title || !reporter_game_name || !reporter_game_uid) return res.status(400).json({ error: '必填字段不完整' });
|
if (!title || !reporter_game_name || !reporter_game_uid) return res.status(400).json({ error: '必填字段不完整' });
|
||||||
|
if (type === 'report' && !reason) return res.status(400).json({ error: '请填写举报原因' });
|
||||||
|
if (type === 'suggestion' && !description) return res.status(400).json({ error: '建议内容不能为空' });
|
||||||
|
if (type === 'appeal' && (!reason || !description)) return res.status(400).json({ error: '请填写完整申诉信息' });
|
||||||
|
|
||||||
const countRow = await getRow("SELECT COUNT(*) as c FROM tickets WHERE (reporter_game_name = ? OR reporter_game_uid = ?) AND status IN ('pending','processing','awaiting_info','appealing')", [reporter_game_name, reporter_game_uid]);
|
const countRow = await getRow("SELECT COUNT(*) as c FROM tickets WHERE (reporter_game_name = ? OR reporter_game_uid = ?) AND status IN ('pending','processing','awaiting_info','appealing')", [reporter_game_name, reporter_game_uid]);
|
||||||
if (countRow.c >= 5) return res.status(400).json({ error: '待处理工单已达上限' });
|
if (countRow.c >= 5) return res.status(400).json({ error: '待处理工单已达上限' });
|
||||||
|
|||||||
Reference in New Issue
Block a user