Unstyled browser-based activation process
[gamestick-pjgsapi.git] / src / ProfileDb.php
index 7f661b79bdac21e3df7019e6418d59815ace9e2d..5eed7262d1bbd16b246ec69f8f121b493f840a56 100644 (file)
@@ -40,6 +40,15 @@ class ProfileDb
         return $row === false ? null : $row;
     }
 
+    public function getProfileByVerificationCode(string $code): ?Profile
+    {
+        $stmt = $this->db->prepare('SELECT * FROM gamesticks WHERE verificationCode = :code');
+        $stmt->setFetchMode(PDO::FETCH_CLASS, 'Profile');
+        $stmt->execute([':code' => $code]);
+        $row = $stmt->fetch();
+        return $row === false ? null : $row;
+    }
+
     public function createProfile(string $hwId): Profile
     {
         $stmt = $this->db->prepare(
@@ -59,6 +68,26 @@ SQL
         return $this->getProfileByHardwareId($hwId);
     }
 
+    public function updateProfile(string $hwId, array $values): ?Profile
+    {
+        $params = [
+            'hwId' => $hwId,
+        ];
+
+        $sql = 'UPDATE gamesticks SET';
+        $sqlParts = [];
+        foreach ($values as $column => $value) {
+            $sqlParts[] = ' ' . $column . '= :' . $column;
+            $params[':' . $column] = $value;
+        }
+        $sql .= implode(', ', $sqlParts) . ' WHERE hwId = :hwId';
+
+        $stmt = $this->db->prepare($sql);
+        $stmt->execute($params);
+
+        return $this->getProfileByHardwareId($hwId);
+    }
+
     protected function createTablesIfNeeded()
     {
         $res = $this->db->query(