From 35d05b006426e5854c7c6ceffd383a32c4f6997b Mon Sep 17 00:00:00 2001 From: Jim Mason Date: Wed, 4 Dec 2024 10:44:52 +0000 Subject: [PATCH] updated setupSSOByName to create new account if one does not already exist --- controllers/SSOCommon.php | 19 ++++++++++--------- engine/impl/User.php | 4 ++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/controllers/SSOCommon.php b/controllers/SSOCommon.php index e5a776d6..d03dc146 100644 --- a/controllers/SSOCommon.php +++ b/controllers/SSOCommon.php @@ -3,7 +3,7 @@ * Zookeeper Online * * @author Jim Mason - * @copyright Copyright (C) 1997-2023 Jim Mason + * @copyright Copyright (C) 1997-2024 Jim Mason * @link https://zookeeper.ibinx.com/ * @license GPL-3.0 * @@ -141,14 +141,15 @@ public static function setupSSOByAccount($account) { } return $retval; } - + public static function setupSSOByName($account, $name) { - $retval = false; - $row = Engine::api(IUser::class)->getUserByFullname($name); - if($row) { - Engine::api(IUser::class)->assignAccount($row["name"], $account); - $retval = self::setupSSOByAccount($account); - } - return $retval; + $api = Engine::api(IUser::class); + $row = $api->getUserByFullname($name); + if($row) + $api->assignAccount($row["name"], $account); + else + $api->createNewAccount($name, $account); + + return self::setupSSOByAccount($account); } } diff --git a/engine/impl/User.php b/engine/impl/User.php index 247fa97a..68356014 100644 --- a/engine/impl/User.php +++ b/engine/impl/User.php @@ -3,7 +3,7 @@ * Zookeeper Online * * @author Jim Mason - * @copyright Copyright (C) 1997-2022 Jim Mason + * @copyright Copyright (C) 1997-2024 Jim Mason * @link https://zookeeper.ibinx.com/ * @license GPL-3.0 * @@ -50,7 +50,7 @@ public function getUserByAccount($account) { } public function getUserByFullname($fullname) { - $query = "SELECT * FROM users WHERE realname = ?"; + $query = "SELECT * FROM users WHERE realname = ? AND ssoaccount IS NULL"; $stmt = $this->prepare($query); $stmt->bindValue(1, $fullname); return $stmt->executeAndFetch();