2016-02-14 23:20:10 +05:30
|
|
|
<?php
|
|
|
|
namespace common\models;
|
|
|
|
|
2016-11-27 20:11:39 +05:30
|
|
|
use common\components\Redis\Set;
|
2016-02-14 23:20:10 +05:30
|
|
|
use yii\db\ActiveRecord;
|
|
|
|
|
|
|
|
/**
|
2016-11-05 20:32:46 +05:30
|
|
|
* Поля:
|
2016-02-14 23:20:10 +05:30
|
|
|
* @property string $access_token
|
|
|
|
* @property string $session_id
|
|
|
|
* @property integer $expire_time
|
|
|
|
*
|
2016-11-05 20:32:46 +05:30
|
|
|
* Геттеры:
|
2016-02-14 23:20:10 +05:30
|
|
|
* @property Set $scopes
|
2016-08-04 03:37:21 +05:30
|
|
|
*
|
2016-11-05 20:32:46 +05:30
|
|
|
* Отношения:
|
2016-08-04 03:37:21 +05:30
|
|
|
* @property OauthSession $session
|
2016-02-14 23:20:10 +05:30
|
|
|
*/
|
|
|
|
class OauthAccessToken extends ActiveRecord {
|
|
|
|
|
|
|
|
public static function tableName() {
|
|
|
|
return '{{%oauth_access_tokens}}';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSession() {
|
|
|
|
return $this->hasOne(OauthSession::class, ['id' => 'session_id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getScopes() {
|
2016-11-05 20:32:46 +05:30
|
|
|
return new Set(static::getDb()->getSchema()->getRawTableName(static::tableName()), $this->access_token, 'scopes');
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public function beforeDelete() {
|
|
|
|
if (!$result = parent::beforeDelete()) {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->getScopes()->delete();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-03 04:24:22 +05:30
|
|
|
public function isExpired() : bool {
|
2016-08-04 03:37:21 +05:30
|
|
|
return time() > $this->expire_time;
|
|
|
|
}
|
|
|
|
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|