2017-02-26 17:09:44 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-02-26 17:09:44 +00:00
|
|
|
declare(strict_types=1);
|
2017-03-28 04:12:12 +00:00
|
|
|
namespace JKingWeb\Arsse\Test\User;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2017-03-28 04:12:12 +00:00
|
|
|
use JKingWeb\Arsse\Lang;
|
|
|
|
use JKingWeb\Arsse\User\Driver;
|
|
|
|
use JKingWeb\Arsse\User\Exception;
|
|
|
|
use JKingWeb\Arsse\User\ExceptionAuthz;
|
2017-02-26 17:09:44 +00:00
|
|
|
use PasswordGenerator\Generator as PassGen;
|
|
|
|
|
|
|
|
abstract class DriverSkeleton {
|
2017-04-07 01:41:21 +00:00
|
|
|
protected $db = [];
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userExists(string $user): bool {
|
2017-02-26 17:09:44 +00:00
|
|
|
return array_key_exists($user, $this->db);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userAdd(string $user, string $password = null): string {
|
2017-02-26 17:09:44 +00:00
|
|
|
$u = [
|
2017-02-28 04:04:13 +00:00
|
|
|
'password' => $password ? password_hash($password, \PASSWORD_DEFAULT) : "",
|
2017-02-26 17:09:44 +00:00
|
|
|
'rights' => Driver::RIGHTS_NONE,
|
|
|
|
];
|
|
|
|
$this->db[$user] = $u;
|
|
|
|
return $password;
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userRemove(string $user): bool {
|
2017-02-26 17:09:44 +00:00
|
|
|
unset($this->db[$user]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userList(string $domain = null): array {
|
2017-02-26 17:09:44 +00:00
|
|
|
$list = array_keys($this->db);
|
2017-08-29 14:50:31 +00:00
|
|
|
if ($domain===null) {
|
2017-02-26 17:09:44 +00:00
|
|
|
return $list;
|
|
|
|
} else {
|
|
|
|
$suffix = '@'.$domain;
|
|
|
|
$len = -1 * strlen($suffix);
|
2017-08-29 14:50:31 +00:00
|
|
|
return array_filter($list, function ($user) use ($suffix, $len) {
|
2017-02-26 17:09:44 +00:00
|
|
|
return substr_compare($user, $suffix, $len);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2017-04-07 01:41:21 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userPasswordSet(string $user, string $newPassword = null, string $oldPassword = null): string {
|
2017-02-26 17:09:44 +00:00
|
|
|
$this->db[$user]['password'] = password_hash($newPassword, \PASSWORD_DEFAULT);
|
|
|
|
return $newPassword;
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userPropertiesGet(string $user): array {
|
2017-02-26 17:09:44 +00:00
|
|
|
$out = $this->db[$user];
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userPropertiesSet(string $user, array $properties): array {
|
2017-02-26 17:09:44 +00:00
|
|
|
$this->db[$user] = array_merge($this->db[$user], $properties);
|
|
|
|
return $this->userPropertiesGet($user);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userRightsGet(string $user): int {
|
2017-02-26 17:09:44 +00:00
|
|
|
return $this->db[$user]['rights'];
|
|
|
|
}
|
2017-04-07 01:41:21 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userRightsSet(string $user, int $level): bool {
|
2017-02-26 17:09:44 +00:00
|
|
|
$this->db[$user]['rights'] = $level;
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|