From 281aef71a053aeed9b7380064bae2c1951ea91d7 Mon Sep 17 00:00:00 2001 From: Jani Cerar <29040621+janicerar@users.noreply.github.com> Date: Fri, 16 Nov 2018 14:41:13 +0100 Subject: [PATCH] Added support for custom User2fa class --- README.md | 5 +++++ config/lifeonscreen2fa.php | 15 +++++++++++---- src/Google2fa.php | 6 +++--- src/Http/Middleware/Google2fa.php | 6 +++--- src/Models/User2fa.php | 6 ++---- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 357d35d..e721099 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,11 @@ return [ * Change this variable to path to user model. */ 'user' => 'App\User', + + /** + * Change this if you need a custom connector + */ + 'user2fa' => User2fa::class, ], 'tables' => [ /** diff --git a/config/lifeonscreen2fa.php b/config/lifeonscreen2fa.php index 4de5719..d40dd13 100644 --- a/config/lifeonscreen2fa.php +++ b/config/lifeonscreen2fa.php @@ -1,5 +1,7 @@ 'App\User', + 'user' => 'App\User', + + /** + * Change this if you need a custom connector + */ + 'user2fa' => User2fa::class, ], 'tables' => [ /** @@ -23,17 +30,17 @@ /** * Number of recovery codes that will be generated. */ - 'count' => 8, + 'count' => 8, /** * Number of blocks in each recovery code. */ - 'blocks' => 3, + 'blocks' => 3, /** * Number of characters in each block in recovery code. */ - 'chars_in_block' => 16, + 'chars_in_block' => 16, /** * The following algorithms are currently supported: diff --git a/src/Google2fa.php b/src/Google2fa.php index 909ac46..bdad258 100644 --- a/src/Google2fa.php +++ b/src/Google2fa.php @@ -3,7 +3,6 @@ namespace Lifeonscreen\Google2fa; use Laravel\Nova\Tool; -use Lifeonscreen\Google2fa\Models\User2fa; use PragmaRX\Google2FA\Google2FA as G2fa; use PragmaRX\Recovery\Recovery; use Request; @@ -123,9 +122,10 @@ public function authenticate() $value = password_hash($value, config('lifeonscreen2fa.recovery_codes.hashing_algorithm')); }); - User2fa::where('user_id', auth()->user()->id)->delete(); + $user2faModel = config('lifeonscreen2fa.models.user2fa'); - $user2fa = new User2fa(); + $user2faModel::where('user_id', auth()->user()->id)->delete(); + $user2fa = new $user2faModel(); $user2fa->user_id = auth()->user()->id; $user2fa->google2fa_secret = $secretKey; $user2fa->recovery = json_encode($recoveryHashes); diff --git a/src/Http/Middleware/Google2fa.php b/src/Http/Middleware/Google2fa.php index a44a9f9..605f42a 100644 --- a/src/Http/Middleware/Google2fa.php +++ b/src/Http/Middleware/Google2fa.php @@ -4,7 +4,6 @@ use Closure; use Lifeonscreen\Google2fa\Google2FAAuthenticator; -use Lifeonscreen\Google2fa\Models\User2fa; use PragmaRX\Google2FA\Google2FA as G2fa; use PragmaRX\Recovery\Recovery; @@ -46,9 +45,10 @@ public function handle($request, Closure $next) ->setChars(config('lifeonscreen2fa.recovery_codes.chars_in_block')) ->toArray(); - User2fa::where('user_id', auth()->user()->id)->delete(); + $user2faModel = config('lifeonscreen2fa.models.user2fa'); + $user2faModel::where('user_id', auth()->user()->id)->delete(); - $user2fa = new User2fa(); + $user2fa = new $user2faModel(); $user2fa->user_id = auth()->user()->id; $user2fa->google2fa_secret = $secretKey; $user2fa->recovery = json_encode($data['recovery']); diff --git a/src/Models/User2fa.php b/src/Models/User2fa.php index 0d2fb67..4cb310c 100644 --- a/src/Models/User2fa.php +++ b/src/Models/User2fa.php @@ -6,8 +6,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; /** - * Class PasswordSecurity - * @package App\GraphQL\Models\User + * Class User2fa + * @package Lifeonscreen\Google2fa\Models */ class User2fa extends Model { @@ -16,8 +16,6 @@ class User2fa extends Model */ protected $table = 'user_2fa'; - protected $guarded = []; - /** * @return BelongsTo */