diff --git a/README.md b/README.md index e721099..bc6715b 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ use Lifeonscreen\Google2fa\Models\User2fa; */ public function user2fa(): HasOne { - return $this->hasOne(User2fa::class); + return $this->hasOne(User2fa::class); // You may pass the foreign and local key } ``` @@ -152,4 +152,4 @@ MIT license. Please see the [license file](docs/license.md) for more information [link-packagist]: https://packagist.org/packages/lifeonscreen/nova-google2fa [link-downloads]: https://packagist.org/packages/lifeonscreen/nova-google2fa -[link-author]: https://github.com/LifeOnScreen \ No newline at end of file +[link-author]: https://github.com/LifeOnScreen diff --git a/composer.json b/composer.json index 6fca6f0..44230fd 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "require": { "php": ">=7.1.0", "bacon/bacon-qr-code": "^2.0", - "pragmarx/recovery": "^0.1.0", + "pragmarx/recovery": "^0.2.1", "pragmarx/google2fa-laravel": "^0.2.0" }, "autoload": { diff --git a/config/lifeonscreen2fa.php b/config/lifeonscreen2fa.php index d40dd13..67f2fba 100644 --- a/config/lifeonscreen2fa.php +++ b/config/lifeonscreen2fa.php @@ -24,6 +24,10 @@ * Table in which users are stored. */ 'user' => 'users', + /** + * Foreign column of model + */ + 'foreign' => 'user_id', ], 'recovery_codes' => [ @@ -50,4 +54,4 @@ */ 'hashing_algorithm' => PASSWORD_BCRYPT, ], -]; \ No newline at end of file +]; diff --git a/database/migrations/2018_10_15_095425_create_user_2fa_table.php b/database/migrations/2018_10_15_095425_create_user_2fa_table.php index ac17d5f..93845ce 100644 --- a/database/migrations/2018_10_15_095425_create_user_2fa_table.php +++ b/database/migrations/2018_10_15_095425_create_user_2fa_table.php @@ -15,13 +15,13 @@ public function up() { Schema::create('user_2fa', function (Blueprint $table) { $table->increments('id'); - $table->unsignedInteger('user_id'); + $table->unsignedInteger(config('lifeonscreen2fa.tables.foreign')); $table->boolean('google2fa_enable')->default(false); $table->string('google2fa_secret')->nullable(); $table->text('recovery')->nullable(); $table->timestamps(); - $table->foreign('user_id') + $table->foreign(config('lifeonscreen2fa.tables.foreign')) ->references('id') ->on(config('lifeonscreen2fa.tables.user')); }); @@ -36,4 +36,4 @@ public function down() { Schema::dropIfExists('user_2fa'); } -} \ No newline at end of file +} diff --git a/src/Google2fa.php b/src/Google2fa.php index f2b6ba2..029be1d 100644 --- a/src/Google2fa.php +++ b/src/Google2fa.php @@ -106,9 +106,9 @@ public function authenticate() $user2faModel = config('lifeonscreen2fa.models.user2fa'); - $user2faModel::where('user_id', auth()->user()->id)->delete(); + $user2faModel::where(config('lifeonscreen2fa.tables.foreign'), auth()->user()->id)->delete(); $user2fa = new $user2faModel(); - $user2fa->user_id = auth()->user()->id; + $user2fa->{config('lifeonscreen2fa.tables.foreign')} = auth()->user()->id; $user2fa->google2fa_secret = $secretKey; $user2fa->recovery = json_encode($recoveryHashes); $user2fa->save(); diff --git a/src/Http/Middleware/Google2fa.php b/src/Http/Middleware/Google2fa.php index 605f42a..f30b17c 100644 --- a/src/Http/Middleware/Google2fa.php +++ b/src/Http/Middleware/Google2fa.php @@ -46,10 +46,10 @@ public function handle($request, Closure $next) ->toArray(); $user2faModel = config('lifeonscreen2fa.models.user2fa'); - $user2faModel::where('user_id', auth()->user()->id)->delete(); + $user2faModel::where(config('lifeonscreen2fa.tables.foreign'), auth()->user()->id)->delete(); $user2fa = new $user2faModel(); - $user2fa->user_id = auth()->user()->id; + $user2fa->{config('lifeonscreen2fa.tables.foreign')} = auth()->user()->id; $user2fa->google2fa_secret = $secretKey; $user2fa->recovery = json_encode($data['recovery']); $user2fa->save(); @@ -59,4 +59,4 @@ public function handle($request, Closure $next) return response(view('google2fa::authenticate')); } -} \ No newline at end of file +} diff --git a/src/Models/User2fa.php b/src/Models/User2fa.php index 4cb310c..daeed06 100644 --- a/src/Models/User2fa.php +++ b/src/Models/User2fa.php @@ -21,6 +21,6 @@ class User2fa extends Model */ public function user(): BelongsTo { - return $this->belongsTo(config('lifeonscreen2fa.models.user')); + return $this->belongsTo(config('lifeonscreen2fa.models.user'),config('lifeonscreen2fa.tables.foreign')); } -} \ No newline at end of file +}