Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldzjap committed Apr 16, 2020
2 parents f95a381 + e56fc7a commit 790f79e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 38 deletions.
6 changes: 2 additions & 4 deletions src/Contracts/SMSToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace MichaelDzjap\TwoFactorAuth\Contracts;

use App\User;

interface SMSToken
{
/**
* Send a user a two-factor authentication token via SMS.
*
* @param \App\User $user
* @param mixed $user
* @return void
*/
public function sendSMSToken(User $user) : void;
public function sendSMSToken($user) : void;
}
18 changes: 8 additions & 10 deletions src/Contracts/TwoFactorProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,38 @@

namespace MichaelDzjap\TwoFactorAuth\Contracts;

use App\User;

interface TwoFactorProvider
{
/**
* Check if two-factor authentication is enabled for a user.
*
* @param \App\User $user
* @param mixed $user
* @return bool
*/
public function enabled(User $user);
public function enabled($user);

/**
* Register a user with this provider.
*
* @param \App\User $user
* @param mixed $user
* @return void
*/
public function register(User $user) : void;
public function register($user) : void;

/**
* Unregister a user with this provider.
*
* @param \App\User $user
* @param mixed $user
* @return bool
*/
public function unregister(User $user);
public function unregister($user);

/**
* Determine if the token is valid.
*
* @param \App\User $user
* @param mixed $user
* @param string $token
* @return bool
*/
public function verify(User $user, string $token);
public function verify($user, string $token);
}
7 changes: 3 additions & 4 deletions src/Events/TwoFactorAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MichaelDzjap\TwoFactorAuth\Events;

use App\User;
use Illuminate\Queue\SerializesModels;

class TwoFactorAuthenticated
Expand All @@ -12,17 +11,17 @@ class TwoFactorAuthenticated
/**
* The user instance.
*
* @var \App\User
* @var mixed
*/
public $user;

/**
* Create a new event instance.
*
* @param \App\User $user
* @param mixed $user
* @return void
*/
public function __construct(User $user)
public function __construct($user)
{
$this->user = $user;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Http/Controllers/TwoFactorAuthenticatesUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MichaelDzjap\TwoFactorAuth\Http\Controllers;

use App\User;
use Illuminate\Foundation\Auth\RedirectsUsers;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
Expand Down Expand Up @@ -76,7 +75,9 @@ public function verifyToken(VerifySMSToken $request)
*/
protected function attemptTwoFactorAuth(Request $request)
{
$user = User::findOrFail($request->session()->get('two-factor:auth')['id']);
$user = config('twofactor-auth.model')::findOrFail(
$request->session()->get('two-factor:auth')['id']
);

if (resolve(TwoFactorProvider::class)->verify($user, $request->input('token'))) {
auth()->login($user); // If SMS code validation passes, login user
Expand Down
6 changes: 2 additions & 4 deletions src/Providers/BaseProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

namespace MichaelDzjap\TwoFactorAuth\Providers;

use App\User;

abstract class BaseProvider
{
/**
* Check if two-factor authentication is enabled.
*
* @param \App\User $user
* @param mixed $user
* @return bool
*/
public function enabled(User $user)
public function enabled($user)
{
$enabled = config('twofactor-auth.enabled', 'user');

Expand Down
17 changes: 8 additions & 9 deletions src/Providers/MessageBirdVerify.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace MichaelDzjap\TwoFactorAuth\Providers;

use Exception;
use App\User;
use MessageBird\Client;
use MessageBird\Exceptions\RequestException;
use MessageBird\Objects\Verify;
Expand Down Expand Up @@ -36,21 +35,21 @@ public function __construct(Client $client)
/**
* Register a user with this provider.
*
* @param \App\User $user
* @param mixed $user
* @return void
*/
public function register(User $user) : void
public function register($user) : void
{
//
}

/**
* Unregister a user with this provider.
*
* @param \App\User $user
* @param mixed $user
* @return bool
*/
public function unregister(User $user)
public function unregister($user)
{
$result = $this->client->verify->delete($user->getTwoFactorAuthId());
$user->setTwoFactorAuthId(null);
Expand All @@ -61,11 +60,11 @@ public function unregister(User $user)
/**
* Determine if the token is valid.
*
* @param \App\User $user
* @param mixed $user
* @param string $token
* @return bool
*/
public function verify(User $user, string $token)
public function verify($user, string $token)
{
// Parse potential MessageBird exceptions. Unfortunately a rather generic
// RequestException is thrown both in the case of an expired token as well as
Expand Down Expand Up @@ -104,11 +103,11 @@ public function verify(User $user, string $token)
/**
* Send a user a two-factor authentication token via SMS.
*
* @param \App\User $user
* @param mixed $user
* @return void
* @throws Exception $exception
*/
public function sendSMSToken(User $user) : void
public function sendSMSToken($user) : void
{
if (!$user->getMobile()) {
throw new Exception("No mobile phone number found for user {$user->id}.");
Expand Down
9 changes: 4 additions & 5 deletions src/Providers/NullProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MichaelDzjap\TwoFactorAuth\Providers;

use App\User;
use MichaelDzjap\TwoFactorAuth\Contracts\SMSToken;
use MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider;

Expand All @@ -11,31 +10,31 @@ class NullProvider extends BaseProvider implements TwoFactorProvider, SMSToken
/**
* {@inheritdoc}
*/
public function register(User $user) : void
public function register($user) : void
{
//
}

/**
* {@inheritdoc}
*/
public function unregister(User $user)
public function unregister($user)
{
//
}

/**
* {@inheritdoc}
*/
public function verify(User $user, string $token)
public function verify($user, string $token)
{
return true;
}

/**
* {@inheritdoc}
*/
public function sendSMSToken(User $user) : void
public function sendSMSToken($user) : void
{
//
}
Expand Down

0 comments on commit 790f79e

Please sign in to comment.