Skip to content

Commit

Permalink
Merge pull request #10 from LifeOnScreen/development
Browse files Browse the repository at this point in the history
Added support for custom User2fa class
  • Loading branch information
janicerar authored Nov 28, 2018
2 parents b3c9e83 + 281aef7 commit 16728e1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
/**
Expand Down
15 changes: 11 additions & 4 deletions config/lifeonscreen2fa.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Lifeonscreen\Google2fa\Models\User2fa;

return [
/**
* Disable or enable middleware.
Expand All @@ -10,7 +12,12 @@
/**
* Change this variable to path to user model.
*/
'user' => 'App\User',
'user' => 'App\User',

/**
* Change this if you need a custom connector
*/
'user2fa' => User2fa::class,
],
'tables' => [
/**
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/Google2fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
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 @@ -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;

Expand Down Expand Up @@ -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']);
Expand Down
6 changes: 2 additions & 4 deletions src/Models/User2fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -16,8 +16,6 @@ class User2fa extends Model
*/
protected $table = 'user_2fa';

protected $guarded = [];

/**
* @return BelongsTo
*/
Expand Down

0 comments on commit 16728e1

Please sign in to comment.