Move "NewPassword" to a common "user" console command
This commit is contained in:
parent
19b89d1fd1
commit
4d436c10df
|
@ -24,7 +24,7 @@ namespace Friendica\Console;
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User as UserModel;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +32,7 @@ use RuntimeException;
|
||||||
*
|
*
|
||||||
* With this tool, you can set a new password for a user
|
* 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', '?'];
|
protected $helpOptions = ['h', 'help', '?'];
|
||||||
|
|
||||||
|
@ -52,12 +52,12 @@ class NewPassword extends \Asika\SimpleConsole\Console
|
||||||
protected function getHelp()
|
protected function getHelp()
|
||||||
{
|
{
|
||||||
$help = <<<HELP
|
$help = <<<HELP
|
||||||
console newpassword - Creates a new password for a given user
|
console user - Modify user settings per console commands.
|
||||||
Usage
|
Usage
|
||||||
bin/console newpassword <nickname> [<password>] [-h|--help|-?] [-v]
|
bin/console user <nickname> password [<password>] [-h|--help|-?] [-v]
|
||||||
|
|
||||||
Description
|
Description
|
||||||
Creates a new password for a user without using the "forgot password" functionality.
|
Modify user settings per console commands.
|
||||||
|
|
||||||
Options
|
Options
|
||||||
-h|--help|-? Show help information
|
-h|--help|-? Show help information
|
||||||
|
@ -88,8 +88,8 @@ HELP;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($this->args) > 2) {
|
if (count($this->args) < 2) {
|
||||||
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
|
throw new \Asika\SimpleConsole\CommandArgsException('Not enough arguments.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->appMode->isInstall()) {
|
if ($this->appMode->isInstall()) {
|
||||||
|
@ -103,14 +103,34 @@ HELP;
|
||||||
throw new RuntimeException($this->l10n->t('User not found'));
|
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)) {
|
if (is_null($password)) {
|
||||||
$this->out($this->l10n->t('Enter new password: '), false);
|
$this->out($this->l10n->t('Enter new password: '), false);
|
||||||
$password = \Seld\CliPrompt\CliPrompt::hiddenPrompt(true);
|
$password = \Seld\CliPrompt\CliPrompt::hiddenPrompt(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = User::updatePassword($user['uid'], $password);
|
$result = UserModel::updatePassword($user['uid'], $password);
|
||||||
|
|
||||||
if (!$this->dba->isResult($result)) {
|
if (!$this->dba->isResult($result)) {
|
||||||
throw new \Exception($this->l10n->t('Password update failed. Please try again.'));
|
throw new \Exception($this->l10n->t('Password update failed. Please try again.'));
|
|
@ -57,7 +57,7 @@ Commands:
|
||||||
autoinstall Starts automatic installation of friendica based on values from htconfig.php
|
autoinstall Starts automatic installation of friendica based on values from htconfig.php
|
||||||
lock Edit site locks
|
lock Edit site locks
|
||||||
maintenance Set maintenance mode for this node
|
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
|
php2po Generate a messages.po file from a strings.php file
|
||||||
po2php Generate a strings.php file from a messages.po file
|
po2php Generate a strings.php file from a messages.po file
|
||||||
typo Checks for parse errors in Friendica files
|
typo Checks for parse errors in Friendica files
|
||||||
|
@ -85,7 +85,7 @@ HELP;
|
||||||
'autoinstall' => Friendica\Console\AutomaticInstallation::class,
|
'autoinstall' => Friendica\Console\AutomaticInstallation::class,
|
||||||
'lock' => Friendica\Console\Lock::class,
|
'lock' => Friendica\Console\Lock::class,
|
||||||
'maintenance' => Friendica\Console\Maintenance::class,
|
'maintenance' => Friendica\Console\Maintenance::class,
|
||||||
'newpassword' => Friendica\Console\NewPassword::class,
|
'user' => Friendica\Console\User::class,
|
||||||
'php2po' => Friendica\Console\PhpToPo::class,
|
'php2po' => Friendica\Console\PhpToPo::class,
|
||||||
'po2php' => Friendica\Console\PoToPhp::class,
|
'po2php' => Friendica\Console\PoToPhp::class,
|
||||||
'typo' => Friendica\Console\Typo::class,
|
'typo' => Friendica\Console\Typo::class,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user