Close #269 added help for console commands + php-cs-fixer

This commit is contained in:
tonydspaniard
2019-06-29 08:32:35 +02:00
parent d4695a60d2
commit 8c551d9030
27 changed files with 123 additions and 85 deletions

View File

@ -32,17 +32,22 @@ class ConfirmController extends Controller
parent::__construct($id, $module, $config);
}
/**
* Confirms a a user by setting its field `confirmed_at` to current time.
*
* @param string $usernameOrEmail Username or email of the user
*
* @throws \yii\base\InvalidConfigException
*/
public function actionIndex($usernameOrEmail)
{
$user = $this->userQuery->whereUsernameOrEmail($usernameOrEmail)->one();
if ($user === null) {
$this->stdout(Yii::t('usuario', 'User is not found') . "\n", Console::FG_RED);
} elseif ($this->make(UserConfirmationService::class, [$user])->run()) {
$this->stdout(Yii::t('usuario', 'User has been confirmed') . "\n", Console::FG_GREEN);
} else {
if ($this->make(UserConfirmationService::class, [$user])->run()) {
$this->stdout(Yii::t('usuario', 'User has been confirmed') . "\n", Console::FG_GREEN);
} else {
$this->stdout(Yii::t('usuario', 'Error occurred while confirming user') . "\n", Console::FG_RED);
}
$this->stdout(Yii::t('usuario', 'Error occurred while confirming user') . "\n", Console::FG_RED);
}
}
}

View File

@ -23,6 +23,18 @@ class CreateController extends Controller
{
use ContainerAwareTrait;
/**
* This command creates a new user account. If no password is not set, an 8-char password will be generated. After
* saving user to database, this command uses mailer component to send credentials (username and password) to user
* via email. A role can be also assigned but it must exists previously on the database.
*
* @param string $email Email
* @param string $username Username
* @param string|null $password The password. If null it will be generated automatically
* @param string|null $role Role to assign (must already exist)
*
* @throws \yii\base\InvalidConfigException
*/
public function actionIndex($email, $username, $password = null, $role = null)
{
/** @var User $user */

View File

@ -12,9 +12,11 @@
namespace Da\User\Command;
use Da\User\Query\UserQuery;
use Throwable;
use Yii;
use yii\base\Module;
use yii\console\Controller;
use yii\db\StaleObjectException;
use yii\helpers\Console;
class DeleteController extends Controller
@ -27,6 +29,15 @@ class DeleteController extends Controller
parent::__construct($id, $module, $config);
}
/**
* This command deletes a user.
*
* @param string $usernameOrEmail Email or username of the user to delete
*
*
* @throws Throwable
* @throws StaleObjectException
*/
public function actionIndex($usernameOrEmail)
{
if ($this->confirm(Yii::t('usuario', 'Are you sure? Deleted user can not be restored'))) {

View File

@ -16,6 +16,7 @@ use Da\User\Query\UserQuery;
use Da\User\Service\ResetPasswordService;
use Da\User\Traits\ContainerAwareTrait;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\Module;
use yii\console\Controller;
use yii\helpers\Console;
@ -32,6 +33,14 @@ class PasswordController extends Controller
parent::__construct($id, $module, $config);
}
/**
* This command updates the user's password.
*
* @param string $usernameOrEmail Username or email of the user who's password needs to be updated
* @param string $password The new password
*
* @throws InvalidConfigException
*/
public function actionIndex($usernameOrEmail, $password)
{
/** @var User $user */