feat: admin server assignment in user management
This commit is contained in:
@@ -80,6 +80,7 @@ async function initSchema(connection) {
|
||||
active TINYINT(1) NOT NULL DEFAULT 0,
|
||||
email_verified TINYINT(1) NOT NULL DEFAULT 0,
|
||||
source ENUM('netease','skin') NOT NULL DEFAULT 'netease',
|
||||
admin_servers JSON,
|
||||
verify_token VARCHAR(255),
|
||||
verify_expires DATETIME,
|
||||
reset_token VARCHAR(255),
|
||||
@@ -264,6 +265,7 @@ async function migrateAdditions(db) {
|
||||
try { await db.execute("ALTER TABLE tickets MODIFY type ENUM('report','suggestion','appeal','result_appeal') NOT NULL"); } catch {}
|
||||
try { await db.execute("ALTER TABLE tickets MODIFY status ENUM('pending','processing','awaiting_info','appealing','resolved','rejected','closed') NOT NULL"); } catch {}
|
||||
try { await db.execute("ALTER TABLE users ADD COLUMN source ENUM('netease','skin') NOT NULL DEFAULT 'netease'"); } catch {}
|
||||
try { await db.execute("ALTER TABLE users ADD COLUMN admin_servers JSON"); } catch {}
|
||||
|
||||
try { await db.execute(`CREATE TABLE IF NOT EXISTS polls (id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(200) NOT NULL, description TEXT, options JSON NOT NULL, group_name VARCHAR(100) NOT NULL DEFAULT '', server_name VARCHAR(100) NOT NULL DEFAULT '', start_time DATETIME, end_time DATETIME, active TINYINT(1) NOT NULL DEFAULT 1, created_by INT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, INDEX idx_active (active), INDEX idx_group_server (group_name, server_name)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`); } catch {}
|
||||
try { await db.execute(`CREATE TABLE IF NOT EXISTS poll_votes (id INT AUTO_INCREMENT PRIMARY KEY, poll_id INT NOT NULL, user_id INT NOT NULL, option_index INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY uk_poll_user (poll_id, user_id), INDEX idx_poll (poll_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`); } catch {}
|
||||
|
||||
@@ -6,7 +6,7 @@ const { authenticate, requireRole } = require('../middleware/auth');
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/', authenticate, requireRole('owner','admin'), async (req, res) => {
|
||||
res.json(await query('SELECT id, username, email, game_name, game_uid, source, role, active, email_verified, created_at FROM users ORDER BY created_at DESC'));
|
||||
res.json(await query('SELECT id, username, email, game_name, game_uid, source, role, active, admin_servers, email_verified, created_at FROM users ORDER BY created_at DESC'));
|
||||
});
|
||||
|
||||
router.get('/:id', authenticate, requireRole('owner','admin'), async (req, res) => {
|
||||
@@ -36,6 +36,7 @@ router.put('/:id', authenticate, requireRole('owner','admin'), async (req, res)
|
||||
if (req.body.game_name) fields.game_name = req.body.game_name;
|
||||
if (req.body.game_uid) fields.game_uid = req.body.game_uid;
|
||||
if (req.body.source) { if (!['netease','skin'].includes(req.body.source)) return res.status(400).json({ error: '无效来源' }); fields.source = req.body.source; }
|
||||
if (req.body.admin_servers !== undefined) fields.admin_servers = JSON.stringify(req.body.admin_servers);
|
||||
if (req.body.role) { if (!['owner','admin','player'].includes(req.body.role)) return res.status(400).json({ error: '无效角色' }); fields.role = req.body.role; }
|
||||
if (req.body.active !== undefined) fields.active = req.body.active ? 1 : 0;
|
||||
if (req.body.password) { if (req.body.password.length < 6) return res.status(400).json({ error: '密码至少6位' }); fields.password = bcrypt.hashSync(req.body.password, 10); }
|
||||
|
||||
Reference in New Issue
Block a user