Add base project files including environment example, license, README, .gitignore, error classes, ESLint config, database modules, texture assets, repositories, routes, schemas, services, and server entry point. This establishes the foundational structure for a Yggdrasil-compatible REST API with modular error handling, database setup, and route organization.
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 |