Skip to content

Commit dcd3b93

Browse files
committed
Fix LoginStatus enum
1 parent 9d98e44 commit dcd3b93

4 files changed

Lines changed: 55 additions & 40 deletions

File tree

src/mako/gatekeeper/LoginStatus.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,31 @@
77

88
namespace mako\gatekeeper;
99

10+
use Deprecated;
11+
1012
/**
1113
* Login status codes.
1214
*/
1315
enum LoginStatus: int
1416
{
15-
case OK = 1;
16-
case BANNED = 2;
17-
case NOT_ACTIVATED = 3;
18-
case INVALID_CREDENTIALS = 4;
19-
case LOCKED = 5;
17+
/* Start compatibility */
18+
#[Deprecated('use LoginStatus::Ok instead', 'Mako 12.2.0')]
19+
public const OK = self::Ok;
20+
#[Deprecated('use LoginStatus::Banned instead', 'Mako 12.2.0')]
21+
public const BANNED = self::Banned;
22+
#[Deprecated('use LoginStatus::NotActivated instead', 'Mako 12.2.0')]
23+
public const NOT_ACTIVATED = self::NotActivated;
24+
#[Deprecated('use LoginStatus::InvalidCredentials instead', 'Mako 12.2.0')]
25+
public const INVALID_CREDENTIALS = self::InvalidCredentials;
26+
#[Deprecated('use LoginStatus::Locked instead', 'Mako 12.2.0')]
27+
public const LOCKED = self::Locked;
28+
/* End compatibility */
29+
30+
case Ok = 1;
31+
case Banned = 2;
32+
case NotActivated = 3;
33+
case InvalidCredentials = 4;
34+
case Locked = 5;
2035

2136
/**
2237
* Returns the status code.
@@ -27,10 +42,10 @@ public function getCode(): int
2742
}
2843

2944
/**
30-
* Returns TRUE if OK and FALSE otherwise.
45+
* Returns TRUE if Ok and FALSE otherwise.
3146
*/
3247
public function toBool(): bool
3348
{
34-
return $this === self::OK;
49+
return $this === self::Ok;
3550
}
3651
}

src/mako/gatekeeper/adapters/Session.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,16 @@ protected function authenticate(int|string $identifier, #[SensitiveParameter] ?s
136136

137137
if ($user !== null) {
138138
if ($this->options['throttling']['enabled'] && $user->isLocked()) {
139-
return LoginStatus::LOCKED;
139+
return LoginStatus::Locked;
140140
}
141141

142142
if ($force || $user->validatePassword($password)) {
143143
if (!$user->isActivated()) {
144-
return LoginStatus::NOT_ACTIVATED;
144+
return LoginStatus::NotActivated;
145145
}
146146

147147
if ($user->isBanned()) {
148-
return LoginStatus::BANNED;
148+
return LoginStatus::Banned;
149149
}
150150

151151
if ($this->options['throttling']['enabled']) {
@@ -154,7 +154,7 @@ protected function authenticate(int|string $identifier, #[SensitiveParameter] ?s
154154

155155
$this->user = $user;
156156

157-
return LoginStatus::OK;
157+
return LoginStatus::Ok;
158158
}
159159
else {
160160
if ($this->options['throttling']['enabled']) {
@@ -163,7 +163,7 @@ protected function authenticate(int|string $identifier, #[SensitiveParameter] ?s
163163
}
164164
}
165165

166-
return LoginStatus::INVALID_CREDENTIALS;
166+
return LoginStatus::InvalidCredentials;
167167
}
168168

169169
/**
@@ -185,12 +185,12 @@ protected function setRememberMeCookie(): void
185185
public function login(null|int|string $identifier, #[SensitiveParameter] ?string $password, bool $remember = false, bool $force = false): LoginStatus
186186
{
187187
if (empty($identifier)) {
188-
return LoginStatus::INVALID_CREDENTIALS;
188+
return LoginStatus::InvalidCredentials;
189189
}
190190

191191
$status = $this->authenticate($identifier, $password, $force);
192192

193-
if ($status === LoginStatus::OK) {
193+
if ($status === LoginStatus::Ok) {
194194
$this->session->regenerateId();
195195

196196
$this->session->regenerateToken();
@@ -218,7 +218,7 @@ public function forceLogin(int|string $identifier, bool $remember = false): Logi
218218
*/
219219
public function basicAuth(bool $clearResponse = false): bool
220220
{
221-
if ($this->isLoggedIn() || $this->login($this->request->getUsername(), $this->request->getPassword()) === LoginStatus::OK) {
221+
if ($this->isLoggedIn() || $this->login($this->request->getUsername(), $this->request->getPassword()) === LoginStatus::Ok) {
222222
return true;
223223
}
224224

tests/unit/gatekeeper/LoginStatusTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@ class LoginStatusTest extends TestCase
1919
*/
2020
public function testLoginStatus(): void
2121
{
22-
$this->assertSame(1, LoginStatus::OK->value);
23-
$this->assertSame(2, LoginStatus::BANNED->value);
24-
$this->assertSame(3, LoginStatus::NOT_ACTIVATED->value);
25-
$this->assertSame(4, LoginStatus::INVALID_CREDENTIALS->value);
26-
$this->assertSame(5, LoginStatus::LOCKED->value);
22+
$this->assertSame(1, LoginStatus::Ok->value);
23+
$this->assertSame(2, LoginStatus::Banned->value);
24+
$this->assertSame(3, LoginStatus::NotActivated->value);
25+
$this->assertSame(4, LoginStatus::InvalidCredentials->value);
26+
$this->assertSame(5, LoginStatus::Locked->value);
2727
}
2828

2929
/**
3030
*
3131
*/
3232
public function testGetCode(): void
3333
{
34-
$this->assertSame(1, LoginStatus::OK->getCode());
35-
$this->assertSame(2, LoginStatus::BANNED->getCode());
36-
$this->assertSame(3, LoginStatus::NOT_ACTIVATED->getCode());
37-
$this->assertSame(4, LoginStatus::INVALID_CREDENTIALS->getCode());
38-
$this->assertSame(5, LoginStatus::LOCKED->getCode());
34+
$this->assertSame(1, LoginStatus::Ok->getCode());
35+
$this->assertSame(2, LoginStatus::Banned->getCode());
36+
$this->assertSame(3, LoginStatus::NotActivated->getCode());
37+
$this->assertSame(4, LoginStatus::InvalidCredentials->getCode());
38+
$this->assertSame(5, LoginStatus::Locked->getCode());
3939
}
4040

4141
/**
4242
*
4343
*/
4444
public function testToBool(): void
4545
{
46-
$this->assertTrue(LoginStatus::OK->toBool());
47-
$this->assertFalse(LoginStatus::BANNED->toBool());
48-
$this->assertFalse(LoginStatus::NOT_ACTIVATED->toBool());
49-
$this->assertFalse(LoginStatus::INVALID_CREDENTIALS->toBool());
50-
$this->assertFalse(LoginStatus::LOCKED->toBool());
46+
$this->assertTrue(LoginStatus::Ok->toBool());
47+
$this->assertFalse(LoginStatus::Banned->toBool());
48+
$this->assertFalse(LoginStatus::NotActivated->toBool());
49+
$this->assertFalse(LoginStatus::InvalidCredentials->toBool());
50+
$this->assertFalse(LoginStatus::Locked->toBool());
5151
}
5252
}

tests/unit/gatekeeper/adapters/SessionTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public function testLoginWithWrongEmail(): void
330330
$status = $adapter->login('foo@example.org', 'password');
331331

332332
$this->assertFalse($status->toBool());
333-
$this->assertEquals(LoginStatus::INVALID_CREDENTIALS, $status);
333+
$this->assertEquals(LoginStatus::InvalidCredentials, $status);
334334
}
335335

336336
/**
@@ -351,7 +351,7 @@ public function testLoginWithWrongPassword(): void
351351
$status = $adapter->login('foo@example.org', 'password');
352352

353353
$this->assertFalse($status->toBool());
354-
$this->assertEquals(LoginStatus::INVALID_CREDENTIALS, $status);
354+
$this->assertEquals(LoginStatus::InvalidCredentials, $status);
355355
}
356356

357357
/**
@@ -374,7 +374,7 @@ public function testLoginForNonActivatedUser(): void
374374
$status = $adapter->login('foo@example.org', 'password');
375375

376376
$this->assertFalse($status->toBool());
377-
$this->assertEquals(LoginStatus::NOT_ACTIVATED, $status);
377+
$this->assertEquals(LoginStatus::NotActivated, $status);
378378
}
379379

380380
/**
@@ -399,7 +399,7 @@ public function testLoginForBannedUser(): void
399399
$status = $adapter->login('foo@example.org', 'password');
400400

401401
$this->assertFalse($status->toBool());
402-
$this->assertEquals(LoginStatus::BANNED, $status);
402+
$this->assertEquals(LoginStatus::Banned, $status);
403403
}
404404

405405
/**
@@ -434,7 +434,7 @@ public function testSuccessfulLogin(): void
434434
$status = $adapter->login('foo@example.org', 'password');
435435

436436
$this->assertTrue($status->toBool());
437-
$this->assertEquals(LoginStatus::OK, $status);
437+
$this->assertEquals(LoginStatus::Ok, $status);
438438
}
439439

440440
/**
@@ -621,7 +621,7 @@ public function testLoginWithWrongPasswordAndThrottling(): void
621621
$status = $adapter->login('foo@example.org', 'password');
622622

623623
$this->assertFalse($status->toBool());
624-
$this->assertEquals(LoginStatus::INVALID_CREDENTIALS, $status);
624+
$this->assertEquals(LoginStatus::InvalidCredentials, $status);
625625
}
626626

627627
/**
@@ -682,7 +682,7 @@ public function testLoginWithLockedAccount(): void
682682
$status = $adapter->login('foo@example.org', 'password');
683683

684684
$this->assertFalse($status->toBool());
685-
$this->assertEquals(LoginStatus::LOCKED, $status);
685+
$this->assertEquals(LoginStatus::Locked, $status);
686686
}
687687

688688
/**
@@ -715,7 +715,7 @@ public function testBasicAuth(): void
715715

716716
$adapter->shouldReceive('isLoggedIn')->once()->andReturn(false);
717717

718-
$adapter->shouldReceive('login')->once()->with(null, null)->andReturn(LoginStatus::INVALID_CREDENTIALS);
718+
$adapter->shouldReceive('login')->once()->with(null, null)->andReturn(LoginStatus::InvalidCredentials);
719719

720720
$this->assertFalse($adapter->basicAuth());
721721
}
@@ -752,7 +752,7 @@ public function testBasicAuthWithClear(): void
752752

753753
$adapter->shouldReceive('isLoggedIn')->once()->andReturn(false);
754754

755-
$adapter->shouldReceive('login')->once()->with(null, null)->andReturn(LoginStatus::INVALID_CREDENTIALS);
755+
$adapter->shouldReceive('login')->once()->with(null, null)->andReturn(LoginStatus::InvalidCredentials);
756756

757757
$this->assertFalse($adapter->basicAuth(true));
758758
}
@@ -790,7 +790,7 @@ public function testBasicAuthLoggingIn(): void
790790

791791
$adapter->shouldReceive('isLoggedIn')->once()->andReturn(false);
792792

793-
$adapter->shouldReceive('login')->once()->with('foo@example.org', 'password')->andReturn(LoginStatus::OK);
793+
$adapter->shouldReceive('login')->once()->with('foo@example.org', 'password')->andReturn(LoginStatus::Ok);
794794

795795
$this->assertTrue($adapter->basicAuth());
796796
}

0 commit comments

Comments
 (0)