Fix merge with upstream
This commit is contained in:
@ -11,12 +11,14 @@
|
||||
|
||||
namespace Da\User\Form;
|
||||
|
||||
use Da\TwoFA\Exception\InvalidSecretKeyException;
|
||||
use Da\User\Helper\SecurityHelper;
|
||||
use Da\User\Model\User;
|
||||
use Da\User\Query\UserQuery;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use Da\User\Validator\TwoFactorCodeValidator;
|
||||
use Yii;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\base\Model;
|
||||
|
||||
class LoginForm extends Model
|
||||
@ -73,12 +75,14 @@ class LoginForm extends Model
|
||||
'login' => Yii::t('usuario', 'Login'),
|
||||
'password' => Yii::t('usuario', 'Password'),
|
||||
'rememberMe' => Yii::t('usuario', 'Remember me next time'),
|
||||
'twoFactorAuthenticationCode' => Yii::t('usuario', 'Two-factor authentication code')
|
||||
'twoFactorAuthenticationCode' => Yii::t('usuario', 'Two factor authentication code')
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws InvalidSecretKeyException
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
@ -111,7 +115,7 @@ class LoginForm extends Model
|
||||
$this->module->twoFactorAuthenticationCycles
|
||||
))
|
||||
->validate()) {
|
||||
$this->addError($attribute, Yii::t('usuario', 'Invalid two-factor code'));
|
||||
$this->addError($attribute, Yii::t('usuario', 'Invalid two factor authentication code'));
|
||||
}
|
||||
}
|
||||
],
|
||||
@ -137,6 +141,7 @@ class LoginForm extends Model
|
||||
/**
|
||||
* Validates form and logs the user in.
|
||||
*
|
||||
* @throws InvalidParamException
|
||||
* @return bool whether the user is logged in successfully
|
||||
*/
|
||||
public function login()
|
||||
|
||||
@ -42,6 +42,8 @@ class RegistrationForm extends Model
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
|
||||
@ -17,7 +17,10 @@ use Da\User\Model\User;
|
||||
use Da\User\Traits\ContainerAwareTrait;
|
||||
use Da\User\Traits\ModuleAwareTrait;
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\base\InvalidParamException;
|
||||
use yii\base\Model;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class SettingsForm extends Model
|
||||
{
|
||||
@ -48,18 +51,30 @@ class SettingsForm extends Model
|
||||
/** @var User */
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* SettingsForm constructor.
|
||||
*
|
||||
* @param SecurityHelper $securityHelper
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(SecurityHelper $securityHelper, array $config = [])
|
||||
{
|
||||
$this->securityHelper = $securityHelper;
|
||||
$config = [
|
||||
'username' => $this->getUser()->username,
|
||||
'email' => $this->getUser()->unconfirmed_email? : $this->getUser()->email
|
||||
];
|
||||
$config = ArrayHelper::merge(
|
||||
[
|
||||
'username' => $this->getUser()->username,
|
||||
'email' => $this->getUser()->unconfirmed_email ?: $this->getUser()->email
|
||||
],
|
||||
$config
|
||||
);
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigException
|
||||
* @throws InvalidParamException
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
@ -75,7 +90,7 @@ class SettingsForm extends Model
|
||||
['email', 'username'],
|
||||
'unique',
|
||||
'when' => function ($model, $attribute) {
|
||||
return $this->getUser()->$attribute != $model->$attribute;
|
||||
return $this->getUser()->$attribute !== $model->$attribute;
|
||||
},
|
||||
'targetClass' => $this->getClassMap()->get(User::class),
|
||||
],
|
||||
@ -110,7 +125,7 @@ class SettingsForm extends Model
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
if ($this->user == null) {
|
||||
if (null === $this->user) {
|
||||
$this->user = Yii::$app->user->identity;
|
||||
}
|
||||
|
||||
@ -120,7 +135,9 @@ class SettingsForm extends Model
|
||||
/**
|
||||
* Saves new account settings.
|
||||
*
|
||||
* @throws \Exception
|
||||
* @return bool
|
||||
*
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
@ -130,9 +147,9 @@ class SettingsForm extends Model
|
||||
$user->scenario = 'settings';
|
||||
$user->username = $this->username;
|
||||
$user->password = $this->new_password;
|
||||
if ($this->email == $user->email && $user->unconfirmed_email != null) {
|
||||
if ($this->email === $user->email && $user->unconfirmed_email !== null) {
|
||||
$user->unconfirmed_email = null;
|
||||
} elseif ($this->email != $user->email) {
|
||||
} elseif ($this->email !== $user->email) {
|
||||
$strategy = EmailChangeStrategyFactory::makeByStrategyType(
|
||||
$this->getModule()->emailChangeStrategy,
|
||||
$this
|
||||
|
||||
Reference in New Issue
Block a user