mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Реализована логика oAuth авторизации приложений, добавлен Redis, удалены лишние тесты, пофикшены старые.
This commit is contained in:
54
common/models/OauthSession.php
Normal file
54
common/models/OauthSession.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace common\models;
|
||||
|
||||
use common\components\redis\Set;
|
||||
use Yii;
|
||||
use yii\db\ActiveRecord;
|
||||
|
||||
/**
|
||||
* Поля:
|
||||
* @property integer $id
|
||||
* @property string $owner_type
|
||||
* @property string $owner_id
|
||||
* @property string $client_id
|
||||
* @property string $client_redirect_uri
|
||||
*
|
||||
* Отношения
|
||||
* @property OauthAccessToken[] $accessTokens
|
||||
* @property OauthClient $client
|
||||
* @property Account $account
|
||||
* @property Set $scopes
|
||||
*/
|
||||
class OauthSession extends ActiveRecord {
|
||||
|
||||
public static function tableName() {
|
||||
return '{{%oauth_sessions}}';
|
||||
}
|
||||
|
||||
public function getOauthAccessTokens() {
|
||||
return $this->hasMany(OauthAccessToken::class, ['session_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getClient() {
|
||||
return $this->hasOne(OauthClient::class, ['id' => 'client_id']);
|
||||
}
|
||||
|
||||
public function getAccount() {
|
||||
return $this->hasOne(Account::class, ['id' => 'owner_id']);
|
||||
}
|
||||
|
||||
public function getScopes() {
|
||||
return new Set($this->getDb()->getSchema()->getRawTableName($this->tableName()), $this->id, 'scopes');
|
||||
}
|
||||
|
||||
public function beforeDelete() {
|
||||
if (!$result = parent::beforeDelete()) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$this->getScopes()->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user