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