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

Commit 10ad276

Browse files
committed
Add a base provider
1 parent 4e6150b commit 10ad276

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

src/Providers/BaseProvider.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace MichaelDzjap\TwoFactorAuth\Providers;
4+
5+
abstract class BaseProvider
6+
{
7+
/**
8+
* Check if two-factor authentication is enabled for a user.
9+
*
10+
* @param User $user
11+
* @return bool
12+
*/
13+
public function enabled(User $user)
14+
{
15+
return !is_null($user->twoFactorAuth);
16+
}
17+
}

src/Providers/MessageBirdVerify.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use MichaelDzjap\TwoFactorAuth\Exceptions\TokenExpiredException;
1414
use MichaelDzjap\TwoFactorAuth\Exceptions\TokenInvalidException;
1515

16-
class MessageBirdVerify implements TwoFactorProvider, SMSToken
16+
class MessageBirdVerify extends BaseProvider implements TwoFactorProvider, SMSToken
1717
{
1818
/**
1919
* MessageBird client instance.
@@ -33,17 +33,6 @@ public function __construct(Client $client)
3333
$this->client = $client;
3434
}
3535

36-
/**
37-
* Check if two-factor authentication is enabled for a user.
38-
*
39-
* @param User $user
40-
* @return bool
41-
*/
42-
public function enabled(User $user)
43-
{
44-
return $user->twoFactorAuth;
45-
}
46-
4736
/**
4837
* Register a user with this provider.
4938
*

src/Providers/NullProvider.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,8 @@
66
use MichaelDzjap\TwoFactorAuth\Contracts\SMSToken;
77
use MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider;
88

9-
class NullProvider implements TwoFactorProvider, SMSToken
9+
class NullProvider extends BaseProvider implements TwoFactorProvider, SMSToken
1010
{
11-
/**
12-
* {@inheritdoc}
13-
*/
14-
public function enabled(User $user)
15-
{
16-
return $user->twoFactorAuth;
17-
}
18-
1911
/**
2012
* {@inheritdoc}
2113
*/

0 commit comments

Comments
 (0)