2016-08-21 04:51:39 +05:30
|
|
|
<?php
|
|
|
|
namespace common\models;
|
|
|
|
|
|
|
|
use common\behaviors\PrimaryKeyValueBehavior;
|
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
use yii\behaviors\TimestampBehavior;
|
|
|
|
use yii\db\ActiveRecord;
|
|
|
|
|
|
|
|
/**
|
2019-07-15 04:29:56 +05:30
|
|
|
* This is a temporary class where all the logic of the authserver.ely.by service.
|
|
|
|
* Since the login and password were allowed there, and the format of storage of the issued tokens was different,
|
|
|
|
* we need to keep the legacy logic and structure under it for the period until we finally migrate.
|
2016-08-21 04:51:39 +05:30
|
|
|
*
|
2019-07-15 04:29:56 +05:30
|
|
|
* Fields:
|
2016-08-21 04:51:39 +05:30
|
|
|
* @property string $access_token
|
|
|
|
* @property string $client_token
|
|
|
|
* @property integer $account_id
|
|
|
|
* @property integer $created_at
|
|
|
|
* @property integer $updated_at
|
|
|
|
*
|
2019-07-15 04:29:56 +05:30
|
|
|
* Relations:
|
2016-08-21 04:51:39 +05:30
|
|
|
* @property Account $account
|
|
|
|
*
|
2019-07-15 04:29:56 +05:30
|
|
|
* Behaviors:
|
2016-08-21 04:51:39 +05:30
|
|
|
* @mixin TimestampBehavior
|
|
|
|
* @mixin PrimaryKeyValueBehavior
|
2019-12-11 16:54:31 +05:30
|
|
|
*
|
|
|
|
* @deprecated This table is no longer used to store authorization information in Minecraft.
|
|
|
|
* In time it will be empty (see the cleanup console command) and when it does, this model,
|
|
|
|
* the table in the database and everything related to the old logic can be removed.
|
2016-08-21 04:51:39 +05:30
|
|
|
*/
|
|
|
|
class MinecraftAccessKey extends ActiveRecord {
|
|
|
|
|
2018-04-18 02:17:25 +05:30
|
|
|
public const LIFETIME = 172800; // Ключ актуален в течение 2 дней
|
2016-08-21 04:51:39 +05:30
|
|
|
|
2017-09-27 22:22:28 +05:30
|
|
|
public static function tableName(): string {
|
2016-08-21 04:51:39 +05:30
|
|
|
return '{{%minecraft_access_keys}}';
|
|
|
|
}
|
|
|
|
|
2017-09-27 22:22:28 +05:30
|
|
|
public function behaviors(): array {
|
2016-08-21 04:51:39 +05:30
|
|
|
return [
|
|
|
|
[
|
|
|
|
'class' => TimestampBehavior::class,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'class' => PrimaryKeyValueBehavior::class,
|
|
|
|
'value' => function() {
|
|
|
|
return Uuid::uuid4()->toString();
|
|
|
|
},
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-06-13 04:25:02 +05:30
|
|
|
public function getAccount(): AccountQuery {
|
|
|
|
/** @noinspection PhpIncompatibleReturnTypeInspection */
|
2016-08-21 04:51:39 +05:30
|
|
|
return $this->hasOne(Account::class, ['id' => 'account_id']);
|
|
|
|
}
|
|
|
|
|
2017-09-27 22:22:28 +05:30
|
|
|
public function isExpired(): bool {
|
2016-09-03 04:24:22 +05:30
|
|
|
return time() > $this->updated_at + self::LIFETIME;
|
2016-08-21 04:51:39 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|