2016-10-28 12:27:35 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
2017-03-28 04:12:12 +00:00
|
|
|
namespace JKingWeb\Arsse\User\Internal;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2017-07-17 11:47:57 +00:00
|
|
|
use JKingWeb\Arsse\Arsse;
|
2017-07-21 02:40:09 +00:00
|
|
|
use JKingWeb\Arsse\User\Exception;
|
2016-10-28 12:27:35 +00:00
|
|
|
|
2017-04-07 01:41:21 +00:00
|
|
|
trait InternalFunctions {
|
2017-02-16 20:29:42 +00:00
|
|
|
protected $actor = [];
|
2017-02-18 00:22:50 +00:00
|
|
|
|
2017-03-28 22:50:00 +00:00
|
|
|
public function __construct() {
|
2017-02-18 00:22:50 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function auth(string $user, string $password): bool {
|
2017-07-21 02:40:09 +00:00
|
|
|
try {
|
|
|
|
$hash = Arsse::$db->userPasswordGet($user);
|
2017-08-29 14:50:31 +00:00
|
|
|
} catch (Exception $e) {
|
2017-07-21 02:40:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
if ($password==="" && $hash==="") {
|
2017-07-21 02:40:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-02-16 20:29:42 +00:00
|
|
|
return password_verify($password, $hash);
|
|
|
|
}
|
2016-10-28 12:27:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userExists(string $user): bool {
|
2017-07-21 02:40:09 +00:00
|
|
|
return Arsse::$db->userExists($user);
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2016-10-28 12:27:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userAdd(string $user, string $password = null): string {
|
2017-07-21 02:40:09 +00:00
|
|
|
return Arsse::$db->userAdd($user, $password);
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2016-10-28 12:27:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userRemove(string $user): bool {
|
2017-07-21 02:40:09 +00:00
|
|
|
return Arsse::$db->userRemove($user);
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2016-10-28 12:27:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userList(string $domain = null): array {
|
2017-07-21 02:40:09 +00:00
|
|
|
return Arsse::$db->userList($domain);
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
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-07-21 02:40:09 +00:00
|
|
|
return Arsse::$db->userPasswordSet($user, $newPassword);
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2016-10-28 12:27:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userPropertiesGet(string $user): array {
|
2017-07-21 02:40:09 +00:00
|
|
|
return Arsse::$db->userPropertiesGet($user);
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2016-10-28 12:27:35 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userPropertiesSet(string $user, array $properties): array {
|
2017-07-21 02:40:09 +00:00
|
|
|
return Arsse::$db->userPropertiesSet($user, $properties);
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
2016-11-04 02:54:27 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function userRightsGet(string $user): int {
|
2017-07-21 02:40:09 +00:00
|
|
|
return Arsse::$db->userRightsGet($user);
|
2017-02-16 20:29:42 +00:00
|
|
|
}
|
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-07-21 02:40:09 +00:00
|
|
|
return Arsse::$db->userRightsSet($user, $level);
|
2017-04-07 01:41:21 +00:00
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|