Add Discord OAuth2 account linking and login support
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.
This commit is contained in:
@@ -90,6 +90,31 @@ async function getPlayerProperty(key, uuid) {
|
||||
}
|
||||
}
|
||||
|
||||
async function getPlayerPropertyByValue(key, value) {
|
||||
try {
|
||||
const sql = `SELECT * FROM playersProperties WHERE name = ? AND value = ?`
|
||||
const rows = await database.query(sql, [key, value])
|
||||
const property = rows[0]
|
||||
|
||||
if (!property) {
|
||||
throw new DefaultError(404, "No property found with this value for the specified key")
|
||||
}
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
property: {
|
||||
name: property.name,
|
||||
value: property.value,
|
||||
uuid: property.uuid
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof DefaultError) throw error
|
||||
logger.log("Internal Server Error".bold + " : " + error.toString(), ["MariaDB", "yellow"])
|
||||
throw new DefaultError(500, "Please contact an administrator.", "InternalServerError")
|
||||
}
|
||||
}
|
||||
|
||||
async function getPlayerSettingsSchema() {
|
||||
const RAW_SCHEMA_CACHE = {
|
||||
privileges: {},
|
||||
@@ -213,11 +238,11 @@ async function banUser(uuid, { reasonKey, reasonMessage, expires = null }) {
|
||||
}
|
||||
|
||||
let reasonId
|
||||
const reasonRows = await database.query("SELECT id FROM banReasons WHERE reason_key = ?", [reasonKey])
|
||||
const reasonRows = await database.query("SELECT id FROM banReasons WHERE reasonKey = ?", [reasonKey])
|
||||
if (reasonRows.length > 0) {
|
||||
reasonId = reasonRows[0].id
|
||||
} else {
|
||||
const insertReason = await database.query("INSERT INTO banReasons (reason_key) VALUES (?)", [reasonKey])
|
||||
const insertReason = await database.query("INSERT INTO banReasons (reasonKey) VALUES (?)", [reasonKey])
|
||||
reasonId = insertReason.insertId
|
||||
}
|
||||
|
||||
@@ -279,7 +304,7 @@ async function getPlayerBans(uuid) {
|
||||
b.banId,
|
||||
b.expires,
|
||||
b.reasonMessage,
|
||||
r.reason_key as reason
|
||||
r.reasonKey as reason
|
||||
FROM bans b
|
||||
JOIN banReasons r ON b.reason = r.id
|
||||
WHERE b.uuid = ?
|
||||
@@ -770,5 +795,6 @@ module.exports = {
|
||||
updatePropertyToPlayer,
|
||||
getPlayerSettingsSchema,
|
||||
updatePlayerPreferences,
|
||||
getPlayerPropertyByValue,
|
||||
deleteExpiredCertificates,
|
||||
}
|
||||
Reference in New Issue
Block a user