1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 17:12:41 +00:00
Arsse/tests/lib/User/DriverSkeleton.php

69 lines
2 KiB
PHP
Raw Normal View History

<?php
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;
use PasswordGenerator\Generator as PassGen;
abstract class DriverSkeleton {
protected $db = [];
2017-08-29 14:50:31 +00:00
public function userExists(string $user): bool {
return array_key_exists($user, $this->db);
}
2017-08-29 14:50:31 +00:00
public function userAdd(string $user, string $password = null): string {
$u = [
2017-02-28 04:04:13 +00:00
'password' => $password ? password_hash($password, \PASSWORD_DEFAULT) : "",
'rights' => Driver::RIGHTS_NONE,
];
$this->db[$user] = $u;
return $password;
}
2017-08-29 14:50:31 +00:00
public function userRemove(string $user): bool {
unset($this->db[$user]);
return true;
}
2017-08-29 14:50:31 +00:00
public function userList(string $domain = null): array {
$list = array_keys($this->db);
2017-08-29 14:50:31 +00:00
if ($domain===null) {
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) {
return substr_compare($user, $suffix, $len);
});
}
}
2017-08-29 14:50:31 +00:00
public function userPasswordSet(string $user, string $newPassword = null, string $oldPassword = null): string {
$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 {
$out = $this->db[$user];
return $out;
}
2017-08-29 14:50:31 +00:00
public function userPropertiesSet(string $user, array $properties): array {
$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 {
return $this->db[$user]['rights'];
}
2017-08-29 14:50:31 +00:00
public function userRightsSet(string $user, int $level): bool {
$this->db[$user]['rights'] = $level;
return true;
}
2017-08-29 14:50:31 +00:00
}