]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - plugins/sql_auth/SQL/user.php
Move some code around, add lookup by ID and get_current_user()
[irc/unrealircd/unrealircd-webpanel.git] / plugins / sql_auth / SQL / user.php
index cdf10a05656cc7f1981bf2a819a63bc7a4c7fd78..0c08fed0816a3023b55f60c5b17b89b77bd4373c 100644 (file)
@@ -4,15 +4,29 @@ class SQLA_User
 {
     public $id = NULL;
     public $username = NULL;
-    public $passhash = NULL;
+    protected $passhash = NULL;
     public $first_name = NULL;
     public $last_name = NULL;
 
-    function __construct(string $name)
+    /**
+     * Find a user in the database by name or ID
+     * @param string $name
+     * @param mixed $id
+     */
+    function __construct(string $name, $id = NULL)
     {
         $conn = sqlnew();
-        $prep = $conn->prepare("SELECT * FROM " . SQL_PREFIX . "users WHERE LOWER(user_name) = :name LIMIT 1");
-        $prep->execute(["name" => strtolower($name)]);
+
+        if ($id)
+        {
+            $prep = $conn->prepare("SELECT * FROM " . SQL_PREFIX . "users WHERE user_id = :id LIMIT 1");
+            $prep->execute(["id" => strtolower($id)]);
+        }
+        elseif ($name)
+        {
+            $prep = $conn->prepare("SELECT * FROM " . SQL_PREFIX . "users WHERE LOWER(user_name) = :name LIMIT 1");
+            $prep->execute(["name" => strtolower($name)]);
+        }
         $data = $prep->fetchAll();
         if ($data = $data[0])
         {
@@ -22,7 +36,24 @@ class SQLA_User
             $this->first_name = $data['first_name'] ?? NULL;
             $this->last_name = $data['last_name'] ?? NULL;
         }
-        
     }
 
+    function password_verify(string $input)
+    {
+        if (password_verify($input, $this->passhash))
+            return true;
+        return false;
+    }
+
+}
+
+
+function get_current_user() : SQLA_User|bool
+{
+    session_start();
+    if (isset($_SESSION['id']))
+    {
+        $user = new SQLA_User()
+    }
+    return false;
 }
\ No newline at end of file