1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_auth\Methods; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use ArrayAccess; |
7
|
|
|
use kalanis\kw_accounts\Interfaces\IAuth; |
8
|
|
|
use kalanis\kw_auth\AuthException; |
9
|
|
|
use kalanis\kw_auth\Interfaces\IKauTranslations; |
10
|
|
|
use kalanis\kw_auth\Traits\TLang; |
11
|
|
|
use kalanis\kw_bans\Bans; |
12
|
|
|
use kalanis\kw_bans\BanException; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class BannedInServerKey |
17
|
|
|
* @package kalanis\kw_auth\AuthMethods |
18
|
|
|
* Throws an exception if incoming user is banned |
19
|
|
|
* Just add it before any other method which try to log user in |
20
|
|
|
*/ |
21
|
|
|
class BannedInServerKey extends AMethods |
22
|
|
|
{ |
23
|
|
|
use TLang; |
24
|
|
|
|
25
|
|
|
protected Bans\ABan $libBan; |
26
|
|
|
/** @var ArrayAccess<string, string|int|float> */ |
27
|
|
|
protected ArrayAccess $server; |
28
|
|
|
protected string $credentialKey = ''; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param IAuth|null $authenticator |
32
|
|
|
* @param AMethods|null $nextOne |
33
|
|
|
* @param ArrayAccess<string, string|int|float> $server |
34
|
|
|
* @param Bans\ABan $ban |
35
|
|
|
* @param string $credentialKey |
36
|
|
|
* @param IKauTranslations|null $kauLang |
37
|
|
|
*/ |
38
|
3 |
|
public function __construct( |
39
|
|
|
?IAuth $authenticator, |
40
|
|
|
?AMethods $nextOne, |
41
|
|
|
ArrayAccess $server, |
42
|
|
|
Bans\ABan $ban, |
43
|
|
|
string $credentialKey, |
44
|
|
|
?IKauTranslations $kauLang = null |
45
|
|
|
) { |
46
|
3 |
|
parent::__construct($authenticator, $nextOne); |
47
|
3 |
|
$this->setAuLang($kauLang); |
48
|
3 |
|
$this->server = $server; |
49
|
3 |
|
$this->libBan = $ban; |
50
|
3 |
|
$this->credentialKey = $credentialKey; |
51
|
3 |
|
} |
52
|
|
|
|
53
|
3 |
|
public function process(\ArrayAccess $credentials): void |
54
|
|
|
{ |
55
|
|
|
try { |
56
|
3 |
|
if ($this->server->offsetExists($this->credentialKey)) { |
57
|
3 |
|
$this->libBan->setLookedFor(strval($this->server->offsetGet($this->credentialKey))); |
58
|
2 |
|
if ($this->libBan->isBanned()) { |
59
|
2 |
|
throw new AuthException($this->getAuLang()->kauBanWantedUser(), 401); |
60
|
|
|
} |
61
|
|
|
} |
62
|
2 |
|
} catch (BanException $ex) { |
63
|
1 |
|
throw new AuthException($ex->getMessage(), $ex->getCode(), $ex); |
64
|
|
|
} |
65
|
1 |
|
} |
66
|
|
|
|
67
|
1 |
|
public function remove(): void |
68
|
|
|
{ |
69
|
1 |
|
} |
70
|
|
|
} |
71
|
|
|
|