mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Изменёна кодировка столбца username в usernames_history для организации бинарного поиска
Из Account вынесена логика аутентификации в дочерний AccountIdentity Исправлена логика валидации при вызове на неизменённом нике для формы смены ника
This commit is contained in:
37
api/models/AccountIdentity.php
Normal file
37
api/models/AccountIdentity.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace api\models;
|
||||
|
||||
use common\models\Account;
|
||||
use yii\base\NotSupportedException;
|
||||
use yii\web\IdentityInterface;
|
||||
|
||||
/**
|
||||
* @method static findIdentityByAccessToken($token, $type = null) этот метод реализуется в UserTrait, который
|
||||
* подключён в родительском Account и позволяет выполнить условия интерфейса
|
||||
* @method string getId() метод реализован в родительском классе, т.к. UserTrait требует, чтобы этот метод
|
||||
* присутствовал обязательно, но при этом не навязывает его как абстрактный
|
||||
*/
|
||||
class AccountIdentity extends Account implements IdentityInterface {
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function findIdentity($id) {
|
||||
return static::findOne($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getAuthKey() {
|
||||
throw new NotSupportedException('This method used for cookie auth, except we using JWT tokens');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validateAuthKey($authKey) {
|
||||
return $this->getAuthKey() === $authKey;
|
||||
}
|
||||
|
||||
}
|
@@ -3,7 +3,6 @@ namespace api\models;
|
||||
|
||||
use api\models\base\PasswordProtectedForm;
|
||||
use common\helpers\Amqp;
|
||||
use common\models\Account;
|
||||
use common\models\amqp\UsernameChanged;
|
||||
use common\models\UsernameHistory;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
@@ -23,7 +22,7 @@ class ChangeUsernameForm extends PasswordProtectedForm {
|
||||
}
|
||||
|
||||
public function validateUsername($attribute) {
|
||||
$account = new Account();
|
||||
$account = $this->getAccount();
|
||||
$account->username = $this->$attribute;
|
||||
if (!$account->validate(['username'])) {
|
||||
$this->addErrors($account->getErrors());
|
||||
|
Reference in New Issue
Block a user