Introduces Discord OAuth2 integration for account association and login, including new routes for linking, unlinking, and authenticating via Discord. Adds supporting services, repositories, and schema validation for the OAuth2 flow. Refactors database schema and queries for consistency, and updates dependencies to include required OAuth2 libraries.
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 |