mirror of
https://github.com/elyby/accounts.git
synced 2024-11-09 23:12:20 +05:30
В форму регистрации и форму повторной отправки Email внедрён валидатор ReCaptcha
This commit is contained in:
parent
bef12954bd
commit
c2986445f1
@ -61,7 +61,7 @@ class SignupController extends Controller {
|
||||
'errors' => $this->normalizeModelErrors($model->getErrors()),
|
||||
];
|
||||
|
||||
if ($response['errors']['email'] === E::RECENTLY_SENT_MESSAGE) {
|
||||
if (ArrayHelper::getValue($response['errors'], 'email') === E::RECENTLY_SENT_MESSAGE) {
|
||||
$activation = $model->getActivation();
|
||||
$response['data'] = [
|
||||
'canRepeatIn' => $activation->canRepeatIn(),
|
||||
|
@ -19,16 +19,23 @@ use yii\base\InvalidConfigException;
|
||||
|
||||
class RegistrationForm extends ApiForm {
|
||||
|
||||
public $captcha;
|
||||
|
||||
public $username;
|
||||
|
||||
public $email;
|
||||
|
||||
public $password;
|
||||
|
||||
public $rePassword;
|
||||
|
||||
public $rulesAgreement;
|
||||
|
||||
public $lang;
|
||||
|
||||
public function rules() {
|
||||
return [
|
||||
[[], ReCaptchaValidator::class, 'message' => E::CAPTCHA_INVALID, 'when' => !YII_ENV_TEST],
|
||||
['captcha', ReCaptchaValidator::class],
|
||||
['rulesAgreement', 'required', 'message' => E::RULES_AGREEMENT_REQUIRED],
|
||||
|
||||
['username', 'validateUsername', 'skipOnEmpty' => false],
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace api\models\authentication;
|
||||
|
||||
use api\components\ReCaptcha\Validator as ReCaptchaValidator;
|
||||
use api\models\base\ApiForm;
|
||||
use common\helpers\Error as E;
|
||||
use common\components\UserFriendlyRandomKey;
|
||||
@ -12,12 +13,15 @@ use yii\base\ErrorException;
|
||||
|
||||
class RepeatAccountActivationForm extends ApiForm {
|
||||
|
||||
public $captcha;
|
||||
|
||||
public $email;
|
||||
|
||||
private $emailActivation;
|
||||
|
||||
public function rules() {
|
||||
return [
|
||||
['captcha', ReCaptchaValidator::class],
|
||||
['email', 'filter', 'filter' => 'trim'],
|
||||
['email', 'required', 'message' => E::EMAIL_REQUIRED],
|
||||
['email', 'validateEmailForAccount'],
|
||||
@ -26,7 +30,7 @@ class RepeatAccountActivationForm extends ApiForm {
|
||||
}
|
||||
|
||||
public function validateEmailForAccount($attribute) {
|
||||
if (!$this->hasErrors($attribute)) {
|
||||
if (!$this->hasErrors()) {
|
||||
$account = $this->getAccount();
|
||||
if ($account === null) {
|
||||
$this->addError($attribute, E::EMAIL_NOT_FOUND);
|
||||
@ -40,7 +44,7 @@ class RepeatAccountActivationForm extends ApiForm {
|
||||
}
|
||||
|
||||
public function validateExistsActivation($attribute) {
|
||||
if (!$this->hasErrors($attribute)) {
|
||||
if (!$this->hasErrors()) {
|
||||
$activation = $this->getActivation();
|
||||
if ($activation !== null && !$activation->canRepeat()) {
|
||||
$this->addError($attribute, E::RECENTLY_SENT_MESSAGE);
|
||||
|
Loading…
Reference in New Issue
Block a user