This repository has been archived on 2024-08-28. You can view files and clone it, but cannot push or open issues or pull requests.
satori-services/public/get-user-for-tetrio.php
2022-07-04 00:07:38 +00:00

47 lines
1.1 KiB
PHP

<?php
$config = parse_ini_file(__DIR__ . '/../config/flashii.ini');
chdir($config['msz-path']);
require_once 'misuzu.php';
header('Content-Type: application/json; charset=utf-8');
$userId = (int)filter_input(INPUT_GET, 'u', FILTER_SANITIZE_NUMBER_INT);
if($userId < 1) {
echo '[]';
return;
}
try {
$userInfo = \Misuzu\Users\User::byId($userId);
} catch(\Misuzu\Users\UserNotFoundException $ex) {
http_response_code(404);
echo '[]';
return;
}
$fields = $userInfo->profileFields();
$discord = '';
foreach($fields as $field)
if($field->field_key === 'discord') {
$discord = $field->field_value;
break;
}
$regAddr = $userInfo->getRegisterRemoteAddress();
$lastAddr = $userInfo->getLastRemoteAddress();
if(strpos($regAddr, ':') === false)
$regAddr = '::ffff:' . $regAddr;
if(strpos($lastAddr, ':') === false)
$lastAddr = '::ffff:' . $lastAddr;
echo json_encode([
'id' => $userInfo->getId(),
'name' => $userInfo->getUsername(),
'email' => $userInfo->getEmailAddress(),
'reg_addr' => $regAddr,
'last_addr' => $lastAddr,
'asscord' => $discord,
]);