Из базы удалена таблица oauth_scopes

This commit is contained in:
ErickSkrauch 2016-11-27 19:19:13 +03:00
parent 744ec9520a
commit 1e94cda399
4 changed files with 35 additions and 14 deletions

View File

@ -12,14 +12,12 @@ class ScopeStorage extends AbstractStorage implements ScopeInterface {
* @inheritdoc * @inheritdoc
*/ */
public function get($scope, $grantType = null, $clientId = null) { public function get($scope, $grantType = null, $clientId = null) {
/** @var OauthScope|null $row */ if (!in_array($scope, OauthScope::getScopes(), true)) {
$row = OauthScope::findOne($scope);
if ($row === null) {
return null; return null;
} }
$entity = new ScopeEntity($this->server); $entity = new ScopeEntity($this->server);
$entity->setId($row->id); $entity->setId($scope);
return $entity; return $entity;
} }

View File

@ -1,21 +1,20 @@
<?php <?php
namespace common\models; namespace common\models;
use yii\db\ActiveRecord; class OauthScope {
/**
* Поля:
* @property string $id
*/
class OauthScope extends ActiveRecord {
const OFFLINE_ACCESS = 'offline_access'; const OFFLINE_ACCESS = 'offline_access';
const MINECRAFT_SERVER_SESSION = 'minecraft_server_session'; const MINECRAFT_SERVER_SESSION = 'minecraft_server_session';
const ACCOUNT_INFO = 'account_info'; const ACCOUNT_INFO = 'account_info';
const ACCOUNT_EMAIL = 'account_email'; const ACCOUNT_EMAIL = 'account_email';
public static function tableName() { public static function getScopes() : array {
return '{{%oauth_scopes}}'; return [
self::OFFLINE_ACCESS,
self::MINECRAFT_SERVER_SESSION,
self::ACCOUNT_INFO,
self::ACCOUNT_EMAIL,
];
} }
} }

View File

@ -0,0 +1,25 @@
<?php
use console\db\Migration;
class m161127_145211_remove_oauth_scopes extends Migration {
public function safeUp() {
$this->dropTable('{{%oauth_scopes}}');
}
public function safeDown() {
$this->createTable('{{%oauth_scopes}}', [
'id' => $this->string(64),
$this->primary('id'),
]);
$this->batchInsert('{{%oauth_scopes}}', ['id'], [
['offline_access'],
['minecraft_server_session'],
['account_info'],
['account_email'],
]);
}
}

View File

@ -1,7 +1,6 @@
<?php <?php
namespace tests\codeception\common\fixtures; namespace tests\codeception\common\fixtures;
use common\models\OauthScope;
use common\models\OauthSession; use common\models\OauthSession;
use yii\test\ActiveFixture; use yii\test\ActiveFixture;