Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down Expand Up @@ -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
[link-author]: https://github.com/LifeOnScreen
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 5 additions & 1 deletion config/lifeonscreen2fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
* Table in which users are stored.
*/
'user' => 'users',
/**
* Foreign column of model
*/
'foreign' => 'user_id',
],

'recovery_codes' => [
Expand All @@ -50,4 +54,4 @@
*/
'hashing_algorithm' => PASSWORD_BCRYPT,
],
];
];
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
Expand All @@ -36,4 +36,4 @@ public function down()
{
Schema::dropIfExists('user_2fa');
}
}
}
4 changes: 2 additions & 2 deletions src/Google2fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Middleware/Google2fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -59,4 +59,4 @@ public function handle($request, Closure $next)

return response(view('google2fa::authenticate'));
}
}
}
4 changes: 2 additions & 2 deletions src/Models/User2fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}
}