Add login for Razer Forge TV
authorChristian Weiske <cweiske@cweiske.de>
Sun, 8 Oct 2023 07:59:09 +0000 (09:59 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sun, 8 Oct 2023 07:59:09 +0000 (09:59 +0200)
www/.htaccess
www/api/razer/session [new file with mode: 0644]
www/api/razer/session.php [new file with mode: 0644]
www/api/v1/gamers/me.json
www/api/v1/gamers/me.php

index 8a9dc04187e7685c1c5111a58efaaca8d066dd6a..5ba02ede2a2243ba20f41878b70aa7a3a00caaa9 100644 (file)
@@ -44,7 +44,8 @@ RewriteRule ^api/v1/gamers$ /api/v1/gamers/register-error.json [R=400,END]
     DirectorySlash Off
 </Files>
 
-#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 (file)
index 0000000..3454a4d
--- /dev/null
@@ -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 (file)
index 0000000..e32915b
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/**
+ * Store the desired username during the login process
+ *
+ * It will be read by the Razer Forge TV when calling api/v1/gamers/me.
+ *
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @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';
index 242f5f06e5a72b4dbd8b6e7f80397ba211d307a9..699922a7cd2d811605e3075a613a2205b5dfc341 100644 (file)
@@ -4,6 +4,8 @@
         "settings": {},
         "founder": false,
         "email": "stouyapi@example.org",
-        "username": "stouyapi"
+        "username": "stouyapi",
+        "nickname": "stouyapi",
+        "avatar": null
     }
 }
index 1f20900f6d40e063d388f9069b6ea883770578ba..742e54476c5756c1416c0d8bc8d7737de0f8b06c 100644 (file)
@@ -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";
 ?>