diff --git a/composer.json b/composer.json index 12d3c40..bc98cba 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "require": { "flashwave/index": "^0.2410", + "flashii/apii": "^0.2", "erusev/parsedown": "~1.6", "sentry/sdk": "^4.0" }, diff --git a/composer.lock b/composer.lock index 16aefdc..5c8c6a4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0fcc2129a9e1c99597116e91c7bb2df1", + "content-hash": "f71663659023233c6bbd47cc74f1d954", "packages": [ { "name": "erusev/parsedown", @@ -56,6 +56,43 @@ }, "time": "2019-12-30T22:54:17+00:00" }, + { + "name": "flashii/apii", + "version": "v0.2.1", + "source": { + "type": "git", + "url": "https://patchii.net/flashii/apii-php.git", + "reference": "6a93d31375dd7e75ff9264f3024f2208ce602f49" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpstan/phpstan": "^1.12", + "phpunit/phpunit": "^10.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Flashii\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "bsd-3-clause-clear" + ], + "authors": [ + { + "name": "flashwave", + "email": "packagist@flash.moe", + "homepage": "https://flash.moe", + "role": "mom" + } + ], + "description": "Client library for the Flashii.net API.", + "homepage": "https://api.flashii.net", + "time": "2024-11-16T16:03:42+00:00" + }, { "name": "flashwave/index", "version": "v0.2410.191603", diff --git a/public/index.php b/public/index.php index cda0723..aedf6f5 100644 --- a/public/index.php +++ b/public/index.php @@ -1,24 +1,29 @@ scopeTo('cauth'), $authToken); +$flashii = new FlashiiClient('Seria', new MisuzuCredentials($authToken), new FlashiiUrls( + $cfg->getString('apii:api', FlashiiUrls::PROD_API_URL), + $cfg->getString('apii:id', FlashiiUrls::PROD_ID_URL) +)); +$authInfo = $flashii->v1()->me(); -if($authInfo->success) { +if($authInfo !== null) { $users = $seria->getUsersContext()->getUsers(); - $users->syncChatUser($authInfo); - $sUserInfo = $users->getUser($authInfo->user_id, 'id'); + $users->syncApiUser($authInfo); + $sUserInfo = $users->getUser($authInfo->getId(), 'id'); $seria->getAuthInfo()->setInfo($sUserInfo); } else $sUserInfo = null; $seria->startCSRFP( $cfg->getString('csrfp:secret', 'mewow'), - $authInfo->success ? $authToken : (string)filter_input(INPUT_SERVER, 'REMOTE_ADDR') + $authInfo === null ? (string)filter_input(INPUT_SERVER, 'REMOTE_ADDR') : $authToken ); $seria->startTemplating(); diff --git a/src/Auth/ChatAuth.php b/src/Auth/ChatAuth.php deleted file mode 100644 index 0f99977..0000000 --- a/src/Auth/ChatAuth.php +++ /dev/null @@ -1,55 +0,0 @@ -getString('secret')); - - $login = curl_init($config->getString('endpoint')); - curl_setopt_array($login, [ - CURLOPT_AUTOREFERER => false, - CURLOPT_FAILONERROR => false, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HEADER => false, - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => http_build_query([ - 'method' => $method, - 'token' => $cookie, - 'ipaddr' => $_SERVER['REMOTE_ADDR'], - ], '', '&', PHP_QUERY_RFC3986), - CURLOPT_RETURNTRANSFER => true, - CURLOPT_TCP_FASTOPEN => true, - CURLOPT_CONNECTTIMEOUT => 2, - CURLOPT_MAXREDIRS => 2, - CURLOPT_PROTOCOLS => CURLPROTO_HTTPS, - CURLOPT_TIMEOUT => 5, - CURLOPT_USERAGENT => 'Seria', - CURLOPT_HTTPHEADER => [ - 'Content-Type: application/x-www-form-urlencoded', - 'X-SharpChat-Signature: ' . $signature, - ], - ]); - $userInfo = json_decode(curl_exec($login)); - curl_close($login); - } - - if(empty($userInfo->success)) { - $userInfo = new stdClass; - $userInfo->success = false; - $userInfo->user_id = 0; - $userInfo->username = 'Anonymous'; - $userInfo->colour_raw = 0x40000000; - $userInfo->rank = 0; - $userInfo->hierarchy = 0; - $userInfo->perms = 0; - } - - return $userInfo; - } -} diff --git a/src/Users/Users.php b/src/Users/Users.php index fcb3567..adfc4a1 100644 --- a/src/Users/Users.php +++ b/src/Users/Users.php @@ -3,6 +3,7 @@ namespace Seria\Users; use InvalidArgumentException; use RuntimeException; +use Flashii\V1\Users\V1User; use Index\XString; use Index\Colour\Colour; use Index\Db\{DbConnection,DbStatementCache}; @@ -18,21 +19,16 @@ class Users { return XString::random(48); } - public function syncChatUser(object $authInfo): void { - if(!$authInfo->success) - return; - - $userColourFixed = /*($authInfo->colour_raw & 0x40000000) ? null :*/ $authInfo->colour_raw; - $stmt = $this->cache->get('INSERT INTO ser_users (user_id, user_name, user_colour, user_rank, user_permissions) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE user_name = ?, user_colour = ?, user_rank = ?, user_permissions = ?'); - $stmt->addParameter(1, $authInfo->user_id); - $stmt->addParameter(2, $authInfo->username); - $stmt->addParameter(3, $userColourFixed); - $stmt->addParameter(4, $authInfo->rank); - $stmt->addParameter(5, $authInfo->perms); - $stmt->addParameter(6, $authInfo->username); - $stmt->addParameter(7, $userColourFixed); - $stmt->addParameter(8, $authInfo->rank); - $stmt->addParameter(9, $authInfo->perms); + public function syncApiUser(V1User $authInfo): void { + $userColourUnfixed = $authInfo->getColourRaw() ?? 0x40000000; + $stmt = $this->cache->get('INSERT INTO ser_users (user_id, user_name, user_colour, user_rank, user_permissions) VALUES (?, ?, ?, ?, 0) ON DUPLICATE KEY UPDATE user_name = ?, user_colour = ?, user_rank = ?'); + $stmt->nextParameter($authInfo->getId()); + $stmt->nextParameter($authInfo->getName()); + $stmt->nextParameter($userColourUnfixed); + $stmt->nextParameter($authInfo->getRank()); + $stmt->nextParameter($authInfo->getName()); + $stmt->nextParameter($userColourUnfixed); + $stmt->nextParameter($authInfo->getRank()); $stmt->execute(); }