2016-02-14 23:20:10 +05:30
|
|
|
<?php
|
|
|
|
namespace common\models;
|
|
|
|
|
|
|
|
use common\components\redis\Set;
|
|
|
|
use yii\db\ActiveRecord;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the model class for table "oauth_access_tokens".
|
|
|
|
*
|
|
|
|
* @property string $access_token
|
|
|
|
* @property string $session_id
|
|
|
|
* @property integer $expire_time
|
|
|
|
*
|
|
|
|
* @property Set $scopes
|
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() {
|
|
|
|
return new Set($this->getDb()->getSchema()->getRawTableName($this->tableName()), $this->access_token, 'scopes');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function beforeDelete() {
|
|
|
|
if (!$result = parent::beforeDelete()) {
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->getScopes()->delete();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-04 03:37:21 +05:30
|
|
|
public function isExpired() {
|
|
|
|
return time() > $this->expire_time;
|
|
|
|
}
|
|
|
|
|
2016-02-14 23:20:10 +05:30
|
|
|
}
|