Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit 659cee1

Browse files
committed
Minor modifications to PR#3
1 parent 72042ab commit 659cee1

File tree

6 files changed

+33
-27
lines changed

6 files changed

+33
-27
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1+
/.idea
12
.DS_Store
23
.Thumbs.db
3-
4-
/.idea

src/Providers/BaseProvider.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
abstract class BaseProvider
88
{
99
/**
10-
* Check if two-factor authentication is enabled, dependent on the "enabled" config option.
10+
* Check if two-factor authentication is enabled.
1111
*
1212
* @param \App\User $user
1313
* @return bool
1414
*/
1515
public function enabled(User $user)
1616
{
17-
$conf = config('twofactor-auth.enabled', 'user');
18-
if ($conf === 'user') {
17+
$enabled = config('twofactor-auth.enabled', 'user');
18+
19+
if ($enabled === 'user') {
1920
return !is_null($user->twoFactorAuth);
2021
}
2122

22-
return $conf === 'enabled';
23+
return $enabled === 'always';
2324
}
2425
}

src/TwoFactorAuth.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class TwoFactorAuth extends Model
3939
*/
4040
public function user() : BelongsTo
4141
{
42-
return $this->belongsTo(\App\User::class, 'user_id', config('twofactor-auth.models.user.primaryKey', 'id'));
42+
return $this->belongsTo(
43+
\App\User::class,
44+
'user_id',
45+
config('twofactor-auth.models.user.primaryKey', 'id')
46+
);
4347
}
4448
}

src/TwoFactorAuthServiceProvider.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88

99
class TwoFactorAuthServiceProvider extends ServiceProvider
1010
{
11-
/**
12-
* Indicates if loading of the provider is deferred.
13-
*
14-
* @var bool
15-
*/
16-
protected $defer = false;
17-
1811
/**
1912
* Bootstrap the application services.
2013
*
@@ -74,8 +67,9 @@ protected function publishMigrations()
7467
$paths = [];
7568

7669
foreach ($files as $file) {
77-
$paths[__DIR__ . '/database/migrations/' . $file] = database_path('migrations/'.date('Y_m_d_His').'_'.$file);
70+
$paths[__DIR__.'/database/migrations/'. $file] = database_path('migrations/'.date('Y_m_d_His').'_'.$file);
7871
}
72+
7973
$this->publishes($paths, 'migrations');
8074
}
8175

src/TwoFactorAuthenticable.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@ trait TwoFactorAuthenticable
1515
*/
1616
public function twoFactorAuth() : HasOne
1717
{
18-
return $this->hasOne(TwoFactorAuth::class, 'user_id', $this->getKeyName());
18+
return $this->hasOne(
19+
TwoFactorAuth::class, 'user_id', $this->getKeyName()
20+
);
1921
}
2022

2123
/**
2224
* Set the two-factor auth id.
2325
*
24-
* @param string $id
26+
* @param string $id
2527
* @return void
2628
*/
2729
public function setTwoFactorAuthId(string $id) : void
2830
{
2931
$enabled = config('twofactor-auth.enabled', 'user');
32+
3033
if ($enabled === 'user') {
3134
// respect when 2fa is not set for user, never insert
3235
$this->twoFactorAuth->update(['id' => $id]);
3336
}
3437

35-
if ($enabled === 'enabled') {
38+
if ($enabled === 'always') {
3639
$this->upsertTwoFactorAuthId($id);
3740
}
3841
}
@@ -50,7 +53,7 @@ public function getTwoFactorAuthId() : string
5053
/**
5154
* Create or update a two-factor authentication record with the given id.
5255
*
53-
* @param string $id
56+
* @param string $id
5457
* @return void
5558
*/
5659
private function upsertTwoFactorAuthId(string $id) : void

src/config/twofactor-auth.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
|--------------------------------------------------------------------------
99
|
1010
| Options:
11-
| - 'enabled': always require two-factor authentication
12-
| - 'disabled': disabled, never require two-factor authentication
13-
| - 'user': look if a row exists in the two_factor_auths table for the
14-
| user
11+
|
12+
| - 'always': Always require two-factor authentication.
13+
| - 'never': Never require two-factor authentication.
14+
| - 'user': Specify manually for which users to enable 2fa.
1515
|
1616
*/
1717

@@ -72,26 +72,31 @@
7272
*/
7373

7474
'routes' => [
75+
7576
'get' => [
7677
'url' => '/auth/token',
7778
'name' => 'auth.token',
7879
],
80+
7981
'post' => '/auth/token',
82+
8083
],
8184

8285
/*
8386
|--------------------------------------------------------------------------
84-
| Model setttings
87+
| Model Setttings
8588
|--------------------------------------------------------------------------
8689
|
87-
| \App\User is used, but its primary key can be specified
90+
| Here you can specify some custom properties of the default user model.
8891
|
8992
*/
9093

9194
'models' => [
95+
9296
'user' => [
93-
'primaryKey' => 'id'
94-
]
97+
'primaryKey' => 'id',
98+
],
99+
95100
],
96101

97102
];

0 commit comments

Comments
 (0)