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