Move from storing tokens in Berry Dash Database to Lncvrt Games Database
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
-- https://www.phpmyadmin.net/
|
-- https://www.phpmyadmin.net/
|
||||||
--
|
--
|
||||||
-- Host: localhost
|
-- Host: localhost
|
||||||
-- Generation Time: Jan 24, 2026 at 08:31 PM
|
-- Generation Time: Jan 30, 2026 at 02:12 AM
|
||||||
-- Server version: 12.1.2-MariaDB
|
-- Server version: 12.1.2-MariaDB
|
||||||
-- PHP Version: 8.5.2
|
-- PHP Version: 8.5.2
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
-- https://www.phpmyadmin.net/
|
-- https://www.phpmyadmin.net/
|
||||||
--
|
--
|
||||||
-- Host: localhost
|
-- Host: localhost
|
||||||
-- Generation Time: Jan 27, 2026 at 05:18 PM
|
-- Generation Time: Jan 30, 2026 at 02:19 AM
|
||||||
-- Server version: 12.1.2-MariaDB
|
-- Server version: 12.1.2-MariaDB
|
||||||
-- PHP Version: 8.5.2
|
-- PHP Version: 8.5.2
|
||||||
|
|
||||||
@@ -113,9 +113,10 @@ CREATE TABLE `resetcodes` (
|
|||||||
CREATE TABLE `users` (
|
CREATE TABLE `users` (
|
||||||
`id` bigint(20) NOT NULL,
|
`id` bigint(20) NOT NULL,
|
||||||
`username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
`username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||||
`password` varchar(60) NOT NULL,
|
`password` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||||
`email` varchar(255) NOT NULL,
|
`email` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL,
|
||||||
`latest_ip` varchar(255) DEFAULT NULL,
|
`token` varchar(512) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL,
|
||||||
|
`latest_ip` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL,
|
||||||
`register_time` bigint(20) NOT NULL,
|
`register_time` bigint(20) NOT NULL,
|
||||||
`leaderboards_banned` tinyint(1) NOT NULL DEFAULT 0
|
`leaderboards_banned` tinyint(1) NOT NULL DEFAULT 0
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import dotenv from 'dotenv'
|
|||||||
import swagger from '@elysiajs/swagger'
|
import swagger from '@elysiajs/swagger'
|
||||||
import { berryDashChats, berryDashUserData, users } from './lib/tables'
|
import { berryDashChats, berryDashUserData, users } from './lib/tables'
|
||||||
import { and, desc, eq } from 'drizzle-orm'
|
import { and, desc, eq } from 'drizzle-orm'
|
||||||
import { checkAuthorization } from './lib/bd/auth'
|
import { checkAuthorization } from './lib/auth'
|
||||||
|
|
||||||
import { handler as getVerifyCodeHandler } from './routes/get-verify-code'
|
import { handler as getVerifyCodeHandler } from './routes/get-verify-code'
|
||||||
|
|
||||||
@@ -124,7 +124,6 @@ app.ws('/ws', {
|
|||||||
const ip = ws.remoteAddress
|
const ip = ws.remoteAddress
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
message.data.auth as string,
|
message.data.auth as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
@@ -181,7 +180,6 @@ app.ws('/ws', {
|
|||||||
const ip = ws.remoteAddress
|
const ip = ws.remoteAddress
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
message.data.auth as string,
|
message.data.auth as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
@@ -311,7 +309,6 @@ app.ws('/ws', {
|
|||||||
const ip = ws.remoteAddress
|
const ip = ws.remoteAddress
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
message.data.auth as string,
|
message.data.auth as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
import { MySql2Database } from 'drizzle-orm/mysql2'
|
import { MySql2Database } from 'drizzle-orm/mysql2'
|
||||||
import { berryDashUserData, users } from '../tables'
|
import { users } from './tables'
|
||||||
import { eq } from 'drizzle-orm'
|
import { eq } from 'drizzle-orm'
|
||||||
|
|
||||||
export async function checkAuthorization (
|
export async function checkAuthorization (
|
||||||
authorizationToken: string,
|
authorizationToken: string,
|
||||||
db1: MySql2Database,
|
db0: MySql2Database,
|
||||||
db0?: MySql2Database,
|
updateIp: string | null
|
||||||
updateIp?: string | null
|
|
||||||
) {
|
) {
|
||||||
if (!authorizationToken) return { valid: false, id: 0 }
|
if (!authorizationToken) return { valid: false, id: 0 }
|
||||||
|
|
||||||
const userData = await db1
|
const userData = await db0
|
||||||
.select({ id: berryDashUserData.id })
|
.select({ id: users.id })
|
||||||
.from(berryDashUserData)
|
.from(users)
|
||||||
.where(eq(berryDashUserData.token, authorizationToken))
|
.where(eq(users.token, authorizationToken))
|
||||||
.execute()
|
.execute()
|
||||||
|
|
||||||
if (!userData[0]) return { valid: false, id: 0 }
|
if (!userData[0]) return { valid: false, id: 0 }
|
||||||
@@ -16,6 +16,7 @@ export const users = mysqlTable('users', {
|
|||||||
username: varchar('username', { length: 255 }).notNull(),
|
username: varchar('username', { length: 255 }).notNull(),
|
||||||
password: varchar('password', { length: 60 }).notNull(),
|
password: varchar('password', { length: 60 }).notNull(),
|
||||||
email: varchar('email', { length: 255 }).notNull(),
|
email: varchar('email', { length: 255 }).notNull(),
|
||||||
|
token: varchar('token', { length: 512 }).notNull(),
|
||||||
latestIp: varchar('latest_ip', { length: 255 }),
|
latestIp: varchar('latest_ip', { length: 255 }),
|
||||||
registerTime: bigint('register_time', { mode: 'number' }).notNull(),
|
registerTime: bigint('register_time', { mode: 'number' }).notNull(),
|
||||||
leaderboardsBanned: boolean('leaderboards_banned').default(false).notNull()
|
leaderboardsBanned: boolean('leaderboards_banned').default(false).notNull()
|
||||||
@@ -94,7 +95,6 @@ export const resetCodes = mysqlTable('resetcodes', {
|
|||||||
|
|
||||||
export const berryDashUserData = mysqlTable('userdata', {
|
export const berryDashUserData = mysqlTable('userdata', {
|
||||||
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement().notNull(),
|
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement().notNull(),
|
||||||
token: varchar('token', { length: 512 }).notNull(),
|
|
||||||
saveData: longtext('save_data').default('{}').notNull(),
|
saveData: longtext('save_data').default('{}').notNull(),
|
||||||
legacyHighScore: bigint('legacy_high_score', { mode: 'number' })
|
legacyHighScore: bigint('legacy_high_score', { mode: 'number' })
|
||||||
.default(0)
|
.default(0)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
getDatabaseConnection,
|
getDatabaseConnection,
|
||||||
jsonResponse
|
jsonResponse
|
||||||
} from '../../../../lib/util'
|
} from '../../../../lib/util'
|
||||||
import { checkAuthorization } from '../../../../lib/bd/auth'
|
import { checkAuthorization } from '../../../../lib/auth'
|
||||||
import { users } from '../../../../lib/tables'
|
import { users } from '../../../../lib/tables'
|
||||||
import { eq } from 'drizzle-orm'
|
import { eq } from 'drizzle-orm'
|
||||||
import bcrypt from 'bcryptjs'
|
import bcrypt from 'bcryptjs'
|
||||||
@@ -29,7 +29,6 @@ export async function handler (context: Context) {
|
|||||||
const authorizationToken = context.headers.authorization
|
const authorizationToken = context.headers.authorization
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
authorizationToken as string,
|
authorizationToken as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
getDatabaseConnection,
|
getDatabaseConnection,
|
||||||
jsonResponse
|
jsonResponse
|
||||||
} from '../../../../lib/util'
|
} from '../../../../lib/util'
|
||||||
import { checkAuthorization } from '../../../../lib/bd/auth'
|
import { checkAuthorization } from '../../../../lib/auth'
|
||||||
import { users } from '../../../../lib/tables'
|
import { users } from '../../../../lib/tables'
|
||||||
import { eq } from 'drizzle-orm'
|
import { eq } from 'drizzle-orm'
|
||||||
|
|
||||||
@@ -28,7 +28,6 @@ export async function handler (context: Context) {
|
|||||||
const authorizationToken = context.headers.authorization
|
const authorizationToken = context.headers.authorization
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
authorizationToken as string,
|
authorizationToken as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ export async function handler (context: Context) {
|
|||||||
.select({
|
.select({
|
||||||
id: users.id,
|
id: users.id,
|
||||||
username: users.username,
|
username: users.username,
|
||||||
password: users.password
|
password: users.password,
|
||||||
|
token: users.token
|
||||||
})
|
})
|
||||||
.from(users)
|
.from(users)
|
||||||
.where(eq(users.username, body.username))
|
.where(eq(users.username, body.username))
|
||||||
@@ -70,30 +71,11 @@ export async function handler (context: Context) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const user2 = await db1
|
|
||||||
.select({ token: berryDashUserData.token })
|
|
||||||
.from(berryDashUserData)
|
|
||||||
.where(eq(berryDashUserData.id, user[0].id))
|
|
||||||
.limit(1)
|
|
||||||
.execute()
|
|
||||||
if (!user2[0]) {
|
|
||||||
connection0.end()
|
|
||||||
connection1.end()
|
|
||||||
return jsonResponse(
|
|
||||||
{
|
|
||||||
success: false,
|
|
||||||
message: 'Invalid username or password',
|
|
||||||
data: null
|
|
||||||
},
|
|
||||||
401
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsonResponse({
|
return jsonResponse({
|
||||||
success: true,
|
success: true,
|
||||||
message: null,
|
message: null,
|
||||||
data: {
|
data: {
|
||||||
session: user2[0].token,
|
session: user[0].token,
|
||||||
username: user[0].username,
|
username: user[0].username,
|
||||||
id: user[0].id
|
id: user[0].id
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ export async function handler (context: Context) {
|
|||||||
username: body.username,
|
username: body.username,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
email: body.email,
|
email: body.email,
|
||||||
|
token,
|
||||||
registerTime: time,
|
registerTime: time,
|
||||||
latestIp: ip
|
latestIp: ip
|
||||||
})
|
})
|
||||||
@@ -164,8 +165,7 @@ export async function handler (context: Context) {
|
|||||||
await db1
|
await db1
|
||||||
.insert(berryDashUserData)
|
.insert(berryDashUserData)
|
||||||
.values({
|
.values({
|
||||||
id: result[0].insertId,
|
id: result[0].insertId
|
||||||
token
|
|
||||||
})
|
})
|
||||||
.execute()
|
.execute()
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
getDatabaseConnection,
|
getDatabaseConnection,
|
||||||
jsonResponse
|
jsonResponse
|
||||||
} from '../../../../lib/util'
|
} from '../../../../lib/util'
|
||||||
import { checkAuthorization } from '../../../../lib/bd/auth'
|
import { checkAuthorization } from '../../../../lib/auth'
|
||||||
import { berryDashUserData, users } from '../../../../lib/tables'
|
import { berryDashUserData, users } from '../../../../lib/tables'
|
||||||
import { eq } from 'drizzle-orm'
|
import { eq } from 'drizzle-orm'
|
||||||
|
|
||||||
@@ -24,7 +24,6 @@ export async function handler (context: Context) {
|
|||||||
const authorizationToken = context.headers.authorization
|
const authorizationToken = context.headers.authorization
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
authorizationToken as string,
|
authorizationToken as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
@@ -40,8 +39,7 @@ export async function handler (context: Context) {
|
|||||||
|
|
||||||
const result = await db1
|
const result = await db1
|
||||||
.select({
|
.select({
|
||||||
saveData: berryDashUserData.saveData,
|
saveData: berryDashUserData.saveData
|
||||||
token: berryDashUserData.token
|
|
||||||
})
|
})
|
||||||
.from(berryDashUserData)
|
.from(berryDashUserData)
|
||||||
.where(eq(berryDashUserData.id, userId))
|
.where(eq(berryDashUserData.id, userId))
|
||||||
@@ -65,6 +63,6 @@ export async function handler (context: Context) {
|
|||||||
if (!savedata.account) savedata.account = {}
|
if (!savedata.account) savedata.account = {}
|
||||||
savedata.account.id = userId
|
savedata.account.id = userId
|
||||||
savedata.account.name = result2[0].username
|
savedata.account.name = result2[0].username
|
||||||
savedata.account.session = result[0].token
|
savedata.account.session = authorizationToken
|
||||||
return jsonResponse({ success: true, message: null, data: savedata }, 200)
|
return jsonResponse({ success: true, message: null, data: savedata }, 200)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
getDatabaseConnection,
|
getDatabaseConnection,
|
||||||
jsonResponse
|
jsonResponse
|
||||||
} from '../../../../lib/util'
|
} from '../../../../lib/util'
|
||||||
import { checkAuthorization } from '../../../../lib/bd/auth'
|
import { checkAuthorization } from '../../../../lib/auth'
|
||||||
import { berryDashUserData } from '../../../../lib/tables'
|
import { berryDashUserData } from '../../../../lib/tables'
|
||||||
import { eq } from 'drizzle-orm'
|
import { eq } from 'drizzle-orm'
|
||||||
|
|
||||||
@@ -28,7 +28,6 @@ export async function handler (context: Context) {
|
|||||||
const authorizationToken = context.headers.authorization
|
const authorizationToken = context.headers.authorization
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
authorizationToken as string,
|
authorizationToken as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
jsonResponse
|
jsonResponse
|
||||||
} from '../../../../lib/util'
|
} from '../../../../lib/util'
|
||||||
import { berryDashChatroomReports } from '../../../../lib/tables'
|
import { berryDashChatroomReports } from '../../../../lib/tables'
|
||||||
import { checkAuthorization } from '../../../../lib/bd/auth'
|
import { checkAuthorization } from '../../../../lib/auth'
|
||||||
import { and, eq } from 'drizzle-orm'
|
import { and, eq } from 'drizzle-orm'
|
||||||
|
|
||||||
type Body = {
|
type Body = {
|
||||||
@@ -29,7 +29,6 @@ export async function handler (context: Context) {
|
|||||||
const authorizationToken = context.headers.authorization
|
const authorizationToken = context.headers.authorization
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
authorizationToken as string,
|
authorizationToken as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
} from '../../../lib/util'
|
} from '../../../lib/util'
|
||||||
import { berryDashMarketplaceIcons, users } from '../../../lib/tables'
|
import { berryDashMarketplaceIcons, users } from '../../../lib/tables'
|
||||||
import { and, eq, inArray, or, sql, not, desc, asc } from 'drizzle-orm'
|
import { and, eq, inArray, or, sql, not, desc, asc } from 'drizzle-orm'
|
||||||
import { checkAuthorization } from '../../../lib/bd/auth'
|
import { checkAuthorization } from '../../../lib/auth'
|
||||||
|
|
||||||
type Body = {
|
type Body = {
|
||||||
sortBy: number
|
sortBy: number
|
||||||
@@ -49,7 +49,6 @@ export async function handler (context: Context) {
|
|||||||
const authorizationToken = context.headers.authorization
|
const authorizationToken = context.headers.authorization
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
authorizationToken as string,
|
authorizationToken as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
hash,
|
hash,
|
||||||
jsonResponse
|
jsonResponse
|
||||||
} from '../../../../lib/util'
|
} from '../../../../lib/util'
|
||||||
import { checkAuthorization } from '../../../../lib/bd/auth'
|
import { checkAuthorization } from '../../../../lib/auth'
|
||||||
import { berryDashMarketplaceIcons, verifyCodes } from '../../../../lib/tables'
|
import { berryDashMarketplaceIcons, verifyCodes } from '../../../../lib/tables'
|
||||||
import { and, desc, eq, sql } from 'drizzle-orm'
|
import { and, desc, eq, sql } from 'drizzle-orm'
|
||||||
import { Buffer } from 'buffer'
|
import { Buffer } from 'buffer'
|
||||||
@@ -61,7 +61,6 @@ export async function handler (context: Context) {
|
|||||||
const authorizationToken = context.headers.authorization
|
const authorizationToken = context.headers.authorization
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
authorizationToken as string,
|
authorizationToken as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
} from '../../../../lib/util'
|
} from '../../../../lib/util'
|
||||||
import { berryDashUserPosts } from '../../../../lib/tables'
|
import { berryDashUserPosts } from '../../../../lib/tables'
|
||||||
import { and, eq } from 'drizzle-orm'
|
import { and, eq } from 'drizzle-orm'
|
||||||
import { checkAuthorization } from '../../../../lib/bd/auth'
|
import { checkAuthorization } from '../../../../lib/auth'
|
||||||
|
|
||||||
export async function handler (context: Context) {
|
export async function handler (context: Context) {
|
||||||
const dbInfo0 = getDatabaseConnection(0)
|
const dbInfo0 = getDatabaseConnection(0)
|
||||||
@@ -24,7 +24,6 @@ export async function handler (context: Context) {
|
|||||||
const authorizationToken = context.headers.authorization
|
const authorizationToken = context.headers.authorization
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
authorizationToken as string,
|
authorizationToken as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
jsonResponse
|
jsonResponse
|
||||||
} from '../../../../lib/util'
|
} from '../../../../lib/util'
|
||||||
import { berryDashUserPosts } from '../../../../lib/tables'
|
import { berryDashUserPosts } from '../../../../lib/tables'
|
||||||
import { checkAuthorization } from '../../../../lib/bd/auth'
|
import { checkAuthorization } from '../../../../lib/auth'
|
||||||
|
|
||||||
type Body = {
|
type Body = {
|
||||||
content: string
|
content: string
|
||||||
@@ -27,7 +27,6 @@ export async function handler (context: Context) {
|
|||||||
const authorizationToken = context.headers.authorization
|
const authorizationToken = context.headers.authorization
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
authorizationToken as string,
|
authorizationToken as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
} from '../../../../lib/util'
|
} from '../../../../lib/util'
|
||||||
import { berryDashUserPosts } from '../../../../lib/tables'
|
import { berryDashUserPosts } from '../../../../lib/tables'
|
||||||
import { and, eq } from 'drizzle-orm'
|
import { and, eq } from 'drizzle-orm'
|
||||||
import { checkAuthorization } from '../../../../lib/bd/auth'
|
import { checkAuthorization } from '../../../../lib/auth'
|
||||||
|
|
||||||
export async function handler (context: Context) {
|
export async function handler (context: Context) {
|
||||||
const dbInfo0 = getDatabaseConnection(0)
|
const dbInfo0 = getDatabaseConnection(0)
|
||||||
@@ -24,7 +24,6 @@ export async function handler (context: Context) {
|
|||||||
const authorizationToken = context.headers.authorization
|
const authorizationToken = context.headers.authorization
|
||||||
const authResult = await checkAuthorization(
|
const authResult = await checkAuthorization(
|
||||||
authorizationToken as string,
|
authorizationToken as string,
|
||||||
db1,
|
|
||||||
db0,
|
db0,
|
||||||
ip
|
ip
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user