feat: admin server assignment in user management
This commit is contained in:
@@ -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