Add admin API, permissions, and player management routes
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.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const fs = require("node:fs/promises")
|
||||
const path = require("node:path")
|
||||
const util = require("node:util")
|
||||
const bcrypt = require("bcryptjs")
|
||||
const logger = require("../modules/logger")
|
||||
const crypto = require("node:crypto")
|
||||
const ssrfcheck = require("ssrfcheck")
|
||||
@@ -498,6 +499,30 @@ async function uploadSkinFromUrl(uuid, url, variant) {
|
||||
return await uploadSkin(uuid, { path: tempPath }, variant)
|
||||
}
|
||||
|
||||
async function changePassword(uuid, newPlainPassword) {
|
||||
if (!newPlainPassword || newPlainPassword.length < 6) {
|
||||
throw new DefaultError(400, "Password is too short. Minimum 6 characters.")
|
||||
}
|
||||
|
||||
const salt = await bcrypt.genSalt(10)
|
||||
const hashedPassword = await bcrypt.hash(newPlainPassword, salt)
|
||||
|
||||
return await userRepository.updatePassword(uuid, hashedPassword)
|
||||
}
|
||||
|
||||
async function grantCape(uuid, hash) {
|
||||
const texture = await userRepository.getTextureByHash(hash)
|
||||
if (!texture) {
|
||||
throw new DefaultError(404, "Texture de cape introuvable dans la base globale.")
|
||||
}
|
||||
|
||||
return await userRepository.addCapeToPlayer(uuid, hash)
|
||||
}
|
||||
|
||||
async function removeCape(uuid, hash) {
|
||||
return await userRepository.removeCapeFromPlayer(uuid, hash)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
banUser,
|
||||
showCape,
|
||||
@@ -505,8 +530,10 @@ module.exports = {
|
||||
unbanUser,
|
||||
resetSkin,
|
||||
isBlocked,
|
||||
grantCape,
|
||||
bulkLookup,
|
||||
uploadSkin,
|
||||
removeCape,
|
||||
blockPlayer,
|
||||
getNameUUIDs,
|
||||
unblockPlayer,
|
||||
@@ -514,6 +541,7 @@ module.exports = {
|
||||
getPlayerBans,
|
||||
changeUsername,
|
||||
getPreferences,
|
||||
changePassword,
|
||||
getBlockedUuids,
|
||||
registerTexture,
|
||||
getLegacyProfile,
|
||||
|
||||
Reference in New Issue
Block a user