Изменёна кодировка столбца username в usernames_history для организации бинарного поиска

Из Account вынесена логика аутентификации в дочерний AccountIdentity
Исправлена логика валидации при вызове на неизменённом нике для формы смены ника
This commit is contained in:
ErickSkrauch
2016-05-12 11:50:30 +03:00
parent 2a4da87fd5
commit 184ff02240
6 changed files with 138 additions and 121 deletions

View File

@@ -13,7 +13,7 @@ return [
'controllerNamespace' => 'api\controllers',
'components' => [
'user' => [
'identityClass' => \common\models\Account::class,
'identityClass' => \api\models\AccountIdentity::class,
'enableSession' => false,
'loginUrl' => null,
],
@@ -21,7 +21,7 @@ return [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'class' => \yii\log\FileTarget::class,
'levels' => ['error', 'warning'],
],
],

View 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;
}
}

View File

@@ -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());