From 4d436c10df9de356b4758e7b2ce80d8f9d1c7e3b Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Thu, 20 Feb 2020 23:08:19 +0100 Subject: [PATCH 01/14] Move "NewPassword" to a common "user" console command --- src/Console/{NewPassword.php => User.php} | 38 +++++++++++++++++------ src/Core/Console.php | 4 +-- 2 files changed, 31 insertions(+), 11 deletions(-) rename src/Console/{NewPassword.php => User.php} (76%) diff --git a/src/Console/NewPassword.php b/src/Console/User.php similarity index 76% rename from src/Console/NewPassword.php rename to src/Console/User.php index 118428866..c12ab3383 100644 --- a/src/Console/NewPassword.php +++ b/src/Console/User.php @@ -24,7 +24,7 @@ namespace Friendica\Console; use Friendica\App; use Friendica\Core\L10n; use Friendica\Database\Database; -use Friendica\Model\User; +use Friendica\Model\User as UserModel; use RuntimeException; /** @@ -32,7 +32,7 @@ use RuntimeException; * * With this tool, you can set a new password for a user */ -class NewPassword extends \Asika\SimpleConsole\Console +class User extends \Asika\SimpleConsole\Console { protected $helpOptions = ['h', 'help', '?']; @@ -52,12 +52,12 @@ class NewPassword extends \Asika\SimpleConsole\Console protected function getHelp() { $help = << [] [-h|--help|-?] [-v] + bin/console user password [] [-h|--help|-?] [-v] Description - Creates a new password for a user without using the "forgot password" functionality. + Modify user settings per console commands. Options -h|--help|-? Show help information @@ -88,8 +88,8 @@ HELP; return 0; } - if (count($this->args) > 2) { - throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); + if (count($this->args) < 2) { + throw new \Asika\SimpleConsole\CommandArgsException('Not enough arguments.'); } if ($this->appMode->isInstall()) { @@ -103,14 +103,34 @@ HELP; throw new RuntimeException($this->l10n->t('User not found')); } - $password = $this->getArgument(1); + $command = $this->getArgument(1); + + switch ($command) { + case 'password': + return $this->setPassword($user); + default: + throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.'); + } + } + + /** + * Sets a new password + * + * @param array $user The user + * + * @return int Return code of this command + */ + private function setPassword(array $user) + { + $password = $this->getArgument(2); + if (is_null($password)) { $this->out($this->l10n->t('Enter new password: '), false); $password = \Seld\CliPrompt\CliPrompt::hiddenPrompt(true); } try { - $result = User::updatePassword($user['uid'], $password); + $result = UserModel::updatePassword($user['uid'], $password); if (!$this->dba->isResult($result)) { throw new \Exception($this->l10n->t('Password update failed. Please try again.')); diff --git a/src/Core/Console.php b/src/Core/Console.php index 70835db9c..86178c209 100644 --- a/src/Core/Console.php +++ b/src/Core/Console.php @@ -57,7 +57,7 @@ Commands: autoinstall Starts automatic installation of friendica based on values from htconfig.php lock Edit site locks maintenance Set maintenance mode for this node - newpassword Set a new password for a given user + user User management php2po Generate a messages.po file from a strings.php file po2php Generate a strings.php file from a messages.po file typo Checks for parse errors in Friendica files @@ -85,7 +85,7 @@ HELP; 'autoinstall' => Friendica\Console\AutomaticInstallation::class, 'lock' => Friendica\Console\Lock::class, 'maintenance' => Friendica\Console\Maintenance::class, - 'newpassword' => Friendica\Console\NewPassword::class, + 'user' => Friendica\Console\User::class, 'php2po' => Friendica\Console\PhpToPo::class, 'po2php' => Friendica\Console\PoToPhp::class, 'typo' => Friendica\Console\Typo::class, From f3f764bc39fe0210ac4cc995cf72ea99fac7bef3 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Thu, 20 Feb 2020 23:43:52 +0100 Subject: [PATCH 02/14] Add new possibility to add a user per console --- src/Console/User.php | 91 +++++++++++++++++++++------ src/Core/L10n.php | 7 ++- src/DI.php | 6 ++ src/Model/User.php | 15 +++++ src/Model/UserService.php | 125 +++++++++++++++++++++++++++++++++++++ src/Module/Admin/Users.php | 63 +++---------------- 6 files changed, 230 insertions(+), 77 deletions(-) create mode 100644 src/Model/UserService.php diff --git a/src/Console/User.php b/src/Console/User.php index c12ab3383..6db2cf84e 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -25,7 +25,9 @@ use Friendica\App; use Friendica\Core\L10n; use Friendica\Database\Database; use Friendica\Model\User as UserModel; +use Friendica\Model\UserService; use RuntimeException; +use Seld\CliPrompt\CliPrompt; /** * tool to set a new password for a user @@ -48,13 +50,16 @@ class User extends \Asika\SimpleConsole\Console * @var Database */ private $dba; + /** @var UserService */ + private $userService; protected function getHelp() { $help = << password [] [-h|--help|-?] [-v] + bin/console user password [] [-h|--help|-?] [-v] + bin/console user add [ [ [ []]]] [-h|--help|-?] [-v] Description Modify user settings per console commands. @@ -66,13 +71,14 @@ HELP; return $help; } - public function __construct(App\Mode $appMode, L10n $l10n, Database $dba, array $argv = null) + public function __construct(App\Mode $appMode, L10n $l10n, Database $dba, UserService $userService, array $argv = null) { parent::__construct($argv); $this->appMode = $appMode; $this->l10n = $l10n; $this->dba = $dba; + $this->userService = $userService; } protected function doExecute() @@ -88,26 +94,17 @@ HELP; return 0; } - if (count($this->args) < 2) { - throw new \Asika\SimpleConsole\CommandArgsException('Not enough arguments.'); - } - if ($this->appMode->isInstall()) { throw new RuntimeException('Database isn\'t ready or populated yet'); } - $nick = $this->getArgument(0); - - $user = $this->dba->selectFirst('user', ['uid'], ['nickname' => $nick]); - if (!$this->dba->isResult($user)) { - throw new RuntimeException($this->l10n->t('User not found')); - } - - $command = $this->getArgument(1); + $command = $this->getArgument(0); switch ($command) { case 'password': - return $this->setPassword($user); + return $this->password(); + case 'add': + return $this->addUser(); default: throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.'); } @@ -116,17 +113,24 @@ HELP; /** * Sets a new password * - * @param array $user The user - * * @return int Return code of this command + * + * @throws \Exception */ - private function setPassword(array $user) + private function password() { + $nick = $this->getArgument(1); + + $user = $this->dba->selectFirst('user', ['uid'], ['nickname' => $nick]); + if (!$this->dba->isResult($user)) { + throw new RuntimeException($this->l10n->t('User not found')); + } + $password = $this->getArgument(2); if (is_null($password)) { $this->out($this->l10n->t('Enter new password: '), false); - $password = \Seld\CliPrompt\CliPrompt::hiddenPrompt(true); + $password = CliPrompt::hiddenPrompt(true); } try { @@ -143,4 +147,53 @@ HELP; return 0; } + + /** + * Adds a new user based on given console arguments + * + * @return bool True, if the command was successful + * @throws \ErrorException + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + private function addUser() + { + $name = $this->getArgument(1); + $nick = $this->getArgument(2); + $email= $this->getArgument(3); + $lang = $this->getArgument(4); + + if (empty($name)) { + $this->out($this->l10n->t('Enter user name: ')); + $name = CliPrompt::prompt(); + if (empty($name)) { + throw new RuntimeException('A name must be set.'); + } + } + if (empty($nick)) { + $this->out($this->l10n->t('Enter user nickname: ')); + $nick = CliPrompt::prompt(); + if (empty($nick)) { + throw new RuntimeException('A nick name must be set.'); + } + } + if (empty($email)) { + $this->out($this->l10n->t('Enter user email address: ')); + $email = CliPrompt::prompt(); + if (empty($email)) { + throw new RuntimeException('A email address must be set.'); + } + } + + if (empty($lang)) { + $this->out($this->l10n->t('Enter a language (optional): ')); + $lang = CliPrompt::prompt(); + } + + if (empty($lang)) { + return $this->userService->createMinimal($name, $email, $nick); + } else { + return $this->userService->createMinimal($name, $email, $nick, $lang); + } + } } diff --git a/src/Core/L10n.php b/src/Core/L10n.php index cda83ac3f..8e6ee171c 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -33,6 +33,9 @@ use Psr\Log\LoggerInterface; */ class L10n { + /** @var string The default language */ + const DEFAULT = 'en'; + /** * A string indicating the current language used for translation: * - Two-letter ISO 639-1 code. @@ -64,7 +67,7 @@ class L10n $this->dba = $dba; $this->logger = $logger; - $this->loadTranslationTable(L10n::detectLanguage($server, $get, $config->get('system', 'language', 'en'))); + $this->loadTranslationTable(L10n::detectLanguage($server, $get, $config->get('system', 'language', self::DEFAULT))); $this->setSessionVariable($session); $this->setLangFromSession($session); } @@ -158,7 +161,7 @@ class L10n * * @return string The two-letter language code */ - public static function detectLanguage(array $server, array $get, string $sysLang = 'en') + public static function detectLanguage(array $server, array $get, string $sysLang = self::DEFAULT) { $lang_variable = $server['HTTP_ACCEPT_LANGUAGE'] ?? null; diff --git a/src/DI.php b/src/DI.php index 39efe2a97..b1d2b82c1 100644 --- a/src/DI.php +++ b/src/DI.php @@ -315,6 +315,12 @@ abstract class DI return self::$dice->create(Model\Storage\IStorage::class); } + /** @return Model\UserService */ + public static function userService() + { + return self::$dice->create(Model\UserService::class); + } + // // "Repository" namespace // diff --git a/src/Model/User.php b/src/Model/User.php index e4ef07e47..27b87f997 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -880,6 +880,21 @@ class User return $return; } + /** + * Sets block state for a given user + * + * @param int $uid The user id + * @param bool $block Block state (default is true) + * + * @return bool True, if successfully blocked + + * @throws Exception + */ + public static function block(int $uid, bool $block = true) + { + return DBA::update('user', ['blocked' => 0], ['uid' => $uid]); + } + /** * Sends pending registration confirmation email * diff --git a/src/Model/UserService.php b/src/Model/UserService.php new file mode 100644 index 000000000..6da45e40e --- /dev/null +++ b/src/Model/UserService.php @@ -0,0 +1,125 @@ +. + * + */ + +namespace Friendica\Model; + +use ErrorException; +use Friendica\App; +use Friendica\Core\Config\IConfig; +use Friendica\Core\L10n; +use Friendica\Network\HTTPException\InternalServerErrorException; +use Friendica\Util\Emailer; +use Friendica\Util\Strings; +use Friendica\Model\User as UserModel; +use ImagickException; + +class UserService +{ + /** @var L10n */ + private $l10n; + /** @var IConfig */ + private $config; + /** @var App\BaseURL */ + private $baseUrl; + /** @var Emailer */ + private $emailer; + + public function __construct(L10n $l10n, IConfig $config, Emailer $emailer, App\BaseURL $baseUrl) + { + $this->l10n = $l10n; + $this->config = $config; + $this->emailer = $emailer; + $this->baseUrl = $baseUrl; + } + + /** + * Creates a new user based on a minimal set and sends an email to this user + * + * @param string $name The user's name + * @param string $email The user's email address + * @param string $nick The user's nick name + * @param string $lang The user's language (default is english) + * + * @return bool True, if the user was created successfully + * @throws InternalServerErrorException + * @throws ErrorException + * @throws ImagickException + */ + public function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT) + { + if (empty($name) || + empty($email) || + empty($nick)) { + throw new InternalServerErrorException('Invalid arguments.'); + } + + $result = UserModel::create([ + 'username' => $name, + 'email' => $email, + 'nickname' => $nick, + 'verified' => 1, + 'language' => $lang + ]); + + $user = $result['user']; + $preamble = Strings::deindent($this->l10n->t(' + Dear %1$s, + the administrator of %2$s has set up an account for you.')); + $body = Strings::deindent($this->l10n->t(' + The login details are as follows: + + Site Location: %1$s + Login Name: %2$s + Password: %3$s + + You may change your password from your account "Settings" page after logging + in. + + Please take a few moments to review the other account settings on that page. + + You may also wish to add some basic information to your default profile + (on the "Profiles" page) so that other people can easily find you. + + We recommend setting your full name, adding a profile photo, + adding some profile "keywords" (very useful in making new friends) - and + perhaps what country you live in; if you do not wish to be more specific + than that. + + We fully respect your right to privacy, and none of these items are necessary. + If you are new and do not know anybody here, they may help + you to make some new and interesting friends. + + If you ever want to delete your account, you can do so at %1$s/removeme + + Thank you and welcome to %4$s.')); + + $preamble = sprintf($preamble, $user['username'], $this->config->get('config', 'sitename')); + $body = sprintf($body, $this->baseUrl->get(), $user['nickname'], $result['password'], $this->config->get('config', 'sitename')); + + $email = $this->emailer + ->newSystemMail() + ->withMessage($this->l10n->t('Registration details for %s', $this->config->get('config', 'sitename')), $preamble, $body) + ->forUser($user) + ->withRecipient($user['email']) + ->build(); + return $this->emailer->send($email); + } +} diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index f5e2d5ed3..20a31333c 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -48,72 +48,23 @@ class Users extends BaseAdmin if ($nu_name !== '' && $nu_email !== '' && $nu_nickname !== '') { try { - $result = User::create([ - 'username' => $nu_name, - 'email' => $nu_email, - 'nickname' => $nu_nickname, - 'verified' => 1, - 'language' => $nu_language - ]); + DI::userService()->createMinimal($nu_name, $nu_email, $nu_nickname, $nu_language); } catch (\Exception $ex) { notice($ex->getMessage()); return; } - - $user = $result['user']; - $preamble = Strings::deindent(DI::l10n()->t(' - Dear %1$s, - the administrator of %2$s has set up an account for you.')); - $body = Strings::deindent(DI::l10n()->t(' - The login details are as follows: - - Site Location: %1$s - Login Name: %2$s - Password: %3$s - - You may change your password from your account "Settings" page after logging - in. - - Please take a few moments to review the other account settings on that page. - - You may also wish to add some basic information to your default profile - (on the "Profiles" page) so that other people can easily find you. - - We recommend setting your full name, adding a profile photo, - adding some profile "keywords" (very useful in making new friends) - and - perhaps what country you live in; if you do not wish to be more specific - than that. - - We fully respect your right to privacy, and none of these items are necessary. - If you are new and do not know anybody here, they may help - you to make some new and interesting friends. - - If you ever want to delete your account, you can do so at %1$s/removeme - - Thank you and welcome to %4$s.')); - - $preamble = sprintf($preamble, $user['username'], DI::config()->get('config', 'sitename')); - $body = sprintf($body, DI::baseUrl()->get(), $user['nickname'], $result['password'], DI::config()->get('config', 'sitename')); - - $email = DI::emailer() - ->newSystemMail() - ->withMessage(DI::l10n()->t('Registration details for %s', DI::config()->get('config', 'sitename')), $preamble, $body) - ->forUser($user) - ->withRecipient($user['email']) - ->build(); - return DI::emailer()->send($email); } if (!empty($_POST['page_users_block'])) { - // @TODO Move this to Model\User:block($users); - DBA::update('user', ['blocked' => 1], ['uid' => $users]); - notice(DI::l10n()->tt('%s user blocked', '%s users blocked', count($users))); + if (User::block($users)) { + notice(DI::l10n()->tt('%s user blocked', '%s users blocked', count($users))); + } } if (!empty($_POST['page_users_unblock'])) { - // @TODO Move this to Model\User:unblock($users); - DBA::update('user', ['blocked' => 0], ['uid' => $users]); - notice(DI::l10n()->tt('%s user unblocked', '%s users unblocked', count($users))); + if (User::block($users, false)) { + notice(DI::l10n()->tt('%s user unblocked', '%s users unblocked', count($users))); + } } if (!empty($_POST['page_users_delete'])) { From 6aee153bbdad959cce28dd1346c135cdd843f9f8 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 21 Feb 2020 22:57:17 +0100 Subject: [PATCH 03/14] Move "User::allow()" to own method and update usages --- mod/regmod.php | 44 +------------ src/Console/User.php | 61 +++++++++++++---- src/DI.php | 6 -- src/Model/Register.php | 21 ++++++ src/Model/User.php | 131 +++++++++++++++++++++++++++++++++++-- src/Model/UserService.php | 125 ----------------------------------- src/Module/Admin/Users.php | 3 +- 7 files changed, 197 insertions(+), 194 deletions(-) delete mode 100644 src/Model/UserService.php diff --git a/mod/regmod.php b/mod/regmod.php index df1020b9f..8c71490e0 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -20,52 +20,12 @@ */ use Friendica\App; -use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Register; use Friendica\Model\User; use Friendica\Module\Security\Login; -function user_allow($hash) -{ - $register = Register::getByHash($hash); - if (!DBA::isResult($register)) { - return false; - } - - $user = User::getById($register['uid']); - if (!DBA::isResult($user)) { - exit(); - } - - Register::deleteByHash($hash); - - DBA::update('user', ['blocked' => false, 'verified' => true], ['uid' => $register['uid']]); - - $profile = DBA::selectFirst('profile', ['net-publish'], ['uid' => $register['uid']]); - - if (DBA::isResult($profile) && $profile['net-publish'] && DI::config()->get('system', 'directory')) { - $url = DI::baseUrl() . '/profile/' . $user['nickname']; - Worker::add(PRIORITY_LOW, "Directory", $url); - } - - $l10n = DI::l10n()->withLang($register['language']); - - $res = User::sendRegisterOpenEmail( - $l10n, - $user, - DI::config()->get('config', 'sitename'), - DI::baseUrl()->get(), - ($register['password'] ?? '') ?: 'Sent in a previous email' - ); - - if ($res) { - info(DI::l10n()->t('Account approved.') . EOL); - return true; - } -} - // This does not have to go through user_remove() and save the nickname // permanently against re-registration, as the person was not yet // allowed to have friends on this system @@ -114,7 +74,9 @@ function regmod_content(App $a) } if ($cmd === 'allow') { - user_allow($hash); + if (User::allow($hash)) { + info(DI::l10n()->t('Account approved.') . EOL); + } DI::baseUrl()->redirect('admin/users/'); } } diff --git a/src/Console/User.php b/src/Console/User.php index 6db2cf84e..3166874e0 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -24,8 +24,8 @@ namespace Friendica\Console; use Friendica\App; use Friendica\Core\L10n; use Friendica\Database\Database; +use Friendica\Model\Register; use Friendica\Model\User as UserModel; -use Friendica\Model\UserService; use RuntimeException; use Seld\CliPrompt\CliPrompt; @@ -50,8 +50,6 @@ class User extends \Asika\SimpleConsole\Console * @var Database */ private $dba; - /** @var UserService */ - private $userService; protected function getHelp() { @@ -60,6 +58,7 @@ console user - Modify user settings per console commands. Usage bin/console user password [] [-h|--help|-?] [-v] bin/console user add [ [ [ []]]] [-h|--help|-?] [-v] + bin/console user allow [] [-h|--help|-?] [-v] Description Modify user settings per console commands. @@ -71,14 +70,13 @@ HELP; return $help; } - public function __construct(App\Mode $appMode, L10n $l10n, Database $dba, UserService $userService, array $argv = null) + public function __construct(App\Mode $appMode, L10n $l10n, Database $dba, array $argv = null) { parent::__construct($argv); - $this->appMode = $appMode; - $this->l10n = $l10n; - $this->dba = $dba; - $this->userService = $userService; + $this->appMode = $appMode; + $this->l10n = $l10n; + $this->dba = $dba; } protected function doExecute() @@ -105,6 +103,8 @@ HELP; return $this->password(); case 'add': return $this->addUser(); + case 'allow': + return $this->allowUser(); default: throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.'); } @@ -158,10 +158,10 @@ HELP; */ private function addUser() { - $name = $this->getArgument(1); - $nick = $this->getArgument(2); - $email= $this->getArgument(3); - $lang = $this->getArgument(4); + $name = $this->getArgument(1); + $nick = $this->getArgument(2); + $email = $this->getArgument(3); + $lang = $this->getArgument(4); if (empty($name)) { $this->out($this->l10n->t('Enter user name: ')); @@ -170,6 +170,7 @@ HELP; throw new RuntimeException('A name must be set.'); } } + if (empty($nick)) { $this->out($this->l10n->t('Enter user nickname: ')); $nick = CliPrompt::prompt(); @@ -177,6 +178,7 @@ HELP; throw new RuntimeException('A nick name must be set.'); } } + if (empty($email)) { $this->out($this->l10n->t('Enter user email address: ')); $email = CliPrompt::prompt(); @@ -191,9 +193,40 @@ HELP; } if (empty($lang)) { - return $this->userService->createMinimal($name, $email, $nick); + return UserModel::createMinimal($name, $email, $nick); } else { - return $this->userService->createMinimal($name, $email, $nick, $lang); + return UserModel::createMinimal($name, $email, $nick, $lang); } } + + /** + * Allows a user based on it's nickname + * + * @return bool True, if allow was successful + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + */ + public function allowUser() + { + $nick = $this->getArgument(1); + + if (!$nick) { + $this->out($this->l10n->t('Enter user nickname: ')); + $nick = CliPrompt::prompt(); + if (empty($nick)) { + throw new RuntimeException('A nick name must be set.'); + } + } + + $user = $this->dba->selectFirst('user', ['uid'], ['nickname' => $nick]); + if (empty($user)) { + throw new RuntimeException($this->l10n->t('User not found')); + } + + $pending = Register::getPendingForUser($user['uid'] ?? 0); + if (empty($pending)) { + throw new RuntimeException($this->l10n->t('User is not pending.')); + } + + return UserModel::allow($pending['hash']); + } } diff --git a/src/DI.php b/src/DI.php index b1d2b82c1..39efe2a97 100644 --- a/src/DI.php +++ b/src/DI.php @@ -315,12 +315,6 @@ abstract class DI return self::$dice->create(Model\Storage\IStorage::class); } - /** @return Model\UserService */ - public static function userService() - { - return self::$dice->create(Model\UserService::class); - } - // // "Repository" namespace // diff --git a/src/Model/Register.php b/src/Model/Register.php index fa8fb7bdb..88e424309 100644 --- a/src/Model/Register.php +++ b/src/Model/Register.php @@ -48,6 +48,27 @@ class Register return DBA::toArray($stmt); } + /** + * Returns the pending user based on a given user id + * + * @param int $uid The user id + * + * @return array The pending user information + * + * @throws \Exception + */ + public static function getPendingForUser(int $uid) + { + return DBA::fetchFirst( + "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email` + FROM `register` + INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` + INNER JOIN `user` ON `register`.`uid` = `user`.`uid` + WHERE `register`.uid = ?", + $uid + ); + } + /** * Returns the pending registration count * diff --git a/src/Model/User.php b/src/Model/User.php index 27b87f997..9c6f29ba0 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -24,6 +24,7 @@ namespace Friendica\Model; use DivineOmega\PasswordExposed; use Exception; use Friendica\Core\Hook; +use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; @@ -31,6 +32,7 @@ use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\TwoFactor\AppSpecificPassword; +use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Object\Image; use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; @@ -279,7 +281,7 @@ class User * @param string $network network name * * @return int group id - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws InternalServerErrorException */ public static function getDefaultGroup($uid, $network = '') { @@ -556,7 +558,7 @@ class User * * @param string $nickname The nickname that should be checked * @return boolean True is the nickname is blocked on the node - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws InternalServerErrorException */ public static function isNicknameBlocked($nickname) { @@ -593,7 +595,7 @@ class User * @param array $data * @return array * @throws \ErrorException - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws InternalServerErrorException * @throws \ImagickException * @throws Exception */ @@ -895,6 +897,123 @@ class User return DBA::update('user', ['blocked' => 0], ['uid' => $uid]); } + /** + * Allows a registration based on a hash + * + * @param string $hash + * + * @return bool True, if the allow was successful + * + * @throws InternalServerErrorException + * @throws Exception + */ + public static function allow(string $hash) + { + $register = Register::getByHash($hash); + if (!DBA::isResult($register)) { + return false; + } + + $user = User::getById($register['uid']); + if (!DBA::isResult($user)) { + return false; + } + + Register::deleteByHash($hash); + + DBA::update('user', ['blocked' => false, 'verified' => true], ['uid' => $register['uid']]); + + $profile = DBA::selectFirst('profile', ['net-publish'], ['uid' => $register['uid']]); + + if (DBA::isResult($profile) && $profile['net-publish'] && DI::config()->get('system', 'directory')) { + $url = DI::baseUrl() . '/profile/' . $user['nickname']; + Worker::add(PRIORITY_LOW, "Directory", $url); + } + + $l10n = DI::l10n()->withLang($register['language']); + + return User::sendRegisterOpenEmail( + $l10n, + $user, + DI::config()->get('config', 'sitename'), + DI::baseUrl()->get(), + ($register['password'] ?? '') ?: 'Sent in a previous email' + ); + } + + /** + * Creates a new user based on a minimal set and sends an email to this user + * + * @param string $name The user's name + * @param string $email The user's email address + * @param string $nick The user's nick name + * @param string $lang The user's language (default is english) + * + * @return bool True, if the user was created successfully + * @throws InternalServerErrorException + * @throws \ErrorException + * @throws \ImagickException + */ + public static function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT) + { + if (empty($name) || + empty($email) || + empty($nick)) { + throw new InternalServerErrorException('Invalid arguments.'); + } + + $result = self::create([ + 'username' => $name, + 'email' => $email, + 'nickname' => $nick, + 'verified' => 1, + 'language' => $lang + ]); + + $user = $result['user']; + $preamble = Strings::deindent(DI::l10n()->t(' + Dear %1$s, + the administrator of %2$s has set up an account for you.')); + $body = Strings::deindent(DI::l10n()->t(' + The login details are as follows: + + Site Location: %1$s + Login Name: %2$s + Password: %3$s + + You may change your password from your account "Settings" page after logging + in. + + Please take a few moments to review the other account settings on that page. + + You may also wish to add some basic information to your default profile + (on the "Profiles" page) so that other people can easily find you. + + We recommend setting your full name, adding a profile photo, + adding some profile "keywords" (very useful in making new friends) - and + perhaps what country you live in; if you do not wish to be more specific + than that. + + We fully respect your right to privacy, and none of these items are necessary. + If you are new and do not know anybody here, they may help + you to make some new and interesting friends. + + If you ever want to delete your account, you can do so at %1$s/removeme + + Thank you and welcome to %4$s.')); + + $preamble = sprintf($preamble, $user['username'], DI::config()->get('config', 'sitename')); + $body = sprintf($body, DI::baseUrl()->get(), $user['nickname'], $result['password'], DI::config()->get('config', 'sitename')); + + $email = DI::emailer() + ->newSystemMail() + ->withMessage(DI::l10n()->t('Registration details for %s', DI::config()->get('config', 'sitename')), $preamble, $body) + ->forUser($user) + ->withRecipient($user['email']) + ->build(); + return DI::emailer()->send($email); + } + /** * Sends pending registration confirmation email * @@ -903,7 +1022,7 @@ class User * @param string $siteurl * @param string $password Plaintext password * @return NULL|boolean from notification() and email() inherited - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws InternalServerErrorException */ public static function sendRegisterPendingEmail($user, $sitename, $siteurl, $password) { @@ -946,7 +1065,7 @@ class User * @param string $password Plaintext password * * @return NULL|boolean from notification() and email() inherited - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws InternalServerErrorException */ public static function sendRegisterOpenEmail(\Friendica\Core\L10n $l10n, $user, $sitename, $siteurl, $password) { @@ -1005,7 +1124,7 @@ class User /** * @param object $uid user to remove * @return bool - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws InternalServerErrorException */ public static function remove($uid) { diff --git a/src/Model/UserService.php b/src/Model/UserService.php deleted file mode 100644 index 6da45e40e..000000000 --- a/src/Model/UserService.php +++ /dev/null @@ -1,125 +0,0 @@ -. - * - */ - -namespace Friendica\Model; - -use ErrorException; -use Friendica\App; -use Friendica\Core\Config\IConfig; -use Friendica\Core\L10n; -use Friendica\Network\HTTPException\InternalServerErrorException; -use Friendica\Util\Emailer; -use Friendica\Util\Strings; -use Friendica\Model\User as UserModel; -use ImagickException; - -class UserService -{ - /** @var L10n */ - private $l10n; - /** @var IConfig */ - private $config; - /** @var App\BaseURL */ - private $baseUrl; - /** @var Emailer */ - private $emailer; - - public function __construct(L10n $l10n, IConfig $config, Emailer $emailer, App\BaseURL $baseUrl) - { - $this->l10n = $l10n; - $this->config = $config; - $this->emailer = $emailer; - $this->baseUrl = $baseUrl; - } - - /** - * Creates a new user based on a minimal set and sends an email to this user - * - * @param string $name The user's name - * @param string $email The user's email address - * @param string $nick The user's nick name - * @param string $lang The user's language (default is english) - * - * @return bool True, if the user was created successfully - * @throws InternalServerErrorException - * @throws ErrorException - * @throws ImagickException - */ - public function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT) - { - if (empty($name) || - empty($email) || - empty($nick)) { - throw new InternalServerErrorException('Invalid arguments.'); - } - - $result = UserModel::create([ - 'username' => $name, - 'email' => $email, - 'nickname' => $nick, - 'verified' => 1, - 'language' => $lang - ]); - - $user = $result['user']; - $preamble = Strings::deindent($this->l10n->t(' - Dear %1$s, - the administrator of %2$s has set up an account for you.')); - $body = Strings::deindent($this->l10n->t(' - The login details are as follows: - - Site Location: %1$s - Login Name: %2$s - Password: %3$s - - You may change your password from your account "Settings" page after logging - in. - - Please take a few moments to review the other account settings on that page. - - You may also wish to add some basic information to your default profile - (on the "Profiles" page) so that other people can easily find you. - - We recommend setting your full name, adding a profile photo, - adding some profile "keywords" (very useful in making new friends) - and - perhaps what country you live in; if you do not wish to be more specific - than that. - - We fully respect your right to privacy, and none of these items are necessary. - If you are new and do not know anybody here, they may help - you to make some new and interesting friends. - - If you ever want to delete your account, you can do so at %1$s/removeme - - Thank you and welcome to %4$s.')); - - $preamble = sprintf($preamble, $user['username'], $this->config->get('config', 'sitename')); - $body = sprintf($body, $this->baseUrl->get(), $user['nickname'], $result['password'], $this->config->get('config', 'sitename')); - - $email = $this->emailer - ->newSystemMail() - ->withMessage($this->l10n->t('Registration details for %s', $this->config->get('config', 'sitename')), $preamble, $body) - ->forUser($user) - ->withRecipient($user['email']) - ->build(); - return $this->emailer->send($email); - } -} diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 20a31333c..5f21a07b2 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -28,7 +28,6 @@ use Friendica\DI; use Friendica\Model\Register; use Friendica\Model\User; use Friendica\Module\BaseAdmin; -use Friendica\Util\Strings; use Friendica\Util\Temporal; class Users extends BaseAdmin @@ -82,7 +81,7 @@ class Users extends BaseAdmin if (!empty($_POST['page_users_approve'])) { require_once 'mod/regmod.php'; foreach ($pending as $hash) { - user_allow($hash); + User::allow($hash); } } From b4f6e8fda1ee04104fe2f22ee88a1b4f2152e589 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 21 Feb 2020 23:03:33 +0100 Subject: [PATCH 04/14] Move "User::deny()" to own method and update usages --- mod/regmod.php | 35 ++++++----------------------------- src/Console/User.php | 13 +++++++++---- src/Model/User.php | 28 ++++++++++++++++++++++++++++ src/Module/Admin/Users.php | 8 ++++++-- 4 files changed, 49 insertions(+), 35 deletions(-) diff --git a/mod/regmod.php b/mod/regmod.php index 8c71490e0..6a31a356a 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -20,44 +20,19 @@ */ use Friendica\App; -use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Model\Register; use Friendica\Model\User; use Friendica\Module\Security\Login; -// This does not have to go through user_remove() and save the nickname -// permanently against re-registration, as the person was not yet -// allowed to have friends on this system -function user_deny($hash) -{ - $register = Register::getByHash($hash); - if (!DBA::isResult($register)) { - return false; - } - - $user = User::getById($register['uid']); - if (!DBA::isResult($user)) { - exit(); - } - - DBA::delete('user', ['uid' => $register['uid']]); - - Register::deleteByHash($register['hash']); - - notice(DI::l10n()->t('Registration revoked for %s', $user['username']) . EOL); - return true; -} - function regmod_content(App $a) { if (!local_user()) { - info(DI::l10n()->t('Please login.') . EOL); + info(DI::l10n()->t('Please login.')); return Login::form(DI::args()->getQueryString(), intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 0 : 1); } if (!is_site_admin() || !empty($_SESSION['submanage'])) { - notice(DI::l10n()->t('Permission denied.') . EOL); + notice(DI::l10n()->t('Permission denied.')); return ''; } @@ -69,13 +44,15 @@ function regmod_content(App $a) $hash = $a->argv[2]; if ($cmd === 'deny') { - user_deny($hash); + if (User::deny($hash)) { + notice(DI::l10n()->t('Registration revoked')); + } DI::baseUrl()->redirect('admin/users/'); } if ($cmd === 'allow') { if (User::allow($hash)) { - info(DI::l10n()->t('Account approved.') . EOL); + info(DI::l10n()->t('Account approved.')); } DI::baseUrl()->redirect('admin/users/'); } diff --git a/src/Console/User.php b/src/Console/User.php index 3166874e0..85aad7edd 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -59,6 +59,7 @@ Usage bin/console user password [] [-h|--help|-?] [-v] bin/console user add [ [ [ []]]] [-h|--help|-?] [-v] bin/console user allow [] [-h|--help|-?] [-v] + bin/console user deny [] [-h|--help|-?] [-v] Description Modify user settings per console commands. @@ -104,7 +105,9 @@ HELP; case 'add': return $this->addUser(); case 'allow': - return $this->allowUser(); + return $this->pendingUser(true); + case 'deny': + return $this->pendingUser(false); default: throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.'); } @@ -200,12 +203,14 @@ HELP; } /** - * Allows a user based on it's nickname + * Allows or denys a user based on it's nickname + * + * @param bool $allow True, if the pending user is allowed, false if denies * * @return bool True, if allow was successful * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function allowUser() + public function pendingUser(bool $allow = true) { $nick = $this->getArgument(1); @@ -227,6 +232,6 @@ HELP; throw new RuntimeException($this->l10n->t('User is not pending.')); } - return UserModel::allow($pending['hash']); + return ($allow) ? UserModel::allow($pending['hash']) : UserModel::deny($pending['hash']); } } diff --git a/src/Model/User.php b/src/Model/User.php index 9c6f29ba0..b1736a7bd 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -941,6 +941,34 @@ class User ); } + /** + * Denys a pending registration + * + * @param string $hash The hash of the pending user + * + * This does not have to go through user_remove() and save the nickname + * permanently against re-registration, as the person was not yet + * allowed to have friends on this system + * + * @return bool True, if the deny was successfull + * @throws Exception + */ + public static function deny(string $hash) + { + $register = Register::getByHash($hash); + if (!DBA::isResult($register)) { + return false; + } + + $user = User::getById($register['uid']); + if (!DBA::isResult($user)) { + return false; + } + + return DBA::delete('user', ['uid' => $register['uid']]) && + Register::deleteByHash($register['hash']); + } + /** * Creates a new user based on a minimal set and sends an email to this user * diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 5f21a07b2..bc99be2e3 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -81,14 +81,18 @@ class Users extends BaseAdmin if (!empty($_POST['page_users_approve'])) { require_once 'mod/regmod.php'; foreach ($pending as $hash) { - User::allow($hash); + if (User::allow($hash)) { + info(DI::l10n()->t('Account approved.')); + } } } if (!empty($_POST['page_users_deny'])) { require_once 'mod/regmod.php'; foreach ($pending as $hash) { - user_deny($hash); + if (User::deny($hash)) { + notice(DI::l10n()->t('Registration revoked')); + } } } From 0c3f8b124bd8fd3dd8f1acff73a3211935ac68a6 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 21 Feb 2020 23:12:07 +0100 Subject: [PATCH 05/14] Add "User::block()" to console command --- src/Console/User.php | 36 +++++++++++++++++++++++++++++++++++- src/Model/User.php | 6 +++--- src/Module/Admin/Users.php | 6 ++---- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/Console/User.php b/src/Console/User.php index 85aad7edd..2c0e1ad28 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -60,6 +60,8 @@ Usage bin/console user add [ [ [ []]]] [-h|--help|-?] [-v] bin/console user allow [] [-h|--help|-?] [-v] bin/console user deny [] [-h|--help|-?] [-v] + bin/console user block [] [-h|--help|-?] [-v] + bin/console user unblock [] [-h|--help|-?] [-v] Description Modify user settings per console commands. @@ -108,6 +110,10 @@ HELP; return $this->pendingUser(true); case 'deny': return $this->pendingUser(false); + case 'block': + return $this->blockUser(true); + case 'unblock': + return $this->blockUser(false); default: throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.'); } @@ -210,7 +216,7 @@ HELP; * @return bool True, if allow was successful * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function pendingUser(bool $allow = true) + private function pendingUser(bool $allow = true) { $nick = $this->getArgument(1); @@ -234,4 +240,32 @@ HELP; return ($allow) ? UserModel::allow($pending['hash']) : UserModel::deny($pending['hash']); } + + /** + * Blocks/unblocks a user + * + * @param bool $block True, if the given user should get blocked + * + * @return bool True, if the command was successful + * @throws \Exception + */ + private function blockUser(bool $block = true) + { + $nick = $this->getArgument(1); + + if (!$nick) { + $this->out($this->l10n->t('Enter user nickname: ')); + $nick = CliPrompt::prompt(); + if (empty($nick)) { + throw new RuntimeException('A nick name must be set.'); + } + } + + $user = $this->dba->selectFirst('user', ['uid'], ['nickname' => $nick]); + if (empty($user)) { + throw new RuntimeException($this->l10n->t('User not found')); + } + + return $block ? UserModel::block($user['uid'] ?? 0) : UserModel::block($user['uid'] ?? 0, false); + } } diff --git a/src/Model/User.php b/src/Model/User.php index b1736a7bd..4c4534b29 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -894,7 +894,7 @@ class User */ public static function block(int $uid, bool $block = true) { - return DBA::update('user', ['blocked' => 0], ['uid' => $uid]); + return DBA::update('user', ['blocked' => $block], ['uid' => $uid]); } /** @@ -1150,11 +1150,11 @@ class User } /** - * @param object $uid user to remove + * @param int $uid user to remove * @return bool * @throws InternalServerErrorException */ - public static function remove($uid) + public static function remove(int $uid) { if (!$uid) { return false; diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index bc99be2e3..d8594695d 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -130,14 +130,12 @@ class Users extends BaseAdmin break; case 'block': parent::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't'); - // @TODO Move this to Model\User:block([$uid]); - DBA::update('user', ['blocked' => 1], ['uid' => $uid]); + User::block($uid); notice(DI::l10n()->t('User "%s" blocked', $user['username'])); break; case 'unblock': parent::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't'); - // @TODO Move this to Model\User:unblock([$uid]); - DBA::update('user', ['blocked' => 0], ['uid' => $uid]); + User::block($uid, false); notice(DI::l10n()->t('User "%s" unblocked', $user['username'])); break; } From bb47624bf2bd17277fd6d5e6fcff4e2b19b55674 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 21 Feb 2020 23:19:47 +0100 Subject: [PATCH 06/14] Add "User::remove()" to console command --- src/Console/User.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Console/User.php b/src/Console/User.php index 2c0e1ad28..ccd3caa37 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -58,6 +58,7 @@ console user - Modify user settings per console commands. Usage bin/console user password [] [-h|--help|-?] [-v] bin/console user add [ [ [ []]]] [-h|--help|-?] [-v] + bin/console user delete [] [-q] [-h|--help|-?] [-v] bin/console user allow [] [-h|--help|-?] [-v] bin/console user deny [] [-h|--help|-?] [-v] bin/console user block [] [-h|--help|-?] [-v] @@ -69,6 +70,7 @@ Description Options -h|--help|-? Show help information -v Show more debug information. + -q Quiet mode (don't ask for a command). HELP; return $help; } @@ -114,6 +116,8 @@ HELP; return $this->blockUser(true); case 'unblock': return $this->blockUser(false); + case 'delete': + return $this->deleteUser(); default: throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.'); } @@ -268,4 +272,37 @@ HELP; return $block ? UserModel::block($user['uid'] ?? 0) : UserModel::block($user['uid'] ?? 0, false); } + + /** + * Deletes a user + * + * @return bool True, if the delete was successful + * @throws \Exception + */ + private function deleteUser() + { + $nick = $this->getArgument(1); + + if (!$nick) { + $this->out($this->l10n->t('Enter user nickname: ')); + $nick = CliPrompt::prompt(); + if (empty($nick)) { + throw new RuntimeException('A nick name must be set.'); + } + } + + $user = $this->dba->selectFirst('user', ['uid'], ['nickname' => $nick]); + if (empty($user)) { + throw new RuntimeException($this->l10n->t('User not found')); + } + + if (!$this->getOption('q')) { + $this->out($this->l10n->t('Type "yes" to delete %s', $nick)); + if (CliPrompt::prompt() !== 'yes') { + throw new RuntimeException('Delete abort.'); + } + } + + return UserModel::remove($user['uid'] ?? -1); + } } From 4f2bea5cb1f4f78649d547d318cc65b11230fee2 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 21 Feb 2020 23:31:37 +0100 Subject: [PATCH 07/14] Move "regmod" functionality into Admin Users page --- mod/regmod.php | 59 -------------------- src/Module/Admin/Users.php | 12 +++- view/templates/admin/users.tpl | 4 +- view/theme/frio/templates/admin/users.tpl | 4 +- view/theme/quattro/templates/admin/users.tpl | 4 +- 5 files changed, 16 insertions(+), 67 deletions(-) delete mode 100644 mod/regmod.php diff --git a/mod/regmod.php b/mod/regmod.php deleted file mode 100644 index 6a31a356a..000000000 --- a/mod/regmod.php +++ /dev/null @@ -1,59 +0,0 @@ -. - * - */ - -use Friendica\App; -use Friendica\DI; -use Friendica\Model\User; -use Friendica\Module\Security\Login; - -function regmod_content(App $a) -{ - if (!local_user()) { - info(DI::l10n()->t('Please login.')); - return Login::form(DI::args()->getQueryString(), intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 0 : 1); - } - - if (!is_site_admin() || !empty($_SESSION['submanage'])) { - notice(DI::l10n()->t('Permission denied.')); - return ''; - } - - if ($a->argc != 3) { - exit(); - } - - $cmd = $a->argv[1]; - $hash = $a->argv[2]; - - if ($cmd === 'deny') { - if (User::deny($hash)) { - notice(DI::l10n()->t('Registration revoked')); - } - DI::baseUrl()->redirect('admin/users/'); - } - - if ($cmd === 'allow') { - if (User::allow($hash)) { - info(DI::l10n()->t('Account approved.')); - } - DI::baseUrl()->redirect('admin/users/'); - } -} diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index d8594695d..07363b732 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -79,7 +79,6 @@ class Users extends BaseAdmin } if (!empty($_POST['page_users_approve'])) { - require_once 'mod/regmod.php'; foreach ($pending as $hash) { if (User::allow($hash)) { info(DI::l10n()->t('Account approved.')); @@ -88,7 +87,6 @@ class Users extends BaseAdmin } if (!empty($_POST['page_users_deny'])) { - require_once 'mod/regmod.php'; foreach ($pending as $hash) { if (User::deny($hash)) { notice(DI::l10n()->t('Registration revoked')); @@ -138,6 +136,16 @@ class Users extends BaseAdmin User::block($uid, false); notice(DI::l10n()->t('User "%s" unblocked', $user['username'])); break; + case 'allow': + parent::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't'); + User::allow(Register::getPendingForUser($uid)['hash'] ?? ''); + notice(DI::l10n()->t('Account approved.')); + break; + case 'deny': + parent::checkFormSecurityTokenRedirectOnError('/admin/users', 'admin_users', 't'); + User::deny(Register::getPendingForUser($uid)['hash'] ?? ''); + notice(DI::l10n()->t('Registration revoked')); + break; } DI::baseUrl()->redirect('admin/users'); diff --git a/view/templates/admin/users.tpl b/view/templates/admin/users.tpl index 6ca85fe7a..8bbffbb7d 100644 --- a/view/templates/admin/users.tpl +++ b/view/templates/admin/users.tpl @@ -35,8 +35,8 @@ {{$u.email}} - - + + diff --git a/view/theme/frio/templates/admin/users.tpl b/view/theme/frio/templates/admin/users.tpl index 256d5cdae..a9c5f003e 100644 --- a/view/theme/frio/templates/admin/users.tpl +++ b/view/theme/frio/templates/admin/users.tpl @@ -49,8 +49,8 @@ {{$u.name}} {{$u.email}} - - + + {{if $u.note}} diff --git a/view/theme/quattro/templates/admin/users.tpl b/view/theme/quattro/templates/admin/users.tpl index 97875a077..bd4e63ec7 100644 --- a/view/theme/quattro/templates/admin/users.tpl +++ b/view/theme/quattro/templates/admin/users.tpl @@ -35,8 +35,8 @@ {{$u.email}} - - + + From 0fade7fc0a048bf7485a0fcc10d2592ef547117b Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 21 Feb 2020 23:43:52 +0100 Subject: [PATCH 08/14] Fix Admin page --- src/Module/Admin/Users.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 07363b732..a264f129c 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -47,7 +47,7 @@ class Users extends BaseAdmin if ($nu_name !== '' && $nu_email !== '' && $nu_nickname !== '') { try { - DI::userService()->createMinimal($nu_name, $nu_email, $nu_nickname, $nu_language); + User::createMinimal($nu_name, $nu_email, $nu_nickname, $nu_language); } catch (\Exception $ex) { notice($ex->getMessage()); return; @@ -55,15 +55,17 @@ class Users extends BaseAdmin } if (!empty($_POST['page_users_block'])) { - if (User::block($users)) { - notice(DI::l10n()->tt('%s user blocked', '%s users blocked', count($users))); + foreach ($users as $uid) { + User::block(Register::getPendingForUser($uid)['hash'] ?? ''); } + notice(DI::l10n()->tt('%s user blocked', '%s users blocked', count($users))); } if (!empty($_POST['page_users_unblock'])) { - if (User::block($users, false)) { - notice(DI::l10n()->tt('%s user unblocked', '%s users unblocked', count($users))); + foreach ($users as $uid) { + User::block(Register::getPendingForUser($uid)['hash'] ?? '', false); } + notice(DI::l10n()->tt('%s user unblocked', '%s users unblocked', count($users))); } if (!empty($_POST['page_users_delete'])) { From ecf7f40704ee7fd2cf181dbe47aca05cb16ab225 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Fri, 21 Feb 2020 23:50:17 +0100 Subject: [PATCH 09/14] Admin page improvements --- src/Module/Admin/Users.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index a264f129c..73a11e65a 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -56,14 +56,14 @@ class Users extends BaseAdmin if (!empty($_POST['page_users_block'])) { foreach ($users as $uid) { - User::block(Register::getPendingForUser($uid)['hash'] ?? ''); + User::block($uid); } notice(DI::l10n()->tt('%s user blocked', '%s users blocked', count($users))); } if (!empty($_POST['page_users_unblock'])) { foreach ($users as $uid) { - User::block(Register::getPendingForUser($uid)['hash'] ?? '', false); + User::block($uid, false); } notice(DI::l10n()->tt('%s user unblocked', '%s users unblocked', count($users))); } @@ -82,18 +82,16 @@ class Users extends BaseAdmin if (!empty($_POST['page_users_approve'])) { foreach ($pending as $hash) { - if (User::allow($hash)) { - info(DI::l10n()->t('Account approved.')); - } + User::allow($hash); } + notice(DI::l10n()->tt('%s user approved', '%s users approved', count($pending))); } if (!empty($_POST['page_users_deny'])) { foreach ($pending as $hash) { - if (User::deny($hash)) { - notice(DI::l10n()->t('Registration revoked')); - } + User::deny($hash); } + notice(DI::l10n()->tt('%s registration revoked', '%s registrations revoked', count($pending))); } DI::baseUrl()->redirect('admin/users'); From 2adc6a0974ad6f7e9609a0fce268d4a53e2ce479 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 25 Feb 2020 22:16:27 +0100 Subject: [PATCH 10/14] Add list command --- src/Console/User.php | 58 ++++++++++++++++++++++++++++++++++++-- src/Content/Pager.php | 5 +++- src/Model/Register.php | 11 ++++++-- src/Model/User.php | 27 ++++++++++++++++++ src/Module/Admin/Users.php | 11 +------- 5 files changed, 95 insertions(+), 17 deletions(-) diff --git a/src/Console/User.php b/src/Console/User.php index ccd3caa37..3fdeac1c5 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -21,7 +21,9 @@ namespace Friendica\Console; +use Console_Table; use Friendica\App; +use Friendica\Content\Pager; use Friendica\Core\L10n; use Friendica\Database\Database; use Friendica\Model\Register; @@ -30,9 +32,7 @@ use RuntimeException; use Seld\CliPrompt\CliPrompt; /** - * tool to set a new password for a user - * - * With this tool, you can set a new password for a user + * tool to manage users of the current node */ class User extends \Asika\SimpleConsole\Console { @@ -63,6 +63,8 @@ Usage bin/console user deny [] [-h|--help|-?] [-v] bin/console user block [] [-h|--help|-?] [-v] bin/console user unblock [] [-h|--help|-?] [-v] + bin/console user list pending [start=0 [count=50]] [-h|--help|-?] [-v] + bin/console user list all [start=0 [count=50]] [-h|--help|-?] [-v] Description Modify user settings per console commands. @@ -118,6 +120,8 @@ HELP; return $this->blockUser(false); case 'delete': return $this->deleteUser(); + case 'list': + return $this->listUser(); default: throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.'); } @@ -305,4 +309,52 @@ HELP; return UserModel::remove($user['uid'] ?? -1); } + + /** + * List user of the current node + * + * @return bool True, if the command was successful + */ + private function listUser() + { + $subCmd = $this->getArgument(1); + $start = $this->getArgument(2, 0); + $count = $this->getArgument(3, Pager::ITEMS_PER_PAGE); + + $table = new Console_Table(); + + switch ($subCmd) { + case 'pending': + $table->setHeaders(['Nick', 'Name', 'URL', 'E-Mail', 'Register Date', 'Comment']); + $pending = Register::getPending($start, $count); + foreach ($pending as $contact) { + $table->addRow([ + $contact['nick'], + $contact['name'], + $contact['url'], + $contact['email'], + $contact['created'], + $contact['note'], + ]); + } + $this->out($table->getTable()); + return true; + case 'all': + default: + $table->setHeaders(['Nick', 'Name', 'URL', 'E-Mail', 'Register Date', 'Comment']); + $contacts = UserModel::getUsers($start, $count); + foreach ($contacts as $contact) { + $table->addRow([ + $contact['nick'], + $contact['name'], + $contact['url'], + $contact['email'], + $contact['created'], + $contact['note'], + ]); + } + $this->out($table->getTable()); + return true; + } + } } diff --git a/src/Content/Pager.php b/src/Content/Pager.php index 5b4345a4c..a5e61bbf9 100644 --- a/src/Content/Pager.php +++ b/src/Content/Pager.php @@ -30,10 +30,13 @@ use Friendica\Util\Strings; */ class Pager { + /** @var int Default count of items per page */ + const ITEMS_PER_PAGE = 50; + /** @var integer */ private $page = 1; /** @var integer */ - protected $itemsPerPage = 50; + protected $itemsPerPage = self::ITEMS_PER_PAGE; /** @var string */ protected $baseQueryString = ''; diff --git a/src/Model/Register.php b/src/Model/Register.php index 88e424309..be00699bf 100644 --- a/src/Model/Register.php +++ b/src/Model/Register.php @@ -21,6 +21,7 @@ namespace Friendica\Model; +use Friendica\Content\Pager; use Friendica\Database\DBA; use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; @@ -33,16 +34,20 @@ class Register /** * Return the list of pending registrations * + * @param int $start Start count (Default is 0) + * @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE) + * * @return array * @throws \Exception */ - public static function getPending() + public static function getPending($start = 0, $count = Pager::ITEMS_PER_PAGE) { $stmt = DBA::p( - "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email` + "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`, `contact`.`nick` FROM `register` INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid` - INNER JOIN `user` ON `register`.`uid` = `user`.`uid`" + INNER JOIN `user` ON `register`.`uid` = `user`.`uid` + LIMIT ?, ?", $start, $count ); return DBA::toArray($stmt); diff --git a/src/Model/User.php b/src/Model/User.php index 4c4534b29..85a999b37 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -23,6 +23,7 @@ namespace Friendica\Model; use DivineOmega\PasswordExposed; use Exception; +use Friendica\Content\Pager; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; @@ -1316,4 +1317,30 @@ class User return $statistics; } + + /** + * Get all users of the current node + * + * @param int $start Start count (Default is 0) + * @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE) + * @param string $order Order of the user list (Default is 'contact.name') + * @param string $order_direction Order direction (Default is ASC) + * + * @return array The list of the users + * @throws Exception + */ + public static function getUsers($start = 0, $count = Pager::ITEMS_PER_PAGE, $order = 'contact.name', $order_direction = '+') + { + $sql_order = '`' . str_replace('.', '`.`', $order) . '`'; + $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC'; + + $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`, `contact`.`nick` + FROM `user` + INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` + WHERE `user`.`verified` + ORDER BY $sql_order $sql_order_direction LIMIT ?, ?", $start, $count + ); + + return DBA::toArray($usersStmt); + } } diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 73a11e65a..66f70a90c 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -156,7 +156,6 @@ class Users extends BaseAdmin $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 100); - // @TODO Move below block to Model\User::getUsers($start, $count, $order = 'contact.name', $order_direction = '+') $valid_orders = [ 'contact.name', 'user.email', @@ -179,16 +178,8 @@ class Users extends BaseAdmin $order = $new_order; } } - $sql_order = '`' . str_replace('.', '`.`', $order) . '`'; - $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC'; - $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date` - FROM `user` - INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` - WHERE `user`.`verified` - ORDER BY $sql_order $sql_order_direction LIMIT ?, ?", $pager->getStart(), $pager->getItemsPerPage() - ); - $users = DBA::toArray($usersStmt); + $users = User::getUsers($pager->getStart(), $pager->getItemsPerPage(), $order, $order_direction); $adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email'))); $_setup_users = function ($e) use ($adminlist) { From 3a317c5c0dbcb159f02bac339261bedbd351078a Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 25 Feb 2020 22:28:02 +0100 Subject: [PATCH 11/14] More list sub commands --- src/Console/User.php | 17 +++++++++++++---- src/Model/User.php | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Console/User.php b/src/Console/User.php index 3fdeac1c5..68e25818b 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -28,6 +28,7 @@ use Friendica\Core\L10n; use Friendica\Database\Database; use Friendica\Model\Register; use Friendica\Model\User as UserModel; +use Friendica\Util\Temporal; use RuntimeException; use Seld\CliPrompt\CliPrompt; @@ -64,6 +65,7 @@ Usage bin/console user block [] [-h|--help|-?] [-v] bin/console user unblock [] [-h|--help|-?] [-v] bin/console user list pending [start=0 [count=50]] [-h|--help|-?] [-v] + bin/console user list removed [start=0 [count=50]] [-h|--help|-?] [-v] bin/console user list all [start=0 [count=50]] [-h|--help|-?] [-v] Description @@ -333,24 +335,31 @@ HELP; $contact['name'], $contact['url'], $contact['email'], - $contact['created'], + Temporal::getRelativeDate($contact['created']), $contact['note'], ]); } $this->out($table->getTable()); return true; case 'all': + case 'removed': default: - $table->setHeaders(['Nick', 'Name', 'URL', 'E-Mail', 'Register Date', 'Comment']); + $table->setHeaders(['Nick', 'Name', 'URL', 'E-Mail', 'Register', 'Login', 'Last Item']); $contacts = UserModel::getUsers($start, $count); foreach ($contacts as $contact) { + if (($subCmd != 'removed') && !empty($contact['account_removed']) || + ($subCmd == 'removed') && empty($contact['account_removed'])) { + continue; + } + $table->addRow([ $contact['nick'], $contact['name'], $contact['url'], $contact['email'], - $contact['created'], - $contact['note'], + Temporal::getRelativeDate($contact['created']), + Temporal::getRelativeDate($contact['login_date']), + Temporal::getRelativeDate($contact['lastitem_date']), ]); } $this->out($table->getTable()); diff --git a/src/Model/User.php b/src/Model/User.php index 85a999b37..b0db51a11 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -1334,7 +1334,7 @@ class User $sql_order = '`' . str_replace('.', '`.`', $order) . '`'; $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC'; - $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`, `contact`.`nick` + $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`, `contact`.`nick`, `contact`.`created` FROM `user` INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` WHERE `user`.`verified` From d950a3241bb690b6143d8aa43b37f36ee7c66197 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 25 Feb 2020 22:40:36 +0100 Subject: [PATCH 12/14] Add basic search --- src/Console/User.php | 61 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/src/Console/User.php b/src/Console/User.php index 68e25818b..5c75353a6 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -67,6 +67,10 @@ Usage bin/console user list pending [start=0 [count=50]] [-h|--help|-?] [-v] bin/console user list removed [start=0 [count=50]] [-h|--help|-?] [-v] bin/console user list all [start=0 [count=50]] [-h|--help|-?] [-v] + bin/console user search id [-h|--help|-?] [-v] + bin/console user search nick [-h|--help|-?] [-v] + bin/console user search mail [-h|--help|-?] [-v] + bin/console user search guid [-h|--help|-?] [-v] Description Modify user settings per console commands. @@ -124,6 +128,8 @@ HELP; return $this->deleteUser(); case 'list': return $this->listUser(); + case 'search': + return $this->searchUser(); default: throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.'); } @@ -313,7 +319,7 @@ HELP; } /** - * List user of the current node + * List users of the current node * * @return bool True, if the command was successful */ @@ -343,7 +349,6 @@ HELP; return true; case 'all': case 'removed': - default: $table->setHeaders(['Nick', 'Name', 'URL', 'E-Mail', 'Register', 'Login', 'Last Item']); $contacts = UserModel::getUsers($start, $count); foreach ($contacts as $contact) { @@ -364,6 +369,58 @@ HELP; } $this->out($table->getTable()); return true; + default: + $this->out($this->getHelp()); + return false; } } + + /** + * Returns a user based on search parameter + * + * @return bool True, if the command was successful + */ + private function searchUser() + { + $fields = [ + 'uid', + 'guid', + 'username', + 'nickname', + 'email', + 'register_date', + 'login_date', + 'verified', + 'blocked', + ]; + + $subCmd = $this->getArgument(1); + $param = $this->getArgument(2); + + $table = new Console_Table(); + $table->setHeaders(['UID', 'GUID', 'Name', 'Nick', 'E-Mail', 'Register', 'Login', 'Verified', 'Blocked']); + + switch ($subCmd) { + case 'id': + $user = UserModel::getById($param, $fields); + break; + case 'guid': + $user = UserModel::getByGuid($param, $fields); + break; + case 'email': + $user = UserModel::getByEmail($param, $fields); + break; + case 'nick': + $user = UserModel::getByNickname($param, $fields); + break; + default: + $this->out($this->getHelp()); + return false; + } + + $table->addRow($user); + $this->out($table->getTable()); + + return true; + } } From ed422be734c10f2fad1b44ee41d0b4d8722366e2 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 25 Feb 2020 23:22:47 +0100 Subject: [PATCH 13/14] Improve start/count parameter --- src/Console/User.php | 19 ++++++++----------- src/Model/User.php | 23 ++++++++++++++++++++--- src/Module/Admin/Users.php | 2 +- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/Console/User.php b/src/Console/User.php index 5c75353a6..ab6b9623c 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -64,9 +64,10 @@ Usage bin/console user deny [] [-h|--help|-?] [-v] bin/console user block [] [-h|--help|-?] [-v] bin/console user unblock [] [-h|--help|-?] [-v] - bin/console user list pending [start=0 [count=50]] [-h|--help|-?] [-v] - bin/console user list removed [start=0 [count=50]] [-h|--help|-?] [-v] - bin/console user list all [start=0 [count=50]] [-h|--help|-?] [-v] + bin/console user list pending [-s|--start=0] [-c|--count=50] [-h|--help|-?] [-v] + bin/console user list removed [-s|--start=0] [-c|--count=50] [-h|--help|-?] [-v] + bin/console user list active [-s|--start=0] [-c|--count=50] [-h|--help|-?] [-v] + bin/console user list all [-s|--start=0] [-c|--count=50] [-h|--help|-?] [-v] bin/console user search id [-h|--help|-?] [-v] bin/console user search nick [-h|--help|-?] [-v] bin/console user search mail [-h|--help|-?] [-v] @@ -326,8 +327,8 @@ HELP; private function listUser() { $subCmd = $this->getArgument(1); - $start = $this->getArgument(2, 0); - $count = $this->getArgument(3, Pager::ITEMS_PER_PAGE); + $start = $this->getOption(['s', 'start'], 0); + $count = $this->getOption(['c', 'count'], Pager::ITEMS_PER_PAGE); $table = new Console_Table(); @@ -348,15 +349,11 @@ HELP; $this->out($table->getTable()); return true; case 'all': + case 'active': case 'removed': $table->setHeaders(['Nick', 'Name', 'URL', 'E-Mail', 'Register', 'Login', 'Last Item']); - $contacts = UserModel::getUsers($start, $count); + $contacts = UserModel::getUsers($start, $count, $subCmd); foreach ($contacts as $contact) { - if (($subCmd != 'removed') && !empty($contact['account_removed']) || - ($subCmd == 'removed') && empty($contact['account_removed'])) { - continue; - } - $table->addRow([ $contact['nick'], $contact['name'], diff --git a/src/Model/User.php b/src/Model/User.php index b0db51a11..c0b9f71c0 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -1323,21 +1323,38 @@ class User * * @param int $start Start count (Default is 0) * @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE) + * @param string $type The type of users, which should get (all, bocked, removed) * @param string $order Order of the user list (Default is 'contact.name') * @param string $order_direction Order direction (Default is ASC) * * @return array The list of the users * @throws Exception */ - public static function getUsers($start = 0, $count = Pager::ITEMS_PER_PAGE, $order = 'contact.name', $order_direction = '+') + public static function getUsers($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'contact.name', $order_direction = '+') { - $sql_order = '`' . str_replace('.', '`.`', $order) . '`'; + $sql_order = '`' . str_replace('.', '`.`', $order) . '`'; $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC'; + switch ($type) { + case 'active': + $sql_extra = 'AND `user`.`blocked` = 0'; + break; + case 'blocked': + $sql_extra = 'AND `user`.`blocked` = 1'; + break; + case 'removed': + $sql_extra = 'AND `user`.`account_removed` = 1'; + break; + case 'all': + default: + $sql_extra = ''; + break; + } + $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`, `contact`.`nick`, `contact`.`created` FROM `user` INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` - WHERE `user`.`verified` + WHERE `user`.`verified` $sql_extra ORDER BY $sql_order $sql_order_direction LIMIT ?, ?", $start, $count ); diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 66f70a90c..6064892f5 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -179,7 +179,7 @@ class Users extends BaseAdmin } } - $users = User::getUsers($pager->getStart(), $pager->getItemsPerPage(), $order, $order_direction); + $users = User::getUsers($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, $order_direction); $adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email'))); $_setup_users = function ($e) use ($adminlist) { From 811f075aa1857a28ea78d0406d2aa7355dd66608 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sat, 29 Feb 2020 17:04:56 +0100 Subject: [PATCH 14/14] Rename method name --- src/Console/User.php | 2 +- src/Model/User.php | 2 +- src/Module/Admin/Users.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Console/User.php b/src/Console/User.php index ab6b9623c..b12a3a6ad 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -352,7 +352,7 @@ HELP; case 'active': case 'removed': $table->setHeaders(['Nick', 'Name', 'URL', 'E-Mail', 'Register', 'Login', 'Last Item']); - $contacts = UserModel::getUsers($start, $count, $subCmd); + $contacts = UserModel::getList($start, $count, $subCmd); foreach ($contacts as $contact) { $table->addRow([ $contact['nick'], diff --git a/src/Model/User.php b/src/Model/User.php index c0b9f71c0..351982e8a 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -1330,7 +1330,7 @@ class User * @return array The list of the users * @throws Exception */ - public static function getUsers($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'contact.name', $order_direction = '+') + public static function getList($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'contact.name', $order_direction = '+') { $sql_order = '`' . str_replace('.', '`.`', $order) . '`'; $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC'; diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 6064892f5..3ef91aadf 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -179,7 +179,7 @@ class Users extends BaseAdmin } } - $users = User::getUsers($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, $order_direction); + $users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, $order_direction); $adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email'))); $_setup_users = function ($e) use ($adminlist) {