diff --git a/4dev/tests/ACL/CoreLibsACLLoginTest.php b/4dev/tests/ACL/CoreLibsACLLoginTest.php index a60f6f62..17f78545 100644 --- a/4dev/tests/ACL/CoreLibsACLLoginTest.php +++ b/4dev/tests/ACL/CoreLibsACLLoginTest.php @@ -265,7 +265,7 @@ final class CoreLibsACLLoginTest extends TestCase 'ajax_post_action' => 'login', ], ], - 'load, session euid set only, php error' => [ + 'load, session ecuuid set only, php error' => [ [ 'page_name' => 'edit_users.php', ], @@ -273,8 +273,8 @@ final class CoreLibsACLLoginTest extends TestCase [], [ 'EUID' => 1, - 'ECUID' => 'abc', - 'ECUUID' => '1233456-1234-1234-1234-123456789012', + 'EUCUID' => 'abc', + 'EUCUUID' => '1233456-1234-1234-1234-123456789012', ], 2, [], @@ -293,8 +293,8 @@ final class CoreLibsACLLoginTest extends TestCase [], [ 'EUID' => 1, - 'ECUID' => 'abc', - 'ECUUID' => '1233456-1234-1234-1234-123456789012', + 'EUCUID' => 'abc', + 'EUCUUID' => 'SET_EUCUUID_IN_TEST', 'USER_NAME' => '', 'GROUP_NAME' => '', 'ADMIN' => 1, @@ -1176,6 +1176,11 @@ final class CoreLibsACLLoginTest extends TestCase $_POST[$post_var] = $post_value; } + // set ingoing session cuuid if requested + if (isset($session['EUCUUID']) && $session['EUCUUID'] == 'SET_EUCUUID_IN_TEST') { + $session['EUCUUID'] = self::$edit_user_cuuid; + } + // set _SESSION data foreach ($session as $session_var => $session_value) { $_SESSION[$session_var] = $session_value; @@ -1435,8 +1440,18 @@ final class CoreLibsACLLoginTest extends TestCase // run test try { // preset, we cannot set that in the provider - $expected['check_access_cuid'] = self::$edit_access_cuid; - $mock_settings['edit_access_cuid'] = self::$edit_access_cuid; + if ( + isset($expected['check_access_cuid']) && + $expected['check_access_cuid'] == 'SET_EDIT_ACCESS_CUID_IN_TEST' + ) { + $expected['check_access_cuid'] = self::$edit_access_cuid; + } + if ( + isset($mock_settings['edit_access_cuid']) && + $mock_settings['edit_access_cuid'] == 'SET_EDIT_ACCESS_CUID_IN_TEST' + ) { + $mock_settings['edit_access_cuid'] = self::$edit_access_cuid; + } // if ajax call // check if parameter, or globals (old type) // else normal call diff --git a/www/admin/class_test.login.php b/www/admin/class_test.login.php index bdf414b5..e5bbc6d4 100644 --- a/www/admin/class_test.login.php +++ b/www/admin/class_test.login.php @@ -99,8 +99,8 @@ echo "ACL: " . Support::printAr($login->loginGetAcl()) . "
"; echo "ACL (MIN): " . Support::printAr($login->loginGetAcl()['min'] ?? []) . "
"; echo "LOCALE: " . Support::printAr($login->loginGetLocale()) . "
"; -echo "ECUID: " . $login->loginGetEcuid() . "
"; -echo "ECUUID: " . $login->loginGetEcuuid() . "
"; +echo "ECUID: " . $login->loginGetEuCuid() . "
"; +echo "ECUUID: " . $login->loginGetEuCuuid() . "
"; echo "
"; // set + check edit access id diff --git a/www/lib/CoreLibs/ACL/Login.php b/www/lib/CoreLibs/ACL/Login.php index a39dbaa8..1421f04c 100644 --- a/www/lib/CoreLibs/ACL/Login.php +++ b/www/lib/CoreLibs/ACL/Login.php @@ -75,18 +75,18 @@ use CoreLibs\Convert\Json; class Login { /** @var ?int the user id var*/ - private ?int $euid; + private ?int $edit_user_id; /** @var ?string the user cuid (note will be super seeded with uuid v4 later) */ - private ?string $ecuid; + private ?string $edit_user_cuid; /** @var ?string UUIDv4, will superseed the ecuid and replace euid as login id */ - private ?string $ecuuid; + private ?string $edit_user_cuuid; /** @var string _GET/_POST loginUserId parameter for non password login */ private string $login_user_id = ''; /** @var string source, either _GET or _POST or empty */ private string $login_user_id_source = ''; /** @var bool set to true if illegal characters where found in the login user id string */ private bool $login_user_id_unclear = false; - // is set to one if login okay, or EUID is set and user is okay to access this page + // is set to one if login okay, or EUCUUID is set and user is okay to access this page /** @var bool */ private bool $permission_okay = false; /** @var string pressed login */ @@ -262,7 +262,7 @@ class Login ], // actually obsolete '100' => [ - 'msg' => '[EUID] came in as GET/POST!', + 'msg' => '[EUCUUID] came in as GET/POST!', 'flag' => 'e', ], // query errors @@ -769,7 +769,7 @@ class Login private function loginLoginUser(): void { // if pressed login at least and is not yet loggined in - if ($this->euid || (!$this->login && !$this->login_user_id)) { + if ($this->edit_user_cuuid || (!$this->login && !$this->login_user_id)) { return; } // if not username AND password where given @@ -939,13 +939,13 @@ class Login } // normal user processing // set class var and session var - $this->euid = (int)$res['edit_user_id']; - $this->ecuid = (string)$res['cuid']; - $this->ecuuid = (string)$res['cuuid']; + $this->edit_user_id = (int)$res['edit_user_id']; + $this->edit_user_cuid = (string)$res['cuid']; + $this->edit_user_cuuid = (string)$res['cuuid']; $this->session->setMany([ - 'EUID' => $this->euid, - 'ECUID' => $this->ecuid, - 'ECUUID' => $this->ecuuid, + 'EUID' => $this->edit_user_id, // DEPRECATED + 'EUCUID' => $this->edit_user_cuid, + 'EUCUUID' => $this->edit_user_cuuid, ]); // check if user is okay $this->loginCheckPermissions(); @@ -962,7 +962,7 @@ class Login SET login_user_id_last_revalidate = NOW() WHERE edit_user_id = $1 SQL; - $this->db->dbExecParams($q, [$this->euid]); + $this->db->dbExecParams($q, [$this->edit_user_id]); } $locale = $res['locale'] ?? 'en'; $encoding = $res['encoding'] ?? 'UTF-8'; @@ -1014,7 +1014,7 @@ class Login login_error_date_first = NULL WHERE edit_user_id = $1 SQL; - $this->db->dbExecParams($q, [$this->euid]); + $this->db->dbExecParams($q, [$this->edit_user_id]); } $edit_page_ids = []; $pages = []; @@ -1022,7 +1022,7 @@ class Login // set pages access $q = << $res['edit_page_id'], 'cuid' => $res['cuid'], + 'cuuid' => $res['cuuid'], // for reference of content data on a differen page 'content_alias_uid' => $res['content_alias_uid'], 'hostname' => $res['hostname'], @@ -1096,7 +1097,7 @@ class Login // get the page content and add them to the page $q = << $res['name'], 'uid' => $res['uid'], + 'cuid' => $res['cuid'], + 'cuuid' => $res['cuuid'], 'online' => $res['online'], 'order' => $res['order_number'], // access name and level @@ -1123,7 +1126,7 @@ class Login // load the edit_access user rights $q = <<db->dbReturnParams($q, [$this->euid]))) { + while (is_array($res = $this->db->dbReturnParams($q, [$this->edit_user_id]))) { // read edit access data fields and drop them into the unit access array $q_sub = << (int)$res['edit_access_id'], // DEPRECATED + 'cuuid' => $res['cuuid'], 'acl_level' => $res['level'], 'acl_type' => $res['type'], 'name' => $res['name'], @@ -1262,8 +1266,8 @@ class Login $this->acl['user_name'] = $_SESSION['USER_NAME']; $this->acl['group_name'] = $_SESSION['GROUP_NAME']; // edit user cuid - $this->acl['ecuid'] = $_SESSION['ECUID']; - $this->acl['ecuuid'] = $_SESSION['ECUUID']; + $this->acl['eucuid'] = $_SESSION['EUCUID']; + $this->acl['eucuuid'] = $_SESSION['EUCUUID']; // set additional acl $this->acl['additional_acl'] = [ 'user' => $_SESSION['USER_ADDITIONAL_ACL'], @@ -1701,15 +1705,15 @@ class Login $event = 'No Permission'; } // prepare for log - if ($this->euid) { + if ($this->edit_user_cuuid) { // get user from user table $q = <<db->dbReturnRowParams($q, [$this->euid]))) { + if (is_array($res = $this->db->dbReturnRowParams($q, [$this->edit_user_cuuid]))) { $username = $res['username']; } } // if euid is set, get username (or try) @@ -2023,10 +2027,10 @@ HTML; empty($username) ? $this->session->get('USER_NAME') ?? '' : $username, is_numeric($this->session->get('EUID')) ? $this->session->get('EUID') : null, - is_string($this->session->get('ECUID')) ? - $this->session->get('ECUID') : null, - !empty($this->session->get('ECUUID')) && Uids::validateUuuidv4($this->session->get('ECUUID')) ? - $this->session->get('ECUUID') : null, + is_string($this->session->get('EUCUID')) ? + $this->session->get('EUCUID') : null, + !empty($this->session->get('EUCUUID')) && Uids::validateUuuidv4($this->session->get('EUCUUID')) ? + $this->session->get('EUCUUID') : null, (string)$event, (string)$error, $data_write, @@ -2153,10 +2157,8 @@ HTML; } } // if there is none, there is none, saves me POST/GET check - $this->euid = (int)($this->session->get('EUID') ?? 0); - // TODO: allow load from cuid - // $this->ecuid = (string)($this->session->get('ECUID') ?? ''); - // $this->ecuuid = (string)($this->session->get('ECUUID') ?? ''); + // $this->euid = (int)($this->session->get('EUID') ?? 0); + $this->edit_user_cuuid = (string)($this->session->get('EUCUUID') ?? ''); // get login vars, are so, can't be changed // prepare // pass on vars to Object vars @@ -2337,7 +2339,7 @@ HTML; return $this->session->get('PAGES'); } - // MARK: logged in uid(pk)/cuid/eccuid + // MARK: logged in uid(pk)/cuid/ecuuid /** * Get the current set EUID (edit user id) @@ -2346,27 +2348,33 @@ HTML; */ public function loginGetEuid(): string { - return (string)$this->euid; + return (string)$this->edit_user_id; } /** - * Get the current set ECUID (edit user cuid) + * Get the current set EUCUID (edit user cuid) * - * @return string ECUID as string + * @return string EUCUID as string */ - public function loginGetEcuid(): string + public function loginGetEuCuid(): string { - return (string)$this->ecuid; + return (string)$this->edit_user_cuid; } /** - * Get the current set ECUUID (edit user cuuid) + * Get the current set EUCUUID (edit user cuuid) * - * @return string ECUUID as string + * @return string EUCUUID as string + * @deprecated Wrong name, use ->loginGetEuCuuid */ public function loginGetEcuuid(): string { - return (string)$this->ecuuid; + return (string)$this->edit_user_cuuid; + } + + public function loginGetEuCuuid(): string + { + return (string)$this->edit_user_cuuid; } // MARK: get error messages @@ -2515,9 +2523,9 @@ HTML; // unset session vars set/used in this login $this->session->sessionDestroy(); // unset euid - $this->euid = null; - $this->ecuid = null; - $this->ecuuid = null; + $this->edit_user_id = null; + $this->edit_user_cuid = null; + $this->edit_user_cuuid = null; // then prints the login screen again $this->permission_okay = false; } @@ -2534,7 +2542,7 @@ HTML; // start with not allowed $this->permission_okay = false; // bail for no euid (no login) - if (empty($this->euid)) { + if (empty($this->edit_user_cuuid)) { return $this->permission_okay; } // euid must match ecuid and ecuuid @@ -2544,7 +2552,7 @@ HTML; } $q = <<db->dbReturnRowParams($q, [$this->euid, $this->page_name]); + $res = $this->db->dbReturnRowParams($q, [$this->edit_user_cuuid, $this->page_name]); if (!is_array($res)) { $this->login_error = 109; return $this->permission_okay; @@ -2622,12 +2630,14 @@ HTML; } else { $this->login_error = 103; } - // set ECUID - $this->ecuid = (string)$res['cuid']; - $this->ecuuid = (string)$res['cuuid']; + // set all the internal vars + $this->edit_user_id = (int)$res['edit_user_id']; + $this->edit_user_cuid = (string)$res['cuid']; + $this->edit_user_cuuid = (string)$res['cuuid']; $this->session->setMany([ - 'ECUID' => $this->ecuid, - 'ECUUID' => $this->ecuuid, + 'EUID' => $this->edit_user_id, // DEPRECATED + 'EUCUID' => $this->edit_user_cuid, + 'EUCUUID' => $this->edit_user_cuuid, ]); // if called from public, so we can check if the permissions are ok return $this->permission_okay;