63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import { RegExpUtility } from "../../../browser/text/RegExpUtitlity";
|
|
import { CryptIO } from "../../crypt/CryptIO";
|
|
import { RJLog } from "../../log/RJLog";
|
|
import { RequestHandler, RequestType } from "../RequestHandler";
|
|
import { FastifyRequest, FastifyReply } from 'fastify';
|
|
import { VariableReplacer, Variables } from "../../../browser/text/replacing/VariableReplacer";
|
|
import { ConfirmSignUpHandler } from "./confirm-signup";
|
|
import { Session } from "../Session";
|
|
import { LocationData } from "../location/LocationData";
|
|
import { ISOTimeStamp } from "../../../browser/date/ISOTimeStamp";
|
|
import { DateFormatter } from "../../../browser/date/DateFormatter";
|
|
import { UAParser } from "ua-parser-js";
|
|
import { UserIsLoggedIn } from "../requirements/user/UserIsLoggedIn";
|
|
|
|
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 )
|
|
{
|
|
let requestBody = request.body;
|
|
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;
|
|
}
|
|
);
|
|
|
|
let info = { name:user.name, email:user.email, lastLogins:lastLogins };
|
|
|
|
return this.sendDataInfo( "User Info", info );
|
|
}
|
|
} |