Skip to content

Commit a702f54

Browse files
committed
refactore: get rid of Authenticatable/UserProvider, use User/UserModel
1 parent ecd95a9 commit a702f54

File tree

9 files changed

+22
-33
lines changed

9 files changed

+22
-33
lines changed

src/Auth.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
use CodeIgniter\Shield\Authentication\AuthenticationException;
88
use CodeIgniter\Shield\Authentication\AuthenticatorInterface;
99
use CodeIgniter\Shield\Entities\User;
10-
use CodeIgniter\Shield\Interfaces\Authenticatable;
11-
use CodeIgniter\Shield\Interfaces\UserProvider;
10+
use CodeIgniter\Shield\Models\UserModel;
1211

1312
/**
1413
* AuthenticatorInterface:
@@ -34,8 +33,8 @@ class Auth
3433
*/
3534
protected ?string $alias = null;
3635

37-
protected ?Authenticatable $user = null;
38-
protected ?UserProvider $userProvider = null;
36+
protected ?User $user = null;
37+
protected ?UserModel $userProvider = null;
3938

4039
public function __construct(Authentication $authenticate)
4140
{
@@ -131,7 +130,7 @@ public function routes(RouteCollection &$routes, array $config = []): void
131130
*
132131
* @throws AuthenticationException
133132
*/
134-
public function getProvider(): UserProvider
133+
public function getProvider(): UserModel
135134
{
136135
if ($this->userProvider !== null) {
137136
return $this->userProvider;

src/Authentication/Authentication.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace CodeIgniter\Shield\Authentication;
44

55
use CodeIgniter\Shield\Config\Auth as AuthConfig;
6-
use CodeIgniter\Shield\Interfaces\UserProvider;
6+
use CodeIgniter\Shield\Models\UserModel;
77

88
class Authentication
99
{
@@ -15,7 +15,7 @@ class Authentication
1515
*/
1616
protected array $instances = [];
1717

18-
protected ?UserProvider $userProvider = null;
18+
protected ?UserModel $userProvider = null;
1919
protected AuthConfig $config;
2020

2121
public function __construct(AuthConfig $config)
@@ -63,7 +63,7 @@ public function factory(?string $alias = null): AuthenticatorInterface
6363
*
6464
* @return $this
6565
*/
66-
public function setProvider(UserProvider $provider): self
66+
public function setProvider(UserModel $provider): self
6767
{
6868
$this->userProvider = $provider;
6969

src/Authentication/Authenticators/AccessTokens.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use CodeIgniter\Shield\Authentication\AuthenticationException;
88
use CodeIgniter\Shield\Authentication\AuthenticatorInterface;
99
use CodeIgniter\Shield\Entities\User;
10-
use CodeIgniter\Shield\Interfaces\UserProvider;
1110
use CodeIgniter\Shield\Models\LoginModel;
1211
use CodeIgniter\Shield\Models\UserIdentityModel;
12+
use CodeIgniter\Shield\Models\UserModel;
1313
use CodeIgniter\Shield\Result;
1414
use InvalidArgumentException;
1515

@@ -18,20 +18,12 @@ class AccessTokens implements AuthenticatorInterface
1818
/**
1919
* The persistence engine
2020
*/
21-
protected UserProvider $provider;
21+
protected UserModel $provider;
2222

23-
/**
24-
* AccessTokens requires HasAccessTokens trait but there is no interface
25-
* for this so the workaround is restricting this class to work with
26-
* the native User instead of Authenticatable
27-
*
28-
* @todo Fix interface issue described above
29-
*/
3023
protected ?User $user = null;
31-
3224
protected LoginModel $loginModel;
3325

34-
public function __construct(UserProvider $provider)
26+
public function __construct(UserModel $provider)
3527
{
3628
helper('session');
3729
$this->provider = $provider;

src/Authentication/Authenticators/Session.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
use CodeIgniter\Shield\Authentication\AuthenticatorInterface;
1111
use CodeIgniter\Shield\Authentication\Passwords;
1212
use CodeIgniter\Shield\Entities\User;
13-
use CodeIgniter\Shield\Interfaces\Authenticatable;
14-
use CodeIgniter\Shield\Interfaces\UserProvider;
1513
use CodeIgniter\Shield\Models\LoginModel;
1614
use CodeIgniter\Shield\Models\RememberModel;
15+
use CodeIgniter\Shield\Models\UserModel;
1716
use CodeIgniter\Shield\Result;
1817
use Exception;
1918
use InvalidArgumentException;
@@ -23,7 +22,7 @@ class Session implements AuthenticatorInterface
2322
/**
2423
* The persistence engine
2524
*/
26-
protected UserProvider $provider;
25+
protected UserModel $provider;
2726

2827
protected ?User $user = null;
2928
protected LoginModel $loginModel;
@@ -35,7 +34,7 @@ class Session implements AuthenticatorInterface
3534

3635
protected RememberModel $rememberModel;
3736

38-
public function __construct(UserProvider $provider)
37+
public function __construct(UserModel $provider)
3938
{
4039
helper('setting');
4140
$this->provider = $provider;
@@ -151,7 +150,7 @@ public function check(array $credentials): Result
151150
*/
152151
public function loggedIn(): bool
153152
{
154-
if ($this->user instanceof Authenticatable) {
153+
if ($this->user instanceof User) {
155154
return true;
156155
}
157156

@@ -161,7 +160,7 @@ public function loggedIn(): bool
161160
if ($userId !== null) {
162161
$this->user = $this->provider->findById($userId);
163162

164-
return $this->user instanceof Authenticatable;
163+
return $this->user instanceof User;
165164
}
166165

167166
return false;

src/Authentication/Traits/Authenticatable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace CodeIgniter\Shield\Authentication\Traits;
44

55
/**
6-
* Intended to be used with Authenticatable (User).
6+
* Intended to be used with User.
77
*/
88
trait Authenticatable
99
{

src/Config/Auth.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ class Auth extends BaseConfig
333333
* By default, this is the included UserModel, which
334334
* works with any of the database engines supported by CodeIgniter.
335335
* You can change it as long as they adhere to the
336-
* CodeIgniter\Shield\Interfaces\UserProvider.
336+
* CodeIgniter\Shield\Models\UserModel.
337337
*
338-
* @var class-string<\CodeIgniter\Shield\Interfaces\UserProvider>
338+
* @var class-string<\CodeIgniter\Shield\Models\UserModel>
339339
*/
340340
public string $userProvider = 'CodeIgniter\Shield\Models\UserModel';
341341

src/Controllers/MagicLinkController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use CodeIgniter\HTTP\RedirectResponse;
77
use CodeIgniter\I18n\Time;
88
use CodeIgniter\Shield\Auth;
9-
use CodeIgniter\Shield\Interfaces\UserProvider;
109
use CodeIgniter\Shield\Models\UserIdentityModel;
10+
use CodeIgniter\Shield\Models\UserModel;
1111

1212
/**
1313
* Handles "Magic Link" logins - an email-based
@@ -20,7 +20,7 @@
2020
class MagicLinkController extends BaseController
2121
{
2222
/**
23-
* @var UserProvider
23+
* @var UserModel
2424
*/
2525
protected $provider;
2626

src/Entities/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use CodeIgniter\Shield\Models\LoginModel;
1111
use CodeIgniter\Shield\Models\UserIdentityModel;
1212

13-
class User extends Entity implements \CodeIgniter\Shield\Interfaces\Authenticatable
13+
class User extends Entity
1414
{
1515
use Authenticatable;
1616
use Authorizable;

src/Models/UserModel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
use CodeIgniter\Model;
66
use CodeIgniter\Shield\Authentication\Traits\UserProvider as UserProviderTrait;
77
use CodeIgniter\Shield\Entities\User;
8-
use CodeIgniter\Shield\Interfaces\UserProvider;
98
use Faker\Generator;
109
use InvalidArgumentException;
1110

12-
class UserModel extends Model implements UserProvider
11+
class UserModel extends Model
1312
{
1413
use UserProviderTrait;
1514

0 commit comments

Comments
 (0)