2025-11-11 21:46:18 +00:00
|
|
|
import { RegExpUtility } from "../../../../browser/text/RegExpUtitlity";
|
|
|
|
|
import { CryptIO } from "../../../crypt/CryptIO";
|
|
|
|
|
import { RJLog } from "../../../log/RJLog";
|
|
|
|
|
import { RequestHandler, RequestType } from "../../RequestHandler";
|
2025-11-10 17:41:48 +00:00
|
|
|
import { FastifyRequest, FastifyReply } from 'fastify';
|
2025-11-11 21:46:18 +00:00
|
|
|
import { VariableReplacer, Variables } from "../../../../browser/text/replacing/VariableReplacer";
|
2025-11-10 17:41:48 +00:00
|
|
|
import { ConfirmSignUpHandler } from "./confirm-signup";
|
2025-11-11 21:46:18 +00:00
|
|
|
import { Session } from "../../Session";
|
|
|
|
|
import { LocationData } from "../../location/LocationData";
|
|
|
|
|
import { ISOTimeStamp } from "../../../../browser/date/ISOTimeStamp";
|
|
|
|
|
import { DateFormatter } from "../../../../browser/date/DateFormatter";
|
2025-11-10 17:41:48 +00:00
|
|
|
import { UAParser } from "ua-parser-js";
|
2025-11-11 21:46:18 +00:00
|
|
|
import { UserIsLoggedIn } from "../../requirements/user/UserIsLoggedIn";
|
2025-11-10 17:41:48 +00:00
|
|
|
|
|
|
|
|
export class UserLoginDataInfo
|
|
|
|
|
{
|
|
|
|
|
time:string;
|
|
|
|
|
location:LocationData;
|
|
|
|
|
app:string;
|
|
|
|
|
os:string;
|
|
|
|
|
deviceType:string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class InfoHandler extends RequestHandler
|
|
|
|
|
{
|
|
|
|
|
static url = "/info";
|
|
|
|
|
constructor()
|
|
|
|
|
{
|
|
|
|
|
super( RequestType.POST, InfoHandler.url, [ new UserIsLoggedIn() ] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async _handle( request:FastifyRequest, reply:FastifyReply )
|
|
|
|
|
{
|
2025-11-11 13:13:39 +00:00
|
|
|
let requestBody = request.body;
|
2025-11-10 17:41:48 +00:00
|
|
|
let tokenData = requestBody as { token:string };
|
|
|
|
|
let tokenID = tokenData.token;
|
|
|
|
|
|
|
|
|
|
let session = this._ums._sessions.get( tokenID );
|
|
|
|
|
let user = await this._ums.userDB.byID( session.userID );
|
|
|
|
|
|
|
|
|
|
let lastLogins = user.lastLogins.map(
|
|
|
|
|
( ld )=>
|
|
|
|
|
{
|
|
|
|
|
let ui = new UserLoginDataInfo();
|
|
|
|
|
ui.time = DateFormatter.forUsers( ISOTimeStamp.toDate( ld.timeStamp ) );
|
|
|
|
|
ui.location = ld.location;
|
|
|
|
|
|
|
|
|
|
let parser = new UAParser( ld.userAgent );
|
|
|
|
|
let result = parser.getResult();
|
|
|
|
|
ui.app = result?.browser?.name || "-";
|
|
|
|
|
ui.os = result?.os?.name || "-";
|
|
|
|
|
ui.deviceType = result?.device?.type || "desktop";
|
|
|
|
|
|
|
|
|
|
return ui;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2025-11-11 21:46:18 +00:00
|
|
|
let info = { name:user.name, id:user.id, email:user.email, lastLogins:lastLogins };
|
2025-11-10 17:41:48 +00:00
|
|
|
|
|
|
|
|
return this.sendDataInfo( "User Info", info );
|
|
|
|
|
}
|
|
|
|
|
}
|