Close #269 added help for console commands + php-cs-fixer
This commit is contained in:
@ -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)
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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'))) {
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -39,7 +39,6 @@ class RecoveryController extends Controller
|
||||
protected $userQuery;
|
||||
protected $tokenQuery;
|
||||
|
||||
|
||||
/**
|
||||
* RecoveryController constructor.
|
||||
*
|
||||
|
||||
@ -43,7 +43,6 @@ class RegistrationController extends Controller
|
||||
protected $userQuery;
|
||||
protected $socialNetworkAccountQuery;
|
||||
|
||||
|
||||
/**
|
||||
* RegistrationController constructor.
|
||||
*
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -38,7 +38,6 @@ class SecurityController extends Controller
|
||||
|
||||
protected $socialNetworkAccountQuery;
|
||||
|
||||
|
||||
/**
|
||||
* SecurityController constructor.
|
||||
*
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,6 @@ use yii\base\Event;
|
||||
*/
|
||||
class GdprEvent extends Event
|
||||
{
|
||||
|
||||
const EVENT_BEFORE_DELETE = 'beforeDelete';
|
||||
const EVENT_AFTER_DELETE = 'afterDelete';
|
||||
/**
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
* @author Lorenzo Milesi <maxxer@yetopen.it>
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
* @author E. Alamo <erosdelalamo@gmail.com>
|
||||
*
|
||||
* 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 = [])
|
||||
{
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
@ -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']
|
||||
)
|
||||
])
|
||||
]
|
||||
)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 = [])
|
||||
{
|
||||
|
||||
@ -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';
|
||||
|
||||
|
||||
@ -1,10 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the 2amigos/yii2-usuario project.
|
||||
*
|
||||
* (c) 2amigOS! <http://2amigos.us/>
|
||||
*
|
||||
* 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
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user