From 2baa2dec47c3704029f7d3f2f0a9d43f5bc9bafb Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sun, 8 Oct 2023 09:59:09 +0200 Subject: [PATCH] Add login for Razer Forge TV --- www/.htaccess | 3 ++- www/api/razer/session | 3 +++ www/api/razer/session.php | 23 +++++++++++++++++++++++ www/api/v1/gamers/me.json | 4 +++- www/api/v1/gamers/me.php | 12 +++++++++++- 5 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 www/api/razer/session create mode 100644 www/api/razer/session.php diff --git a/www/.htaccess b/www/.htaccess index 8a9dc04..5ba02ed 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -44,7 +44,8 @@ RewriteRule ^api/v1/gamers$ /api/v1/gamers/register-error.json [R=400,END] DirectorySlash Off -#Disable the next two lines to have static usernames only +#Disable the next three lines to have static usernames only +RewriteRule ^api/razer/session$ /api/razer/session.php [END] RewriteRule ^api/v1/gamers/me$ /api/v1/gamers/me.php [END] RewriteRule ^api/v1/sessions$ /api/v1/sessions.php [END] diff --git a/www/api/razer/session b/www/api/razer/session new file mode 100644 index 0000000..3454a4d --- /dev/null +++ b/www/api/razer/session @@ -0,0 +1,3 @@ +{ + "token": "00702342-0000-1111-2222-c3e1500cafe1" +} diff --git a/www/api/razer/session.php b/www/api/razer/session.php new file mode 100644 index 0000000..e32915b --- /dev/null +++ b/www/api/razer/session.php @@ -0,0 +1,23 @@ + + * @see api/razer/session + * @see api/v1/gamers/me + */ + +if (!isset($_POST['email'])) { + header('HTTP/1.0 400 Bad Request'); + header('Content-type: application/json'); + echo '{"error":{"message":"E-Mail missing","code": 2001}}' . "\n"; + exit(1); +} +$email = $_POST['email']; + +//we use the ouya username storage code here +// and simply use the part before the @ in the e-mail as username. +list($_POST['username']) = explode('@', $email); +require __DIR__ . '/../v1/sessions.php'; diff --git a/www/api/v1/gamers/me.json b/www/api/v1/gamers/me.json index 242f5f0..699922a 100644 --- a/www/api/v1/gamers/me.json +++ b/www/api/v1/gamers/me.json @@ -4,6 +4,8 @@ "settings": {}, "founder": false, "email": "stouyapi@example.org", - "username": "stouyapi" + "username": "stouyapi", + "nickname": "stouyapi", + "avatar": null } } diff --git a/www/api/v1/gamers/me.php b/www/api/v1/gamers/me.php index 1f20900..742e544 100644 --- a/www/api/v1/gamers/me.php +++ b/www/api/v1/gamers/me.php @@ -6,6 +6,11 @@ * @see api/v1/sessions */ $dbFile = __DIR__ . '/../../../../data/usernames.sqlite3'; +$cfgFile = __DIR__ . '/../../../../config.php'; +if (file_exists($cfgFile)) { + include $cfgFile; +} + $ip = $_SERVER['REMOTE_ADDR']; if ($ip == '') { @@ -40,13 +45,18 @@ if ($row === false) { $data = json_decode(file_get_contents('me.json')); $data->gamer->username = $row['username']; +$data->gamer->nickname = $row['username']; switch (strtolower($row['username'])) { case 'cweiske': + $data->gamer->founder = true; + $data->gamer->avatar = $GLOBALS['baseUrl'] . 'avatars/cweiske.png'; + break; case 'szeraax': $data->gamer->founder = true; + break; } header('Content-type: application/json'); -echo json_encode($data) . "\n"; +echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"; ?> -- 2.30.2