security-history: acción y estado web multiidioma

La lib devolvía la acción ("Token de seguridad solicitado") y el estado del login
web ("Conexión exitosa"/"Contraseña incorrecta") en español. Ahora devuelve claves
(actionKey='tokenRequested'; statusKey='success'/'wrongPassword'/'other' + statusRaw)
y la página las traduce (History.security.action/webStatus). El coloreado rojo pasa
a depender de statusKey==='wrongPassword'. Verificado con datos reales.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-14 19:39:46 +00:00
parent 19d3c43a76
commit 16ae9f0db8
4 changed files with 31 additions and 13 deletions
+11 -9
View File
@@ -3,7 +3,7 @@ import { db, DB } from './db'
export interface ActivityEntry {
user: string
action: string
actionKey: string // clave de acción traducible (p.ej. 'tokenRequested')
ip: string
date: Date
}
@@ -13,17 +13,18 @@ export interface RealmConnection {
}
export interface WebConnection {
user: string
status: string
statusKey: 'success' | 'wrongPassword' | 'other'
statusRaw: string // texto original (para el caso 'other')
ip: string
date: Date
}
/** Traduce el estado guardado del intento de login web a la etiqueta del diseño. */
function webStatusLabel(raw: string): string {
/** Clasifica el estado guardado del intento de login web en una clave traducible. */
function webStatusKey(raw: string): 'success' | 'wrongPassword' | 'other' {
const s = (raw || '').toLowerCase()
if (s.includes('exito') || s.includes('éxito') || s.includes('success')) return 'Conexión exitosa'
if (s.includes('fracaso') || s.includes('fail') || s.includes('incorrect')) return 'Contraseña incorrecta'
return raw || '—'
if (s.includes('exito') || s.includes('éxito') || s.includes('success')) return 'success'
if (s.includes('fracaso') || s.includes('fail') || s.includes('incorrect')) return 'wrongPassword'
return 'other'
}
/**
@@ -52,7 +53,7 @@ export async function getSecurityHistory(
[accountId, limit],
)
for (const r of rows) {
activity.push({ user: displayUser, action: 'Token de seguridad solicitado', ip: String(r.ip_address || '—'), date: new Date(r.created_at) })
activity.push({ user: displayUser, actionKey: 'tokenRequested', ip: String(r.ip_address || '—'), date: new Date(r.created_at) })
}
} catch {
/* tabla ausente */
@@ -93,7 +94,8 @@ export async function getSecurityHistory(
[email, limit],
)
for (const r of rows) {
web.push({ user: displayUser, status: webStatusLabel(String(r.status)), ip: String(r.ip_address || ''), date: new Date(r.timestamp) })
const raw = String(r.status || '')
web.push({ user: displayUser, statusKey: webStatusKey(raw), statusRaw: raw, ip: String(r.ip_address || '—'), date: new Date(r.timestamp) })
}
} catch {
/* tabla ausente */