1
1
Fork 0
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:
J. King 2020-11-11 18:50:27 -05:00
parent eb2fe522bf
commit dde9d7a28a
2 changed files with 20 additions and 11 deletions

View file

@ -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;
}

View file

@ -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 {
}