diff --git a/CHANGELOG.md b/CHANGELOG.md
index 88aef6f..22da579 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
- Enh #325: Added support for sqlite3 (santilin)
- Fix #326: Fix rule for the user auth_tf_enabled field (santilin)
- Fix #290: Fix wrong email message for resending confirmation (tonydspaniard)
+ - Enh #269: Added help documentation to console commands (tonydspaniard)
## 1.5.0 April 19, 2019
- Fix: Fix condition in EmailChangeService (it was always false) (borisaeric)
diff --git a/src/User/Command/ConfirmController.php b/src/User/Command/ConfirmController.php
index 79accf4..f0e5978 100644
--- a/src/User/Command/ConfirmController.php
+++ b/src/User/Command/ConfirmController.php
@@ -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);
}
}
}
diff --git a/src/User/Command/CreateController.php b/src/User/Command/CreateController.php
index a98e98c..0af7d66 100644
--- a/src/User/Command/CreateController.php
+++ b/src/User/Command/CreateController.php
@@ -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 */
diff --git a/src/User/Command/DeleteController.php b/src/User/Command/DeleteController.php
index 54af4f3..50e4621 100644
--- a/src/User/Command/DeleteController.php
+++ b/src/User/Command/DeleteController.php
@@ -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'))) {
diff --git a/src/User/Command/PasswordController.php b/src/User/Command/PasswordController.php
index 62dc497..9e97fcb 100644
--- a/src/User/Command/PasswordController.php
+++ b/src/User/Command/PasswordController.php
@@ -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 */
diff --git a/src/User/Controller/RecoveryController.php b/src/User/Controller/RecoveryController.php
index a935669..9925c87 100644
--- a/src/User/Controller/RecoveryController.php
+++ b/src/User/Controller/RecoveryController.php
@@ -39,7 +39,6 @@ class RecoveryController extends Controller
protected $userQuery;
protected $tokenQuery;
-
/**
* RecoveryController constructor.
*
diff --git a/src/User/Controller/RegistrationController.php b/src/User/Controller/RegistrationController.php
index 424d8b0..452476e 100644
--- a/src/User/Controller/RegistrationController.php
+++ b/src/User/Controller/RegistrationController.php
@@ -43,7 +43,6 @@ class RegistrationController extends Controller
protected $userQuery;
protected $socialNetworkAccountQuery;
-
/**
* RegistrationController constructor.
*
diff --git a/src/User/Controller/RuleController.php b/src/User/Controller/RuleController.php
index 74626ca..3a05cea 100644
--- a/src/User/Controller/RuleController.php
+++ b/src/User/Controller/RuleController.php
@@ -11,18 +11,18 @@
namespace Da\User\Controller;
+use Da\User\Filter\AccessRuleFilter;
use Da\User\Model\Rule;
use Da\User\Search\RuleSearch;
use Da\User\Service\AuthRuleEditionService;
use Da\User\Traits\AuthManagerAwareTrait;
use Da\User\Traits\ContainerAwareTrait;
use Da\User\Validator\AjaxRequestModelValidator;
-use Da\User\Filter\AccessRuleFilter;
use Yii;
+use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
-use yii\filters\AccessControl;
class RuleController extends Controller
{
diff --git a/src/User/Controller/SecurityController.php b/src/User/Controller/SecurityController.php
index 5412e5f..31ecbb5 100644
--- a/src/User/Controller/SecurityController.php
+++ b/src/User/Controller/SecurityController.php
@@ -38,7 +38,6 @@ class SecurityController extends Controller
protected $socialNetworkAccountQuery;
-
/**
* SecurityController constructor.
*
diff --git a/src/User/Controller/SettingsController.php b/src/User/Controller/SettingsController.php
index 0f77e9e..810e82c 100644
--- a/src/User/Controller/SettingsController.php
+++ b/src/User/Controller/SettingsController.php
@@ -11,7 +11,6 @@
namespace Da\User\Controller;
-
use Da\User\Contracts\MailChangeStrategyInterface;
use Da\User\Event\GdprEvent;
use Da\User\Event\ProfileEvent;
@@ -56,16 +55,15 @@ class SettingsController extends Controller
protected $userQuery;
protected $socialNetworkAccountQuery;
-
/**
* SettingsController constructor.
*
- * @param string $id
- * @param Module $module
- * @param ProfileQuery $profileQuery
- * @param UserQuery $userQuery
+ * @param string $id
+ * @param Module $module
+ * @param ProfileQuery $profileQuery
+ * @param UserQuery $userQuery
* @param SocialNetworkAccountQuery $socialNetworkAccountQuery
- * @param array $config
+ * @param array $config
*/
public function __construct(
$id,
@@ -74,8 +72,7 @@ class SettingsController extends Controller
UserQuery $userQuery,
SocialNetworkAccountQuery $socialNetworkAccountQuery,
array $config = []
- )
- {
+ ) {
$this->profileQuery = $profileQuery;
$this->userQuery = $userQuery;
$this->socialNetworkAccountQuery = $socialNetworkAccountQuery;
@@ -159,9 +156,9 @@ class SettingsController extends Controller
public function actionPrivacy()
{
- if (!$this->module->enableGdprCompliance)
+ if (!$this->module->enableGdprCompliance) {
throw new NotFoundHttpException();
-
+ }
return $this->render('privacy', [
'module' => $this->module
]);
@@ -169,9 +166,9 @@ class SettingsController extends Controller
public function actionGdprDelete()
{
- if (!$this->module->enableGdprCompliance)
+ if (!$this->module->enableGdprCompliance) {
throw new NotFoundHttpException();
-
+ }
/** @var GdprDeleteForm $form */
$form = $this->make(GdprDeleteForm::class);
@@ -209,15 +206,12 @@ class SettingsController extends Controller
'website' => $anonymReplacement . ".tld",
'bio' => Yii::t('usuario', 'Deleted by GDPR request')
]);
-
-
}
$this->trigger(GdprEvent::EVENT_AFTER_DELETE, $event);
Yii::$app->session->setFlash('info', Yii::t('usuario', 'Your personal information has been removed'));
return $this->goHome();
-
}
return $this->render('gdpr-delete', [
@@ -225,32 +219,6 @@ class SettingsController extends Controller
]);
}
- /**
- * @param $id
- * @throws ForbiddenHttpException
- * @throws NotFoundHttpException
- * @throws \Exception
- * @throws \Throwable
- * @throws \yii\db\StaleObjectException
- */
- protected function disconnectSocialNetwork($id)
- {
- /** @var SocialNetworkAccount $account */
- $account = $this->socialNetworkAccountQuery->whereId($id)->one();
-
- if ($account === null) {
- throw new NotFoundHttpException();
- }
- if ($account->user_id !== Yii::$app->user->id) {
- throw new ForbiddenHttpException();
- }
- $event = $this->make(SocialNetworkConnectEvent::class, [Yii::$app->user->identity, $account]);
-
- $this->trigger(SocialNetworkConnectEvent::EVENT_BEFORE_DISCONNECT, $event);
- $account->delete();
- $this->trigger(SocialNetworkConnectEvent::EVENT_AFTER_DISCONNECT, $event);
- }
-
/**
* Exports the data from the current user in a mechanical readable format (csv). Properties exported can be defined
* in the module configuration.
@@ -260,9 +228,9 @@ class SettingsController extends Controller
*/
public function actionExport()
{
- if (!$this->module->enableGdprCompliance)
+ if (!$this->module->enableGdprCompliance) {
throw new NotFoundHttpException();
-
+ }
try {
$properties = $this->module->gdprExportProperties;
$user = Yii::$app->user->identity;
@@ -294,7 +262,6 @@ class SettingsController extends Controller
} catch (\Throwable $e) {
throw $e;
}
-
}
public function actionAccount()
@@ -444,4 +411,30 @@ class SettingsController extends Controller
$this->redirect(['account']);
}
+
+ /**
+ * @param $id
+ * @throws ForbiddenHttpException
+ * @throws NotFoundHttpException
+ * @throws \Exception
+ * @throws \Throwable
+ * @throws \yii\db\StaleObjectException
+ */
+ protected function disconnectSocialNetwork($id)
+ {
+ /** @var SocialNetworkAccount $account */
+ $account = $this->socialNetworkAccountQuery->whereId($id)->one();
+
+ if ($account === null) {
+ throw new NotFoundHttpException();
+ }
+ if ($account->user_id !== Yii::$app->user->id) {
+ throw new ForbiddenHttpException();
+ }
+ $event = $this->make(SocialNetworkConnectEvent::class, [Yii::$app->user->identity, $account]);
+
+ $this->trigger(SocialNetworkConnectEvent::EVENT_BEFORE_DISCONNECT, $event);
+ $account->delete();
+ $this->trigger(SocialNetworkConnectEvent::EVENT_AFTER_DISCONNECT, $event);
+ }
}
diff --git a/src/User/Event/GdprEvent.php b/src/User/Event/GdprEvent.php
index d038b96..703c191 100644
--- a/src/User/Event/GdprEvent.php
+++ b/src/User/Event/GdprEvent.php
@@ -19,7 +19,6 @@ use yii\base\Event;
*/
class GdprEvent extends Event
{
-
const EVENT_BEFORE_DELETE = 'beforeDelete';
const EVENT_AFTER_DELETE = 'afterDelete';
/**
diff --git a/src/User/Factory/MailFactory.php b/src/User/Factory/MailFactory.php
index e21336c..6cb7920 100644
--- a/src/User/Factory/MailFactory.php
+++ b/src/User/Factory/MailFactory.php
@@ -117,12 +117,12 @@ class MailFactory
/**
* Builds a MailerService.
*
- * @param string $type
+ * @param string $type
* @param string|array|\Closure $from
- * @param string $to
- * @param string $subject
- * @param string $view
- * @param array $params
+ * @param string $to
+ * @param string $subject
+ * @param string $view
+ * @param array $params
*
* @throws InvalidConfigException
* @return MailService
@@ -130,7 +130,7 @@ class MailFactory
*/
public static function makeMailerService($type, $from, $to, $subject, $view, $params = [])
{
- if ($from instanceof \Closure){
+ if ($from instanceof \Closure) {
$from = $from($type);
}
/** @noinspection PhpIncompatibleReturnTypeInspection */
diff --git a/src/User/Filter/PasswordAgeEnforceFilter.php b/src/User/Filter/PasswordAgeEnforceFilter.php
index 9f92746..a0334a7 100644
--- a/src/User/Filter/PasswordAgeEnforceFilter.php
+++ b/src/User/Filter/PasswordAgeEnforceFilter.php
@@ -4,7 +4,6 @@
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS!
- * @author Lorenzo Milesi
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
diff --git a/src/User/Form/GdprDeleteForm.php b/src/User/Form/GdprDeleteForm.php
index 427376c..a720907 100644
--- a/src/User/Form/GdprDeleteForm.php
+++ b/src/User/Form/GdprDeleteForm.php
@@ -4,7 +4,6 @@
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS!
- * @author E. Alamo
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
@@ -12,7 +11,6 @@
namespace Da\User\Form;
-
use Da\User\Helper\SecurityHelper;
use Da\User\Model\User;
use Da\User\Traits\ContainerAwareTrait;
@@ -42,7 +40,7 @@ class GdprDeleteForm extends Model
/**
* @param SecurityHelper $securityHelper
- * @param array $config
+ * @param array $config
*/
public function __construct(SecurityHelper $securityHelper, $config = [])
{
diff --git a/src/User/Form/LoginForm.php b/src/User/Form/LoginForm.php
index 3327fba..c086b34 100644
--- a/src/User/Form/LoginForm.php
+++ b/src/User/Form/LoginForm.php
@@ -142,7 +142,7 @@ class LoginForm extends Model
* Validates form and logs the user in.
*
* @throws InvalidParamException
- * @return bool whether the user is logged in successfully
+ * @return bool whether the user is logged in successfully
*/
public function login()
{
diff --git a/src/User/Form/RegistrationForm.php b/src/User/Form/RegistrationForm.php
index 79156b4..bd96894 100644
--- a/src/User/Form/RegistrationForm.php
+++ b/src/User/Form/RegistrationForm.php
@@ -103,13 +103,17 @@ class RegistrationForm extends Model
public function attributeHints()
{
return [
- 'gdpr_consent' => Yii::t('usuario', 'I agree processing of my personal data and the use of cookies to facilitate the operation of this site. For more information read our {privacyPolicy}',
+ 'gdpr_consent' => Yii::t(
+ 'usuario',
+ 'I agree processing of my personal data and the use of cookies to facilitate the operation of this site. For more information read our {privacyPolicy}',
[
- 'privacyPolicy' => Html::a(Yii::t('usuario', 'privacy policy'),
+ 'privacyPolicy' => Html::a(
+ Yii::t('usuario', 'privacy policy'),
$this->module->gdprPrivacyPolicyUrl,
['target' => '_blank']
)
- ])
+ ]
+ )
];
}
}
diff --git a/src/User/Form/SettingsForm.php b/src/User/Form/SettingsForm.php
index 3366b34..803a6d6 100644
--- a/src/User/Form/SettingsForm.php
+++ b/src/User/Form/SettingsForm.php
@@ -55,7 +55,7 @@ class SettingsForm extends Model
* SettingsForm constructor.
*
* @param SecurityHelper $securityHelper
- * @param array $config
+ * @param array $config
*/
public function __construct(SecurityHelper $securityHelper, array $config = [])
{
diff --git a/src/User/Migration/m000000_000002_create_profile_table.php b/src/User/Migration/m000000_000002_create_profile_table.php
index aec68f6..e92105d 100644
--- a/src/User/Migration/m000000_000002_create_profile_table.php
+++ b/src/User/Migration/m000000_000002_create_profile_table.php
@@ -34,7 +34,7 @@ class m000000_000002_create_profile_table extends Migration
MigrationHelper::resolveTableOptions($this->db->driverName)
);
- $this->addPrimaryKey('{{%profile_pk}}','{{%profile}}','user_id');
+ $this->addPrimaryKey('{{%profile_pk}}', '{{%profile}}', 'user_id');
$restrict = MigrationHelper::isMicrosoftSQLServer($this->db->driverName) ? 'NO ACTION' : 'RESTRICT';
diff --git a/src/User/Migration/m000000_000008_add_last_login_ip.php b/src/User/Migration/m000000_000008_add_last_login_ip.php
index 4b9f8d9..8d03a1c 100644
--- a/src/User/Migration/m000000_000008_add_last_login_ip.php
+++ b/src/User/Migration/m000000_000008_add_last_login_ip.php
@@ -1,10 +1,19 @@
+ *
+ * For the full copyright and license information, please view
+ * the LICENSE file that was distributed with this source code.
+ */
+
namespace Da\User\Migration;
use yii\db\Migration;
use yii\db\Schema;
-
/**
* Class m000000_000008_add_last_login_ip
* @author: Kartik Visweswaran
diff --git a/src/User/Migration/m000000_000009_add_gdpr_consent_fields.php b/src/User/Migration/m000000_000009_add_gdpr_consent_fields.php
index 32c4c02..9dc5590 100644
--- a/src/User/Migration/m000000_000009_add_gdpr_consent_fields.php
+++ b/src/User/Migration/m000000_000009_add_gdpr_consent_fields.php
@@ -11,16 +11,16 @@
namespace Da\User\Migration;
-use yii\db\Migration;
use Da\User\Helper\MigrationHelper;
+use yii\db\Migration;
class m000000_000009_add_gdpr_consent_fields extends Migration
{
public function safeUp()
{
- $this->addColumn('{{%user}}', 'gdpr_consent', $this->boolean()->defaultValue(MigrationHelper::getBooleanValue($this->db->driverName,false)));
+ $this->addColumn('{{%user}}', 'gdpr_consent', $this->boolean()->defaultValue(MigrationHelper::getBooleanValue($this->db->driverName, false)));
$this->addColumn('{{%user}}', 'gdpr_consent_date', $this->integer(11)->null());
- $this->addColumn('{{%user}}', 'gdpr_deleted', $this->boolean()->defaultValue(MigrationHelper::getBooleanValue($this->db->driverName,false)));
+ $this->addColumn('{{%user}}', 'gdpr_deleted', $this->boolean()->defaultValue(MigrationHelper::getBooleanValue($this->db->driverName, false)));
}
public function safeDown()
diff --git a/src/User/Model/Rule.php b/src/User/Model/Rule.php
index 1803947..a406b35 100644
--- a/src/User/Model/Rule.php
+++ b/src/User/Model/Rule.php
@@ -14,8 +14,8 @@ namespace Da\User\Model;
use Da\User\Traits\AuthManagerAwareTrait;
use Da\User\Validator\RbacRuleNameValidator;
use Da\User\Validator\RbacRuleValidator;
-use yii\base\Model;
use Yii;
+use yii\base\Model;
class Rule extends Model
{
diff --git a/src/User/Model/SocialNetworkAccount.php b/src/User/Model/SocialNetworkAccount.php
index a064103..3251880 100644
--- a/src/User/Model/SocialNetworkAccount.php
+++ b/src/User/Model/SocialNetworkAccount.php
@@ -75,7 +75,7 @@ class SocialNetworkAccount extends ActiveRecord
/**
* @throws Exception
* @throws InvalidParamException
- * @return string the connection url
+ * @return string the connection url
*/
public function getConnectionUrl()
{
diff --git a/src/User/Model/Token.php b/src/User/Model/Token.php
index 27d441c..2ee8e97 100644
--- a/src/User/Model/Token.php
+++ b/src/User/Model/Token.php
@@ -101,7 +101,7 @@ class Token extends ActiveRecord
/**
* @throws RuntimeException
- * @return bool Whether token has expired
+ * @return bool Whether token has expired
*/
public function getIsExpired()
{
diff --git a/src/User/Model/User.php b/src/User/Model/User.php
index 0581719..212ff73 100644
--- a/src/User/Model/User.php
+++ b/src/User/Model/User.php
@@ -286,7 +286,7 @@ class User extends ActiveRecord implements IdentityInterface
/**
* @throws InvalidConfigException
- * @return bool whether the user is an admin or not
+ * @return bool whether the user is an admin or not
*/
public function getIsAdmin()
{
diff --git a/src/User/Service/PasswordExpireService.php b/src/User/Service/PasswordExpireService.php
index 4f668fd..bcbc611 100644
--- a/src/User/Service/PasswordExpireService.php
+++ b/src/User/Service/PasswordExpireService.php
@@ -11,9 +11,9 @@
namespace Da\User\Service;
-use Yii;
use Da\User\Contracts\ServiceInterface;
use Da\User\Model\User;
+use Yii;
class PasswordExpireService implements ServiceInterface
{
diff --git a/src/User/Service/UserCreateService.php b/src/User/Service/UserCreateService.php
index 2800460..60ff7eb 100644
--- a/src/User/Service/UserCreateService.php
+++ b/src/User/Service/UserCreateService.php
@@ -59,6 +59,7 @@ class UserCreateService implements ServiceInterface
? $model->password
: $this->securityHelper->generatePassword(8);
+ /** @var UserEvent $event */
$event = $this->make(UserEvent::class, [$model]);
$model->trigger(UserEvent::EVENT_BEFORE_CREATE, $event);
@@ -75,15 +76,15 @@ class UserCreateService implements ServiceInterface
['email' => $model->email]
);
// from web display a flash message (if enabled)
- if($this->getModule()->enableFlashMessages == TRUE && is_a(Yii::$app, yii\web\Application::class)) {
+ if ($this->getModule()->enableFlashMessages === true && is_a(Yii::$app, yii\web\Application::class)) {
Yii::$app->session->setFlash(
'warning',
$error_msg
);
}
// if we're from console add an error to the model in order to return an error message
- if(is_a(Yii::$app, yii\console\Application::class)) {
- $model->addError("username", $error_msg);
+ if (is_a(Yii::$app, yii\console\Application::class)) {
+ $model->addError('username', $error_msg);
}
$transaction->rollBack();
return false;
diff --git a/src/User/Widget/ReCaptchaWidget.php b/src/User/Widget/ReCaptchaWidget.php
index dfae5ce..f5bd278 100644
--- a/src/User/Widget/ReCaptchaWidget.php
+++ b/src/User/Widget/ReCaptchaWidget.php
@@ -83,7 +83,7 @@ class ReCaptchaWidget extends InputWidget
/**
* @throws InvalidConfigException
- * @return array the google recaptcha options.
+ * @return array the google recaptcha options.
*/
protected function getCaptchaOptions()
{