1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_auth\Methods; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_auth\AuthException; |
7
|
|
|
use kalanis\kw_auth\Interfaces\IAuth; |
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
|
|
|
/** @var Bans\ABan */ |
25
|
|
|
protected $libBan = null; |
26
|
|
|
/** @var string */ |
27
|
|
|
protected $credentialKey = ''; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param IAuth|null $authenticator |
31
|
|
|
* @param AMethods|null $nextOne |
32
|
|
|
* @param Bans\ABan $ban |
33
|
|
|
* @param string $credentialKey |
34
|
|
|
* @param IKauTranslations|null $kauLang |
35
|
|
|
*/ |
36
|
3 |
|
public function __construct( |
37
|
|
|
?IAuth $authenticator, |
38
|
|
|
?AMethods $nextOne, |
39
|
|
|
Bans\ABan $ban, |
40
|
|
|
string $credentialKey, |
41
|
|
|
?IKauTranslations $kauLang = null |
42
|
|
|
) { |
43
|
3 |
|
parent::__construct($authenticator, $nextOne); |
44
|
3 |
|
$this->setAuLang($kauLang); |
45
|
3 |
|
$this->libBan = $ban; |
46
|
3 |
|
$this->credentialKey = $credentialKey; |
47
|
3 |
|
} |
48
|
|
|
|
49
|
3 |
|
public function process(\ArrayAccess $credentials): void |
50
|
|
|
{ |
51
|
|
|
try { |
52
|
3 |
|
if ($credentials->offsetExists($this->credentialKey)) { |
53
|
3 |
|
$this->libBan->setLookedFor(strval($credentials->offsetGet($this->credentialKey))); |
54
|
2 |
|
if ($this->libBan->isBanned()) { |
55
|
2 |
|
throw new AuthException($this->getAuLang()->kauBanWantedUser(), 401); |
56
|
|
|
} |
57
|
|
|
} |
58
|
2 |
|
} catch (BanException $ex) { |
59
|
1 |
|
throw new AuthException($ex->getMessage(), $ex->getCode(), $ex); |
60
|
|
|
} |
61
|
1 |
|
} |
62
|
|
|
|
63
|
1 |
|
public function remove(): void |
64
|
|
|
{ |
65
|
1 |
|
} |
66
|
|
|
} |
67
|
|
|
|