From 8906370bb96823627ed8b6cfa381fcac6ce0d9b8 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Thu, 16 Jun 2016 23:32:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D1=80=D0=B0=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=20=D1=85=D0=B5=D0=BB=D0=BF=D0=B5=D1=80=20Error,=20?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D1=8B=20=D0=B2=D1=81=D0=B5?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=B4=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA.=20=D0=9F=D0=BE=D0=B4=D0=BA=D0=BE=D1=80=D1=80=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20errorDict=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D1=80=D0=BE=D0=BD=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controllers/AuthenticationController.php | 5 +- api/controllers/SignupController.php | 3 +- api/models/FeedbackForm.php | 7 ++- .../authentication/ForgotPasswordForm.php | 9 +-- api/models/authentication/LoginForm.php | 11 ++-- .../authentication/RecoverPasswordForm.php | 6 +- .../authentication/RefreshTokenForm.php | 5 +- .../authentication/RegistrationForm.php | 11 ++-- .../RepeatAccountActivationForm.php | 11 ++-- api/models/base/KeyConfirmationForm.php | 3 +- api/models/base/PasswordProtectedForm.php | 5 +- .../ChangeEmail/ConfirmNewEmailForm.php | 4 +- .../profile/ChangeEmail/InitStateForm.php | 6 +- .../profile/ChangeEmail/NewEmailForm.php | 3 +- api/models/profile/ChangePasswordForm.php | 10 +-- api/models/profile/ChangeUsernameForm.php | 5 +- .../EmailActivationKeyValidator.php | 5 +- common/helpers/Error.php | 63 +++++++++++++++++++ common/models/Account.php | 21 ++++--- common/validators/LanguageValidator.php | 3 +- common/validators/PasswordValidate.php | 3 +- .../models/profile/ChangePasswordFormTest.php | 8 +-- 22 files changed, 146 insertions(+), 61 deletions(-) create mode 100644 common/helpers/Error.php diff --git a/api/controllers/AuthenticationController.php b/api/controllers/AuthenticationController.php index 07555d6..e9d336f 100644 --- a/api/controllers/AuthenticationController.php +++ b/api/controllers/AuthenticationController.php @@ -5,6 +5,7 @@ use api\models\authentication\ForgotPasswordForm; use api\models\authentication\LoginForm; use api\models\authentication\RecoverPasswordForm; use api\models\authentication\RefreshTokenForm; +use common\helpers\Error as E; use common\helpers\StringHelper; use Yii; use yii\filters\AccessControl; @@ -48,7 +49,7 @@ class AuthenticationController extends Controller { 'errors' => $this->normalizeModelErrors($model->getErrors()), ]; - if (ArrayHelper::getValue($data['errors'], 'login') === 'error.account_not_activated') { + if (ArrayHelper::getValue($data['errors'], 'login') === E::ACCOUNT_NOT_ACTIVATED) { $data['data']['email'] = $model->getAccount()->email; } @@ -69,7 +70,7 @@ class AuthenticationController extends Controller { 'errors' => $this->normalizeModelErrors($model->getErrors()), ]; - if (ArrayHelper::getValue($data['errors'], 'login') === 'error.recently_sent_message') { + if (ArrayHelper::getValue($data['errors'], 'login') === E::RECENTLY_SENT_MESSAGE) { $emailActivation = $model->getEmailActivation(); $data['data'] = [ 'canRepeatIn' => $emailActivation->canRepeatIn(), diff --git a/api/controllers/SignupController.php b/api/controllers/SignupController.php index 996e8ef..e338f17 100644 --- a/api/controllers/SignupController.php +++ b/api/controllers/SignupController.php @@ -4,6 +4,7 @@ namespace api\controllers; use api\models\authentication\ConfirmEmailForm; use api\models\authentication\RepeatAccountActivationForm; use api\models\authentication\RegistrationForm; +use common\helpers\Error as E; use Yii; use yii\filters\AccessControl; use yii\helpers\ArrayHelper; @@ -60,7 +61,7 @@ class SignupController extends Controller { 'errors' => $this->normalizeModelErrors($model->getErrors()), ]; - if ($response['errors']['email'] === 'error.recently_sent_message') { + if ($response['errors']['email'] === E::RECENTLY_SENT_MESSAGE) { $activation = $model->getActivation(); $response['data'] = [ 'canRepeatIn' => $activation->canRepeatIn(), diff --git a/api/models/FeedbackForm.php b/api/models/FeedbackForm.php index f9f1361..59848fa 100644 --- a/api/models/FeedbackForm.php +++ b/api/models/FeedbackForm.php @@ -1,6 +1,7 @@ 'error.{attribute}_required'], + ['subject', 'required', 'message' => E::SUBJECT_REQUIRED], + ['email', 'required', 'message' => E::EMAIL_REQUIRED], + ['message', 'required', 'message' => E::MESSAGE_REQUIRED], [['subject'], 'string', 'max' => 255], - [['email'], 'email'], + [['email'], 'email', 'message' => E::EMAIL_INVALID], [['message'], 'string', 'max' => 65535], ]; } diff --git a/api/models/authentication/ForgotPasswordForm.php b/api/models/authentication/ForgotPasswordForm.php index 78f2757..61dfe5e 100644 --- a/api/models/authentication/ForgotPasswordForm.php +++ b/api/models/authentication/ForgotPasswordForm.php @@ -2,6 +2,7 @@ namespace api\models\authentication; use api\models\base\ApiForm; +use common\helpers\Error as E; use api\traits\AccountFinder; use common\components\UserFriendlyRandomKey; use common\models\Account; @@ -18,7 +19,7 @@ class ForgotPasswordForm extends ApiForm { public function rules() { return [ - ['login', 'required', 'message' => 'error.login_required'], + ['login', 'required', 'message' => E::LOGIN_REQUIRED], ['login', 'validateLogin'], ['login', 'validateActivity'], ['login', 'validateFrequency'], @@ -28,7 +29,7 @@ class ForgotPasswordForm extends ApiForm { public function validateLogin($attribute) { if (!$this->hasErrors()) { if ($this->getAccount() === null) { - $this->addError($attribute, 'error.' . $attribute . '_not_exist'); + $this->addError($attribute, E::LOGIN_NOT_EXIST); } } } @@ -37,7 +38,7 @@ class ForgotPasswordForm extends ApiForm { if (!$this->hasErrors()) { $account = $this->getAccount(); if ($account->status !== Account::STATUS_ACTIVE) { - $this->addError($attribute, 'error.account_not_activated'); + $this->addError($attribute, E::ACCOUNT_NOT_ACTIVATED); } } } @@ -46,7 +47,7 @@ class ForgotPasswordForm extends ApiForm { if (!$this->hasErrors()) { $emailConfirmation = $this->getEmailActivation(); if ($emailConfirmation !== null && !$emailConfirmation->canRepeat()) { - $this->addError($attribute, 'error.recently_sent_message'); + $this->addError($attribute, E::RECENTLY_SENT_MESSAGE); } } } diff --git a/api/models/authentication/LoginForm.php b/api/models/authentication/LoginForm.php index 0a24652..3462000 100644 --- a/api/models/authentication/LoginForm.php +++ b/api/models/authentication/LoginForm.php @@ -3,6 +3,7 @@ namespace api\models\authentication; use api\models\AccountIdentity; use api\models\base\ApiForm; +use common\helpers\Error as E; use api\traits\AccountFinder; use common\models\Account; use Yii; @@ -19,12 +20,12 @@ class LoginForm extends ApiForm { public function rules() { return [ - ['login', 'required', 'message' => 'error.login_required'], + ['login', 'required', 'message' => E::LOGIN_REQUIRED], ['login', 'validateLogin'], ['password', 'required', 'when' => function(self $model) { return !$model->hasErrors(); - }, 'message' => 'error.password_required'], + }, 'message' => E::PASSWORD_REQUIRED], ['password', 'validatePassword'], ['login', 'validateActivity'], @@ -36,7 +37,7 @@ class LoginForm extends ApiForm { public function validateLogin($attribute) { if (!$this->hasErrors()) { if ($this->getAccount() === null) { - $this->addError($attribute, 'error.' . $attribute . '_not_exist'); + $this->addError($attribute, E::LOGIN_NOT_EXIST); } } } @@ -45,7 +46,7 @@ class LoginForm extends ApiForm { if (!$this->hasErrors()) { $account = $this->getAccount(); if ($account === null || !$account->validatePassword($this->password)) { - $this->addError($attribute, 'error.' . $attribute . '_incorrect'); + $this->addError($attribute, E::PASSWORD_INCORRECT); } } } @@ -54,7 +55,7 @@ class LoginForm extends ApiForm { if (!$this->hasErrors()) { $account = $this->getAccount(); if ($account->status !== Account::STATUS_ACTIVE) { - $this->addError($attribute, 'error.account_not_activated'); + $this->addError($attribute, E::ACCOUNT_NOT_ACTIVATED); } } } diff --git a/api/models/authentication/RecoverPasswordForm.php b/api/models/authentication/RecoverPasswordForm.php index b90dd2d..31a2998 100644 --- a/api/models/authentication/RecoverPasswordForm.php +++ b/api/models/authentication/RecoverPasswordForm.php @@ -3,6 +3,7 @@ namespace api\models\authentication; use api\models\AccountIdentity; use api\models\base\KeyConfirmationForm; +use common\helpers\Error as E; use common\models\EmailActivation; use common\validators\PasswordValidate; use Yii; @@ -16,7 +17,8 @@ class RecoverPasswordForm extends KeyConfirmationForm { public function rules() { return array_merge(parent::rules(), [ - [['newPassword', 'newRePassword'], 'required', 'message' => 'error.{attribute}_required'], + ['newPassword', 'required', 'message' => E::NEW_PASSWORD_REQUIRED], + ['newRePassword', 'required', 'message' => E::NEW_RE_PASSWORD_REQUIRED], ['newPassword', PasswordValidate::class], ['newRePassword', 'validatePasswordAndRePasswordMatch'], ]); @@ -25,7 +27,7 @@ class RecoverPasswordForm extends KeyConfirmationForm { public function validatePasswordAndRePasswordMatch($attribute) { if (!$this->hasErrors()) { if ($this->newPassword !== $this->newRePassword) { - $this->addError($attribute, 'error.rePassword_does_not_match'); + $this->addError($attribute, E::NEW_RE_PASSWORD_DOES_NOT_MATCH); } } } diff --git a/api/models/authentication/RefreshTokenForm.php b/api/models/authentication/RefreshTokenForm.php index e637e98..71bc702 100644 --- a/api/models/authentication/RefreshTokenForm.php +++ b/api/models/authentication/RefreshTokenForm.php @@ -2,6 +2,7 @@ namespace api\models\authentication; use api\models\base\ApiForm; +use common\helpers\Error as E; use common\models\AccountSession; use Yii; @@ -16,7 +17,7 @@ class RefreshTokenForm extends ApiForm { public function rules() { return [ - ['refresh_token', 'required'], + ['refresh_token', 'required', 'message' => E::REFRESH_TOKEN_REQUIRED], ['refresh_token', 'validateRefreshToken'], ]; } @@ -25,7 +26,7 @@ class RefreshTokenForm extends ApiForm { if (!$this->hasErrors()) { /** @var AccountSession|null $token */ if ($this->getSession() === null) { - $this->addError('refresh_token', 'error.refresh_token_not_exist'); + $this->addError('refresh_token', E::REFRESH_TOKEN_NOT_EXISTS); } } } diff --git a/api/models/authentication/RegistrationForm.php b/api/models/authentication/RegistrationForm.php index 61d066a..e01bb2c 100644 --- a/api/models/authentication/RegistrationForm.php +++ b/api/models/authentication/RegistrationForm.php @@ -3,6 +3,7 @@ namespace api\models\authentication; use api\components\ReCaptcha\Validator as ReCaptchaValidator; use api\models\base\ApiForm; +use common\helpers\Error as E; use api\models\profile\ChangeUsernameForm; use common\components\UserFriendlyRandomKey; use common\models\Account; @@ -26,14 +27,14 @@ class RegistrationForm extends ApiForm { public function rules() { return [ - [[], ReCaptchaValidator::class, 'message' => 'error.captcha_invalid', 'when' => !YII_ENV_TEST], - ['rulesAgreement', 'required', 'message' => 'error.rulesAgreement_required'], + [[], ReCaptchaValidator::class, 'message' => E::CAPTCHA_INVALID, 'when' => !YII_ENV_TEST], + ['rulesAgreement', 'required', 'message' => E::RULES_AGREEMENT_REQUIRED], ['username', 'validateUsername', 'skipOnEmpty' => false], ['email', 'validateEmail', 'skipOnEmpty' => false], - ['password', 'required', 'message' => 'error.password_required'], - ['rePassword', 'required', 'message' => 'error.rePassword_required'], + ['password', 'required', 'message' => E::PASSWORD_REQUIRED], + ['rePassword', 'required', 'message' => E::RE_PASSWORD_REQUIRED], ['password', PasswordValidate::class], ['rePassword', 'validatePasswordAndRePasswordMatch'], @@ -60,7 +61,7 @@ class RegistrationForm extends ApiForm { public function validatePasswordAndRePasswordMatch($attribute) { if (!$this->hasErrors()) { if ($this->password !== $this->rePassword) { - $this->addError($attribute, "error.rePassword_does_not_match"); + $this->addError($attribute, E::RE_PASSWORD_DOES_NOT_MATCH); } } } diff --git a/api/models/authentication/RepeatAccountActivationForm.php b/api/models/authentication/RepeatAccountActivationForm.php index f13a824..18a7136 100644 --- a/api/models/authentication/RepeatAccountActivationForm.php +++ b/api/models/authentication/RepeatAccountActivationForm.php @@ -2,6 +2,7 @@ namespace api\models\authentication; use api\models\base\ApiForm; +use common\helpers\Error as E; use common\components\UserFriendlyRandomKey; use common\models\Account; use common\models\confirmations\RegistrationConfirmation; @@ -18,7 +19,7 @@ class RepeatAccountActivationForm extends ApiForm { public function rules() { return [ ['email', 'filter', 'filter' => 'trim'], - ['email', 'required', 'message' => 'error.email_required'], + ['email', 'required', 'message' => E::EMAIL_REQUIRED], ['email', 'validateEmailForAccount'], ['email', 'validateExistsActivation'], ]; @@ -28,12 +29,12 @@ class RepeatAccountActivationForm extends ApiForm { if (!$this->hasErrors($attribute)) { $account = $this->getAccount(); if ($account === null) { - $this->addError($attribute, "error.{$attribute}_not_found"); + $this->addError($attribute, E::EMAIL_NOT_FOUND); } elseif ($account->status === Account::STATUS_ACTIVE) { - $this->addError($attribute, "error.account_already_activated"); + $this->addError($attribute, E::ACCOUNT_ALREADY_ACTIVATED); } elseif ($account->status !== Account::STATUS_REGISTERED) { // TODO: такие аккаунты следует логировать за попытку к саботажу - $this->addError($attribute, "error.account_cannot_resend_message"); + $this->addError($attribute, E::ACCOUNT_CANNOT_RESEND_MESSAGE); } } } @@ -42,7 +43,7 @@ class RepeatAccountActivationForm extends ApiForm { if (!$this->hasErrors($attribute)) { $activation = $this->getActivation(); if ($activation !== null && !$activation->canRepeat()) { - $this->addError($attribute, 'error.recently_sent_message'); + $this->addError($attribute, E::RECENTLY_SENT_MESSAGE); } } } diff --git a/api/models/base/KeyConfirmationForm.php b/api/models/base/KeyConfirmationForm.php index 07f50eb..9148351 100644 --- a/api/models/base/KeyConfirmationForm.php +++ b/api/models/base/KeyConfirmationForm.php @@ -1,6 +1,7 @@ 'error.key_required'], + ['key', 'required', 'message' => E::KEY_REQUIRED], ['key', EmailActivationKeyValidator::class], ]; } diff --git a/api/models/base/PasswordProtectedForm.php b/api/models/base/PasswordProtectedForm.php index 2289969..da82ba0 100644 --- a/api/models/base/PasswordProtectedForm.php +++ b/api/models/base/PasswordProtectedForm.php @@ -1,6 +1,7 @@ 'error.password_required'], + [['password'], 'required', 'message' => E::PASSWORD_REQUIRED], [['password'], 'validatePassword'], ]; } public function validatePassword() { if (!$this->getAccount()->validatePassword($this->password)) { - $this->addError('password', 'error.password_invalid'); + $this->addError('password', E::PASSWORD_INVALID); } } diff --git a/api/models/profile/ChangeEmail/ConfirmNewEmailForm.php b/api/models/profile/ChangeEmail/ConfirmNewEmailForm.php index efc47d1..466dc04 100644 --- a/api/models/profile/ChangeEmail/ConfirmNewEmailForm.php +++ b/api/models/profile/ChangeEmail/ConfirmNewEmailForm.php @@ -22,11 +22,11 @@ class ConfirmNewEmailForm extends KeyConfirmationForm { /** * @return Account */ - public function getAccount() { + public function getAccount() : Account { return $this->account; } - public function changeEmail() { + public function changeEmail() : bool { if (!$this->validate()) { return false; } diff --git a/api/models/profile/ChangeEmail/InitStateForm.php b/api/models/profile/ChangeEmail/InitStateForm.php index dc96a30..378047b 100644 --- a/api/models/profile/ChangeEmail/InitStateForm.php +++ b/api/models/profile/ChangeEmail/InitStateForm.php @@ -21,7 +21,7 @@ class InitStateForm extends PasswordProtectedForm { parent::__construct($config); } - public function getAccount() { + public function getAccount() : Account { return $this->account; } @@ -32,7 +32,7 @@ class InitStateForm extends PasswordProtectedForm { ]); } - public function sendCurrentEmailConfirmation() { + public function sendCurrentEmailConfirmation() : bool { if (!$this->validate()) { return false; } @@ -55,7 +55,7 @@ class InitStateForm extends PasswordProtectedForm { * @return CurrentEmailConfirmation * @throws ErrorException */ - public function createCode() { + public function createCode() : CurrentEmailConfirmation { $account = $this->getAccount(); $emailActivation = new CurrentEmailConfirmation(); $emailActivation->account_id = $account->id; diff --git a/api/models/profile/ChangeEmail/NewEmailForm.php b/api/models/profile/ChangeEmail/NewEmailForm.php index 07950ea..c87ba6c 100644 --- a/api/models/profile/ChangeEmail/NewEmailForm.php +++ b/api/models/profile/ChangeEmail/NewEmailForm.php @@ -2,6 +2,7 @@ namespace api\models\profile\ChangeEmail; use api\models\base\KeyConfirmationForm; +use common\helpers\Error as E; use common\models\Account; use common\models\confirmations\NewEmailConfirmation; use common\models\EmailActivation; @@ -33,7 +34,7 @@ class NewEmailForm extends KeyConfirmationForm { public function rules() { return array_merge(parent::rules(), [ - ['email', 'required', 'message' => 'error.email_required'], + ['email', 'required', 'message' => E::EMAIL_REQUIRED], ['email', 'validateEmail'], ]); } diff --git a/api/models/profile/ChangePasswordForm.php b/api/models/profile/ChangePasswordForm.php index 64bc5f2..d4d0cb6 100644 --- a/api/models/profile/ChangePasswordForm.php +++ b/api/models/profile/ChangePasswordForm.php @@ -2,6 +2,7 @@ namespace api\models\profile; use api\models\base\PasswordProtectedForm; +use common\helpers\Error as E; use common\models\Account; use common\validators\PasswordValidate; use Yii; @@ -31,7 +32,8 @@ class ChangePasswordForm extends PasswordProtectedForm { */ public function rules() { return ArrayHelper::merge(parent::rules(), [ - [['newPassword', 'newRePassword'], 'required', 'message' => 'error.{attribute}_required'], + ['newPassword', 'required', 'message' => E::NEW_PASSWORD_REQUIRED], + ['newRePassword', 'required', 'message' => E::NEW_RE_PASSWORD_REQUIRED], ['newPassword', PasswordValidate::class], ['newRePassword', 'validatePasswordAndRePasswordMatch'], ['logoutAll', 'boolean'], @@ -41,7 +43,7 @@ class ChangePasswordForm extends PasswordProtectedForm { public function validatePasswordAndRePasswordMatch($attribute) { if (!$this->hasErrors($attribute)) { if ($this->newPassword !== $this->newRePassword) { - $this->addError($attribute, 'error.newRePassword_does_not_match'); + $this->addError($attribute, E::NEW_RE_PASSWORD_DOES_NOT_MATCH); } } } @@ -49,7 +51,7 @@ class ChangePasswordForm extends PasswordProtectedForm { /** * @return boolean */ - public function changePassword() { + public function changePassword() : bool { if (!$this->validate()) { return false; } @@ -79,7 +81,7 @@ class ChangePasswordForm extends PasswordProtectedForm { return true; } - protected function getAccount() { + protected function getAccount() : Account { return $this->_account; } diff --git a/api/models/profile/ChangeUsernameForm.php b/api/models/profile/ChangeUsernameForm.php index a162f3b..074b48f 100644 --- a/api/models/profile/ChangeUsernameForm.php +++ b/api/models/profile/ChangeUsernameForm.php @@ -2,6 +2,7 @@ namespace api\models\profile; use api\models\base\PasswordProtectedForm; +use common\helpers\Error; use common\helpers\Amqp; use common\models\amqp\UsernameChanged; use common\models\UsernameHistory; @@ -16,8 +17,8 @@ class ChangeUsernameForm extends PasswordProtectedForm { public function rules() { return ArrayHelper::merge(parent::rules(), [ - [['username'], 'required', 'message' => 'error.{attribute}_required'], - [['username'], 'validateUsername'], + ['username', 'required', 'message' => Error::USERNAME_REQUIRED], + ['username', 'validateUsername'], ]); } diff --git a/api/validators/EmailActivationKeyValidator.php b/api/validators/EmailActivationKeyValidator.php index 3154876..9684482 100644 --- a/api/validators/EmailActivationKeyValidator.php +++ b/api/validators/EmailActivationKeyValidator.php @@ -1,14 +1,15 @@ findEmailActivationModel($value)) === null) { diff --git a/common/helpers/Error.php b/common/helpers/Error.php new file mode 100644 index 0000000..fb3fb7b --- /dev/null +++ b/common/helpers/Error.php @@ -0,0 +1,63 @@ + 'trim'], - [['username'], 'required', 'message' => 'error.username_required'], + [['username'], 'required', 'message' => E::USERNAME_REQUIRED], [['username'], 'string', 'min' => 3, 'max' => 21, - 'tooShort' => 'error.username_too_short', - 'tooLong' => 'error.username_too_long', + 'tooShort' => E::USERNAME_TOO_SHORT, + 'tooLong' => E::USERNAME_TOO_LONG, ], [['username'], 'match', 'pattern' => '/^[\p{L}\d-_\.!?#$%^&*()\[\]:;]+$/u', - 'message' => 'error.username_invalid', + 'message' => E::USERNAME_INVALID, ], - [['username'], 'unique', 'message' => 'error.username_not_available'], + [['username'], 'unique', 'message' => E::USERNAME_NOT_AVAILABLE], [['email'], 'filter', 'filter' => 'trim'], - [['email'], 'required', 'message' => 'error.email_required'], - [['email'], 'string', 'max' => 255, 'tooLong' => 'error.email_too_long'], - [['email'], 'email', 'checkDNS' => true, 'enableIDN' => true, 'message' => 'error.email_invalid'], - [['email'], TempmailValidator::class, 'message' => 'error.email_is_tempmail'], - [['email'], 'unique', 'message' => 'error.email_not_available'], + [['email'], 'required', 'message' => E::EMAIL_REQUIRED], + [['email'], 'string', 'max' => 255, 'tooLong' => E::EMAIL_TOO_LONG], + [['email'], 'email', 'checkDNS' => true, 'enableIDN' => true, 'message' => E::EMAIL_INVALID], + [['email'], TempmailValidator::class, 'message' => E::EMAIL_IS_TEMPMAIL], + [['email'], 'unique', 'message' => E::EMAIL_NOT_AVAILABLE], [['lang'], LanguageValidator::class], [['lang'], 'default', 'value' => 'en'], diff --git a/common/validators/LanguageValidator.php b/common/validators/LanguageValidator.php index a553bac..409e4a4 100644 --- a/common/validators/LanguageValidator.php +++ b/common/validators/LanguageValidator.php @@ -1,12 +1,13 @@ specify('error.newRePassword_does_not_match expected if passwords not match', function() { + $this->specify('error.rePassword_does_not_match expected if passwords not match', function() { $account = new Account(); $account->setPassword('12345678'); $model = new ChangePasswordForm($account, [ @@ -36,7 +36,7 @@ class ChangePasswordFormTest extends DbTestCase { 'newRePassword' => 'another-password', ]); $model->validatePasswordAndRePasswordMatch('newRePassword'); - expect($model->getErrors('newRePassword'))->equals(['error.newRePassword_does_not_match']); + expect($model->getErrors('newRePassword'))->equals(['error.rePassword_does_not_match']); }); $this->specify('no errors expected if passwords are valid', function() { @@ -51,7 +51,7 @@ class ChangePasswordFormTest extends DbTestCase { expect($model->getErrors('newRePassword'))->isEmpty(); }); - $this->specify('error.newRePassword_does_not_match expected even if there are errors on other attributes', function() { + $this->specify('error.rePassword_does_not_match expected even if there are errors on other attributes', function() { // this is very important, because password change flow may be combined of two steps // therefore we need to validate password sameness before we will validate current account password $account = new Account(); @@ -61,7 +61,7 @@ class ChangePasswordFormTest extends DbTestCase { 'newRePassword' => 'another-password', ]); $model->validate(); - expect($model->getErrors('newRePassword'))->equals(['error.newRePassword_does_not_match']); + expect($model->getErrors('newRePassword'))->equals(['error.rePassword_does_not_match']); }); }