Dashboard de /account: info, puntos, créditos, token y personajes
- lib/account.ts: getAccountDashboard(session) lee puntos (home_api_points), créditos battlepay (battlenet_accounts), estado del token de seguridad (home_securitytoken) y personajes (acore_characters). Resiliente si las BD de AzerothCore no están pobladas (devuelve vacíos/0). - app/[locale]/account: página protegida enriquecida (tarjetas de cuenta + puntos + rejilla de personajes con oro), i18n. Namespace Account ampliado. Verificado: build OK, guarda sigue redirigiendo a login sin sesión. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
||||||
import { redirect } from '@/i18n/navigation'
|
import { redirect } from '@/i18n/navigation'
|
||||||
import { getSession } from '@/lib/session'
|
import { getSession } from '@/lib/session'
|
||||||
|
import { getAccountDashboard } from '@/lib/account'
|
||||||
import { LogoutButton } from '@/components/LogoutButton'
|
import { LogoutButton } from '@/components/LogoutButton'
|
||||||
|
|
||||||
export const dynamic = 'force-dynamic'
|
export const dynamic = 'force-dynamic'
|
||||||
@@ -14,20 +15,61 @@ export default async function AccountPage({ params }: { params: Promise<{ locale
|
|||||||
if (!session.bnetId) redirect({ href: '/login', locale })
|
if (!session.bnetId) redirect({ href: '/login', locale })
|
||||||
if (!session.username) redirect({ href: '/select-account', locale })
|
if (!session.username) redirect({ href: '/select-account', locale })
|
||||||
|
|
||||||
|
const data = await getAccountDashboard(session)
|
||||||
|
|
||||||
|
const card = 'rounded-lg border border-amber-900/60 bg-[#241812] p-4'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="mx-auto max-w-2xl px-4 py-8">
|
<main className="mx-auto max-w-3xl px-4 py-8">
|
||||||
<h1 className="mb-6 text-2xl font-bold text-amber-500">{t('title')}</h1>
|
<div className="mb-6 flex items-center justify-between">
|
||||||
<div className="space-y-2 rounded-lg border border-amber-900/60 bg-[#241812] p-4 text-sm">
|
<h1 className="text-2xl font-bold text-amber-500">{t('title')}</h1>
|
||||||
<p>
|
<LogoutButton className="rounded border border-amber-900/60 px-3 py-1 text-sm text-amber-200 hover:text-amber-400" />
|
||||||
{t('bnetAccount')}: <span className="text-amber-400">{session.bnetEmail}</span>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
{t('gameAccount')}: <span className="text-amber-400">{session.username}</span>
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-6">
|
|
||||||
<LogoutButton />
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
|
<section className={card}>
|
||||||
|
<div className="space-y-1 text-sm">
|
||||||
|
<p>{t('bnetAccount')}: <span className="text-amber-400">{data.bnetEmail}</span></p>
|
||||||
|
<p>{t('gameAccount')}: <span className="text-amber-400">{data.gameAccount}</span></p>
|
||||||
|
<p>
|
||||||
|
{t('securityToken')}:{' '}
|
||||||
|
<span className="text-amber-400">
|
||||||
|
{data.securityTokenDate
|
||||||
|
? `${t('requested')} — ${new Date(data.securityTokenDate).toLocaleString(locale)}`
|
||||||
|
: t('notRequested')}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className={card}>
|
||||||
|
<h2 className="mb-2 text-lg font-semibold">{t('points')}</h2>
|
||||||
|
<div className="space-y-1 text-sm">
|
||||||
|
<p>{t('dp')}: <span className="text-amber-400">{data.dp}</span></p>
|
||||||
|
<p>{t('vp')}: <span className="text-amber-400">{data.vp}</span></p>
|
||||||
|
<p>{t('battlepayCredits')}: <span className="text-amber-400">{data.battlepayCredits}</span></p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<section className="mt-6">
|
||||||
|
<h2 className="mb-3 text-lg font-semibold">{t('characters')}</h2>
|
||||||
|
{data.characters.length === 0 ? (
|
||||||
|
<p className="text-amber-200/70">{t('noCharacters')}</p>
|
||||||
|
) : (
|
||||||
|
<div className="grid gap-3 sm:grid-cols-2 md:grid-cols-3">
|
||||||
|
{data.characters.map((c) => (
|
||||||
|
<div key={c.name} className={card}>
|
||||||
|
<p className="font-semibold text-amber-400">{c.name}</p>
|
||||||
|
<p className="text-sm">{t('level')} {c.level}</p>
|
||||||
|
<p className="text-sm text-amber-200/70">
|
||||||
|
{c.gold}g {c.silver}s {c.copper}c
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
</main>
|
</main>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import type { RowDataPacket } from 'mysql2'
|
||||||
|
import { db, DB } from './db'
|
||||||
|
import type { SessionData } from './session'
|
||||||
|
|
||||||
|
export interface Character {
|
||||||
|
name: string
|
||||||
|
level: number
|
||||||
|
gold: number
|
||||||
|
silver: number
|
||||||
|
copper: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AccountDashboard {
|
||||||
|
bnetEmail: string
|
||||||
|
gameAccount: string
|
||||||
|
dp: number
|
||||||
|
vp: number
|
||||||
|
battlepayCredits: number
|
||||||
|
securityTokenDate: string | null
|
||||||
|
characters: Character[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Datos del panel de cuenta. Resiliente si las BD de AzerothCore no están pobladas. */
|
||||||
|
export async function getAccountDashboard(session: SessionData): Promise<AccountDashboard> {
|
||||||
|
const accountId = session.accountId ?? 0
|
||||||
|
|
||||||
|
let dp = 0
|
||||||
|
let vp = 0
|
||||||
|
try {
|
||||||
|
const [p] = await db(DB.default).query<RowDataPacket[]>(
|
||||||
|
'SELECT dp, vp FROM home_api_points WHERE accountID = ?',
|
||||||
|
[accountId],
|
||||||
|
)
|
||||||
|
if (p[0]) {
|
||||||
|
dp = p[0].dp
|
||||||
|
vp = p[0].vp
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
|
||||||
|
let battlepayCredits = 0
|
||||||
|
try {
|
||||||
|
const [c] = await db(DB.auth).query<RowDataPacket[]>(
|
||||||
|
'SELECT battlePayCredits FROM battlenet_accounts WHERE id = ?',
|
||||||
|
[session.bnetId ?? 0],
|
||||||
|
)
|
||||||
|
if (c[0]?.battlePayCredits != null) battlepayCredits = c[0].battlePayCredits
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
|
||||||
|
let securityTokenDate: string | null = null
|
||||||
|
try {
|
||||||
|
const [s] = await db(DB.default).query<RowDataPacket[]>(
|
||||||
|
'SELECT created_at FROM home_securitytoken WHERE user_id = ? ORDER BY created_at DESC LIMIT 1',
|
||||||
|
[accountId],
|
||||||
|
)
|
||||||
|
if (s[0]) securityTokenDate = new Date(s[0].created_at).toISOString()
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
|
||||||
|
let characters: Character[] = []
|
||||||
|
try {
|
||||||
|
const [ch] = await db(DB.characters).query<RowDataPacket[]>(
|
||||||
|
'SELECT name, level, money FROM characters WHERE account = ?',
|
||||||
|
[accountId],
|
||||||
|
)
|
||||||
|
characters = ch.map((r) => ({
|
||||||
|
name: r.name,
|
||||||
|
level: r.level,
|
||||||
|
gold: Math.floor(r.money / 10000),
|
||||||
|
silver: Math.floor((r.money % 10000) / 100),
|
||||||
|
copper: r.money % 100,
|
||||||
|
}))
|
||||||
|
} catch {
|
||||||
|
/* la BD de personajes puede no estar poblada */
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
bnetEmail: session.bnetEmail ?? '',
|
||||||
|
gameAccount: session.username ?? '',
|
||||||
|
dp,
|
||||||
|
vp,
|
||||||
|
battlepayCredits,
|
||||||
|
securityTokenDate,
|
||||||
|
characters,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,7 +44,17 @@
|
|||||||
"title": "My account",
|
"title": "My account",
|
||||||
"bnetAccount": "Account (Battle.net)",
|
"bnetAccount": "Account (Battle.net)",
|
||||||
"gameAccount": "Game account",
|
"gameAccount": "Game account",
|
||||||
"logout": "Log out"
|
"logout": "Log out",
|
||||||
|
"points": "Points",
|
||||||
|
"dp": "DP",
|
||||||
|
"vp": "VP",
|
||||||
|
"battlepayCredits": "Battlepay credits",
|
||||||
|
"securityToken": "Security token",
|
||||||
|
"requested": "Requested",
|
||||||
|
"notRequested": "Not requested",
|
||||||
|
"characters": "My characters",
|
||||||
|
"level": "Level",
|
||||||
|
"noCharacters": "You have no characters yet."
|
||||||
},
|
},
|
||||||
"SelectAccount": {
|
"SelectAccount": {
|
||||||
"title": "Select your game account",
|
"title": "Select your game account",
|
||||||
|
|||||||
@@ -44,7 +44,17 @@
|
|||||||
"title": "Mi cuenta",
|
"title": "Mi cuenta",
|
||||||
"bnetAccount": "Cuenta (Battle.net)",
|
"bnetAccount": "Cuenta (Battle.net)",
|
||||||
"gameAccount": "Cuenta de juego",
|
"gameAccount": "Cuenta de juego",
|
||||||
"logout": "Cerrar sesión"
|
"logout": "Cerrar sesión",
|
||||||
|
"points": "Puntos",
|
||||||
|
"dp": "PD",
|
||||||
|
"vp": "PV",
|
||||||
|
"battlepayCredits": "Créditos Battlepay",
|
||||||
|
"securityToken": "Token de seguridad",
|
||||||
|
"requested": "Solicitado",
|
||||||
|
"notRequested": "Sin solicitar",
|
||||||
|
"characters": "Mis personajes",
|
||||||
|
"level": "Nivel",
|
||||||
|
"noCharacters": "No tienes personajes todavía."
|
||||||
},
|
},
|
||||||
"SelectAccount": {
|
"SelectAccount": {
|
||||||
"title": "Selecciona tu cuenta de juego",
|
"title": "Selecciona tu cuenta de juego",
|
||||||
|
|||||||
Reference in New Issue
Block a user