Introduces admin database tables, repository, and service for managing administrators and permissions. Adds new admin routes for banning players, managing cosmetics (capes), changing player passwords and usernames, and handling player textures. Updates user and session services to support admin actions and permission checks. Adds related schema validation for new endpoints.
44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
const express = require("express")
|
|
const router = express.Router()
|
|
const utils = require("../modules/utils")
|
|
const logger = require("../modules/logger")
|
|
const authService = require("../services/authService")
|
|
const adminService = require("../services/adminService")
|
|
|
|
if (utils.isTrueFromDotEnv("SUPPORT_REGISTER")) {
|
|
router.post("/", adminService.hasPermission("REGISTER_USER"), async (req, res) => {
|
|
const { username, password, email, registrationCountry, preferredLanguage } = req.body
|
|
const clientIp = req.headers["x-forwarded-for"] || req.connection.remoteAddress
|
|
|
|
const result = await authService.registerUser({
|
|
username,
|
|
password,
|
|
email,
|
|
registrationCountry,
|
|
preferredLanguage,
|
|
clientIp
|
|
})
|
|
|
|
logger.log(`New user registered: ${username}`, ["Web", "yellow", "AUTH", "green"])
|
|
return res.status(200).json(result)
|
|
})
|
|
} else {
|
|
router.post("/", async (req, res) => {
|
|
const { username, password, email, registrationCountry, preferredLanguage } = req.body
|
|
const clientIp = req.headers["x-forwarded-for"] || req.connection.remoteAddress
|
|
|
|
const result = await authService.registerUser({
|
|
username,
|
|
password,
|
|
email,
|
|
registrationCountry,
|
|
preferredLanguage,
|
|
clientIp
|
|
})
|
|
|
|
logger.log(`New user registered: ${username}`, ["Web", "yellow", "AUTH", "green"])
|
|
return res.status(200).json(result)
|
|
})
|
|
}
|
|
|
|
module.exports = router |