From dde9d7a28a37066b124d6ad41c99464ac9dc1953 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 11 Nov 2020 18:50:27 -0500 Subject: [PATCH] Refinements to user manager A greater effort is made to keep the internal database synchronized --- lib/User.php | 21 ++++++++++++++++++++- lib/User/ExceptionNotImplemented.php | 10 ---------- 2 files changed, 20 insertions(+), 11 deletions(-) delete mode 100644 lib/User/ExceptionNotImplemented.php diff --git a/lib/User.php b/lib/User.php index afe4920..8ebee8a 100644 --- a/lib/User.php +++ b/lib/User.php @@ -49,7 +49,12 @@ class User { } public function add($user, $password = null): string { - return $this->u->userAdd($user, $password) ?? $this->u->userAdd($user, $this->generatePassword()); + $out = $this->u->userAdd($user, $password) ?? $this->u->userAdd($user, $this->generatePassword()); + // synchronize the internal database + if (!Arsse::$db->userExists($user)) { + Arsse::$db->userAdd($user, $out); + } + return $out; } public function remove(string $user): bool { @@ -70,6 +75,9 @@ class User { Arsse::$db->userPasswordSet($user, $out); // also invalidate any current sessions for the user Arsse::$db->sessionDestroy($user); + } else { + // if the user does not exist, add it with the new password + Arsse::$db->userAdd($user, $out); } return $out; } @@ -81,6 +89,10 @@ class User { Arsse::$db->userPasswordSet($user, null); // also invalidate any current sessions for the user Arsse::$db->sessionDestroy($user); + } else { + // if the user does not exist + Arsse::$db->userAdd($user, ""); + Arsse::$db->userPasswordSet($user, null); } return $out; } @@ -91,6 +103,10 @@ class User { public function propertiesGet(string $user): array { $extra = $this->u->userPropertiesGet($user); + // synchronize the internal database + if (!Arsse::$db->userExists($user)) { + Arsse::$db->userAdd($user, $this->generatePassword()); + } // unconditionally retrieve from the database to get at least the user number, and anything else the driver does not provide $out = Arsse::$db->userPropertiesGet($user); // layer on the driver's data @@ -125,6 +141,9 @@ class User { } $out = $this->u->userPropertiesSet($user, $in); // synchronize the internal database + if (!Arsse::$db->userExists($user)) { + Arsse::$db->userAdd($user, $this->generatePassword()); + } Arsse::$db->userPropertiesSet($user, $out); return $out; } diff --git a/lib/User/ExceptionNotImplemented.php b/lib/User/ExceptionNotImplemented.php deleted file mode 100644 index 12518ac..0000000 --- a/lib/User/ExceptionNotImplemented.php +++ /dev/null @@ -1,10 +0,0 @@ -