From a4487513cc9c0c0726f4630ce915149ff7631cf1 Mon Sep 17 00:00:00 2001 From: Roel van Hintum Date: Tue, 13 Feb 2024 21:27:59 +0100 Subject: [PATCH] fix: Missing usertoken table on fresh install --- CHANGELOG.md | 4 ++++ src/migrations/Install.php | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31b7b35..bc80d46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ================== +## 3.3.5 - 2024-02-13 +### Fixed +- fix: Missing usertoken table on fresh install + ## 3.3.4 - 2024-02-08 ### Fixed - fix: Exposure of Sensitive Attributes diff --git a/src/migrations/Install.php b/src/migrations/Install.php index f157028..90ee688 100644 --- a/src/migrations/Install.php +++ b/src/migrations/Install.php @@ -3,6 +3,7 @@ use craft\db\Migration; use born05\twofactorauthentication\records\User; +use born05\twofactorauthentication\records\UserToken; class Install extends Migration { @@ -23,8 +24,19 @@ public function safeUp() ]); $this->createIndex(null, User::tableName(), ['userId'], true); - $this->addForeignKey(null, User::tableName(), ['userId'], '{{%users}}', ['id'], 'CASCADE', null); + + $this->createTable(UserToken::tableName(), [ + 'id' => $this->primaryKey(), + 'userId' => $this->integer()->notNull(), + 'token' => $this->string(100)->notNull(), + 'dateCreated' => $this->dateTime()->notNull(), + 'dateUpdated' => $this->dateTime()->notNull(), + 'uid' => $this->uid(), + ]); + + $this->createIndex(null, UserToken::tableName(), ['userId', 'dateCreated'], false); + $this->createIndex(null, UserToken::tableName(), ['userId', 'token', 'dateCreated'], true); } protected function upgradeFromCraft2() @@ -46,6 +58,7 @@ public function safeDown() { $this->dropTableIfExists('{{%twofactorauthentication_session}}'); $this->dropTableIfExists(User::tableName()); + $this->dropTableIfExists(UserToken::tableName()); return true; }