mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Refinements to user manager
A greater effort is made to keep the internal database synchronized
This commit is contained in:
parent
eb2fe522bf
commit
dde9d7a28a
2 changed files with 20 additions and 11 deletions
21
lib/User.php
21
lib/User.php
|
@ -49,7 +49,12 @@ class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add($user, $password = null): string {
|
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 {
|
public function remove(string $user): bool {
|
||||||
|
@ -70,6 +75,9 @@ class User {
|
||||||
Arsse::$db->userPasswordSet($user, $out);
|
Arsse::$db->userPasswordSet($user, $out);
|
||||||
// also invalidate any current sessions for the user
|
// also invalidate any current sessions for the user
|
||||||
Arsse::$db->sessionDestroy($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;
|
return $out;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +89,10 @@ class User {
|
||||||
Arsse::$db->userPasswordSet($user, null);
|
Arsse::$db->userPasswordSet($user, null);
|
||||||
// also invalidate any current sessions for the user
|
// also invalidate any current sessions for the user
|
||||||
Arsse::$db->sessionDestroy($user);
|
Arsse::$db->sessionDestroy($user);
|
||||||
|
} else {
|
||||||
|
// if the user does not exist
|
||||||
|
Arsse::$db->userAdd($user, "");
|
||||||
|
Arsse::$db->userPasswordSet($user, null);
|
||||||
}
|
}
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
@ -91,6 +103,10 @@ class User {
|
||||||
|
|
||||||
public function propertiesGet(string $user): array {
|
public function propertiesGet(string $user): array {
|
||||||
$extra = $this->u->userPropertiesGet($user);
|
$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
|
// 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);
|
$out = Arsse::$db->userPropertiesGet($user);
|
||||||
// layer on the driver's data
|
// layer on the driver's data
|
||||||
|
@ -125,6 +141,9 @@ class User {
|
||||||
}
|
}
|
||||||
$out = $this->u->userPropertiesSet($user, $in);
|
$out = $this->u->userPropertiesSet($user, $in);
|
||||||
// synchronize the internal database
|
// synchronize the internal database
|
||||||
|
if (!Arsse::$db->userExists($user)) {
|
||||||
|
Arsse::$db->userAdd($user, $this->generatePassword());
|
||||||
|
}
|
||||||
Arsse::$db->userPropertiesSet($user, $out);
|
Arsse::$db->userPropertiesSet($user, $out);
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
<?php
|
|
||||||
/** @license MIT
|
|
||||||
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
||||||
* See LICENSE and AUTHORS files for details */
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
namespace JKingWeb\Arsse\User;
|
|
||||||
|
|
||||||
class ExceptionNotImplemented extends Exception {
|
|
||||||
}
|
|
Loading…
Reference in a new issue