-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1285 from proditis/master
tokens and api work
- Loading branch information
Showing
69 changed files
with
2,983 additions
and
833 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
backend/migrations-init/m241103_021658_target_api_url_routes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Class m241103_021658_target_api_url_routes | ||
*/ | ||
class m241103_021658_target_api_url_routes extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->upsert('url_route',['source'=>'profile/generate-token','destination'=>'profile/generate-token','weight'=>339]); | ||
//$this->upsert('url_route',['source'=>'api/targets','destination'=>'api/target/index','weight'=>642]); | ||
$this->upsert('url_route',['source'=>'api/target/claim','destination'=>'api/target/claim','weight'=>643]); | ||
$this->upsert('url_route',['source'=>'api/target/instances','destination'=>'api/target/instances','weight'=>643]); | ||
$this->upsert('url_route',['source'=>'api/target/<id:\d+>','destination'=>'api/target/view','weight'=>644]); | ||
$this->upsert('url_route',['source'=>'api/target/<id:\d+>/spin','destination'=>'api/target/spin','weight'=>645]); | ||
$this->upsert('url_route',['source'=>'api/target/<id:\d+>/spawn','destination'=>'api/target/spawn','weight'=>646]); | ||
$this->upsert('url_route',['source'=>'api/target/<id:\d+>/shut','destination'=>'api/target/shut','weight'=>647]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
echo "m241103_021658_target_api_url_routes cannot be reverted.\n"; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
backend/migrations-init/m241104_211706_add_default_token_validities.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Class m241104_211706_add_default_token_validities | ||
*/ | ||
class m241104_211706_add_default_token_validities extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->upsert('sysconfig',['id'=>'password_reset_token_validity','val'=>'24 hour'],true); | ||
$this->upsert('sysconfig',['id'=>'mail_verification_token_validity','val'=>'10 day'],true); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
echo "m241104_211706_add_default_token_validities cannot be reverted.\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
backend/migrations/m241103_000427_create_player_token_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Handles the creation of table `{{%player_token}}`. | ||
*/ | ||
class m241103_000427_create_player_token_table extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->createTable('{{%player_token}}', [ | ||
'player_id' => $this->integer()->unsigned()->notNull(), | ||
'type' => $this->string(32)->notNull()->defaultValue('API'), | ||
'token' => $this->string(128)->notNull()->unique(), | ||
'description' => $this->text()->notNull()->defaultValue(""), | ||
'expires_at' => $this->dateTime(), | ||
'created_at' => $this->timestamp(), | ||
]); | ||
$this->addPrimaryKey('player_token-pk', 'player_token', ['player_id', 'type']); | ||
$this->addForeignKey('fk-player_token-player_id-player', '{{%player_token}}', 'player_id', 'player', 'id', 'CASCADE', 'CASCADE'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
$this->dropTable('{{%player_token}}'); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
backend/migrations/m241103_105725_create_player_token_history_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Handles the creation of table `{{%player_token_history}}`. | ||
*/ | ||
class m241103_105725_create_player_token_history_table extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->createTable('{{%player_token_history}}', [ | ||
'id'=>$this->primaryKey(), | ||
'player_id' => $this->integer()->unsigned()->notNull(), | ||
'type' => $this->string(32)->notNull()->defaultValue('API'), | ||
'token' => $this->string(128)->notNull(), | ||
'description' => $this->text()->notNull()->defaultValue(''), | ||
'expires_at' => $this->dateTime(), | ||
'created_at' => $this->timestamp(), | ||
'ts' => $this->timestamp(), | ||
]); | ||
$this->addForeignKey('fk-player_token_history-player_id-player', '{{%player_token_history}}', 'player_id', 'player', 'id', 'CASCADE', 'CASCADE'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
$this->dropTable('{{%player_token}}'); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
backend/migrations/m241103_105924_create_tai_player_token_trigger.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Class m241103_105924_create_tai_player_token_trigger | ||
*/ | ||
class m241103_105924_create_tai_player_token_trigger extends Migration | ||
{ | ||
public $DROP_SQL="DROP TRIGGER IF EXISTS {{%tai_player_token}}"; | ||
public $CREATE_SQL="CREATE TRIGGER {{%tai_player_token}} AFTER INSERT ON {{%player_token}} FOR EACH ROW | ||
thisBegin:BEGIN | ||
IF (@TRIGGER_CHECKS = FALSE) THEN | ||
LEAVE thisBegin; | ||
END IF; | ||
INSERT INTO player_token_history (player_id,`type`,token,`description`,expires_at,created_at,ts) VALUES (NEW.player_id,NEW.type,NEW.token,NEW.description,NEW.expires_at,NEW.created_at,NOW()); | ||
END"; | ||
|
||
public function up() | ||
{ | ||
$this->db->createCommand($this->DROP_SQL)->execute(); | ||
$this->db->createCommand($this->CREATE_SQL)->execute(); | ||
} | ||
|
||
public function down() | ||
{ | ||
$this->db->createCommand($this->DROP_SQL)->execute(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
backend/migrations/m241103_105954_create_tau_player_token_trigger.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Class m241103_105954_create_tau_player_token_trigger | ||
*/ | ||
class m241103_105954_create_tau_player_token_trigger extends Migration | ||
{ | ||
public $DROP_SQL="DROP TRIGGER IF EXISTS {{%tau_player_token}}"; | ||
public $CREATE_SQL="CREATE TRIGGER {{%tau_player_token}} AFTER UPDATE ON {{%player_token}} FOR EACH ROW | ||
thisBegin:BEGIN | ||
IF (@TRIGGER_CHECKS = FALSE) THEN | ||
LEAVE thisBegin; | ||
END IF; | ||
IF (NEW.token != OLD.token) THEN | ||
INSERT INTO player_token_history (player_id,`type`,token,description,expires_at,created_at,ts) VALUES (NEW.player_id,NEW.type,NEW.token,NEW.description,NEW.expires_at,NEW.created_at,NOW()); | ||
END IF; | ||
END"; | ||
|
||
public function up() | ||
{ | ||
$this->db->createCommand($this->DROP_SQL)->execute(); | ||
$this->db->createCommand($this->CREATE_SQL)->execute(); | ||
} | ||
|
||
public function down() | ||
{ | ||
$this->db->createCommand($this->DROP_SQL)->execute(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
backend/migrations/m241103_110652_create_tad_player_token_trigger.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Class m241103_110652_create_tad_player_token_trigger | ||
*/ | ||
class m241103_110652_create_tad_player_token_trigger extends Migration | ||
{ | ||
public $DROP_SQL="DROP TRIGGER IF EXISTS {{%tad_player_token}}"; | ||
public $CREATE_SQL="CREATE TRIGGER {{%tad_player_token}} AFTER DELETE ON {{%player_token}} FOR EACH ROW | ||
thisBegin:BEGIN | ||
IF (@TRIGGER_CHECKS = FALSE) THEN | ||
LEAVE thisBegin; | ||
END IF; | ||
INSERT INTO player_token_history (player_id,`type`,token,description,expires_at,created_at,ts) VALUES (OLD.player_id,OLD.type,OLD.token,OLD.description,OLD.expires_at,OLD.created_at,NOW()); | ||
END"; | ||
|
||
public function up() | ||
{ | ||
$this->db->createCommand($this->DROP_SQL)->execute(); | ||
$this->db->createCommand($this->CREATE_SQL)->execute(); | ||
} | ||
|
||
public function down() | ||
{ | ||
$this->db->createCommand($this->DROP_SQL)->execute(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
backend/migrations/m241103_121625_create_expire_player_tokens_procedure.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Class m241103_121625_create_expire_player_tokens_procedure | ||
*/ | ||
class m241103_121625_create_expire_player_tokens_procedure extends Migration | ||
{ | ||
public $DROP_SQL = "DROP PROCEDURE IF EXISTS {{%expire_player_tokens}}"; | ||
public $CREATE_SQL = "CREATE PROCEDURE {{%expire_player_tokens}} () | ||
BEGIN | ||
DECLARE tnow TIMESTAMP; | ||
SET tnow=NOW(); | ||
IF (SELECT COUNT(*) FROM player_token WHERE expires_at<tnow and `type`='API')>0 THEN | ||
START TRANSACTION; | ||
INSERT INTO notification (player_id,category,title,body,archived,created_at,updated_at) SELECT player_id,'info','Token expiration',CONCAT(type,' Token [',description,'] expired at ',expires_at),0,tnow,tnow FROM player_token WHERE expires_at<tnow and `type`='API'; | ||
DELETE FROM player_token WHERE expires_at<tnow and `type`='API'; | ||
COMMIT; | ||
END IF; | ||
IF (SELECT COUNT(*) FROM player_token WHERE expires_at<tnow)>0 THEN | ||
DELETE FROM player_token WHERE expires_at<tnow; | ||
END IF; | ||
END"; | ||
|
||
public function up() | ||
{ | ||
$this->db->createCommand($this->DROP_SQL)->execute(); | ||
$this->db->createCommand($this->CREATE_SQL)->execute(); | ||
} | ||
|
||
public function down() | ||
{ | ||
$this->db->createCommand($this->DROP_SQL)->execute(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/migrations/m241103_121633_create_ev_player_token_expiration_event.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Class m241103_121633_create_ev_player_token_expiration_event | ||
*/ | ||
class m241103_121633_create_ev_player_token_expiration_event extends Migration | ||
{ | ||
public $DROP_SQL = "DROP EVENT IF EXISTS {{%ev_player_token_expiration}}"; | ||
public $CREATE_SQL = "CREATE EVENT {{%ev_player_token_expiration}} ON SCHEDULE EVERY 10 SECOND ON COMPLETION PRESERVE ENABLE DO | ||
BEGIN | ||
ALTER EVENT {{%ev_player_token_expiration}} DISABLE; | ||
call expire_player_tokens(); | ||
ALTER EVENT {{%ev_player_token_expiration}} ENABLE; | ||
END"; | ||
|
||
public function up() | ||
{ | ||
$this->db->createCommand($this->DROP_SQL)->execute(); | ||
$this->db->createCommand($this->CREATE_SQL)->execute(); | ||
} | ||
|
||
public function down() | ||
{ | ||
$this->db->createCommand($this->DROP_SQL)->execute(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
backend/migrations/m241104_201004_drop_token_columns_from_player_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Handles dropping columns from table `{{%player}}`. | ||
*/ | ||
class m241104_201004_drop_token_columns_from_player_table extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->db->createCommand("INSERT INTO player_token (player_id,type,token,expires_at,created_at) SELECT id,'password_reset',substr(password_reset_token,1,30),now()+ INTERVAL 24 HOUR,now() FROM player WHERE password_reset_token is not null and password_reset_token!=''")->execute(); | ||
$this->db->createCommand("INSERT INTO player_token (player_id,type,token,expires_at,created_at) SELECT id,'email_verification',substr(verification_token,1,30),now()+ INTERVAL 24 HOUR,now() FROM player WHERE verification_token is not null and verification_token!=''")->execute(); | ||
$this->dropColumn('player', 'password_reset_token'); | ||
$this->dropColumn('player', 'verification_token'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
$this->addColumn('player', 'password_reset_token', $this->string()); | ||
$this->addColumn('player', 'verification_token', $this->string()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
backend/migrations/m241104_231037_drop_tbu_player_trigger.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Class m241104_231037_drop_tbu_player_trigger | ||
*/ | ||
class m241104_231037_drop_tbu_player_trigger extends Migration | ||
{ | ||
public $DROP_SQL = "DROP TRIGGER IF EXISTS {{%tbu_player}}"; | ||
|
||
public function up() | ||
{ | ||
$this->db->createCommand($this->DROP_SQL)->execute(); | ||
} | ||
|
||
public function down() | ||
{ | ||
echo "Nothing to reverse..."; | ||
} | ||
} |
Oops, something went wrong.