|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* SPDX-FileCopyrightText: 2018 Christoph Wurst <[email protected]> |
|
5
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace OCA\TwoFactorGateway\Provider; |
|
9
|
|
|
|
|
10
|
|
|
use JsonSerializable; |
|
11
|
|
|
use OCA\TwoFactorGateway\Service\StateStorage; |
|
12
|
|
|
use OCP\IUser; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @psalm-type TwoFactorGatewayState = array{ |
|
16
|
|
|
* gatewayName: string, |
|
17
|
|
|
* state: int, |
|
18
|
|
|
* phoneNumber: ?string, |
|
19
|
|
|
* } |
|
20
|
|
|
* |
|
21
|
|
|
* @psalm-assert-if-true TwoFactorGatewayState $this |
|
22
|
|
|
*/ |
|
23
|
|
|
class State implements JsonSerializable { |
|
24
|
|
|
|
|
25
|
13 |
|
public function __construct( |
|
26
|
|
|
private IUser $user, |
|
27
|
|
|
private int $state, |
|
28
|
|
|
private string $gatewayName, |
|
29
|
|
|
private ?string $identifier = null, |
|
30
|
|
|
private ?string $verificationCode = null, |
|
31
|
|
|
) { |
|
32
|
13 |
|
} |
|
33
|
|
|
|
|
34
|
5 |
|
public static function verifying(IUser $user, |
|
35
|
|
|
string $gatewayName, |
|
36
|
|
|
string $identifier, |
|
37
|
|
|
string $verificationCode): State { |
|
38
|
5 |
|
return new State( |
|
39
|
5 |
|
$user, |
|
40
|
5 |
|
StateStorage::STATE_VERIFYING, |
|
41
|
5 |
|
$gatewayName, |
|
42
|
5 |
|
$identifier, |
|
43
|
5 |
|
$verificationCode |
|
44
|
5 |
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
public static function disabled(IUser $user, string $gatewayName): State { |
|
48
|
1 |
|
return new State( |
|
49
|
1 |
|
$user, |
|
50
|
1 |
|
StateStorage::STATE_DISABLED, |
|
51
|
1 |
|
$gatewayName |
|
52
|
1 |
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
2 |
|
public function verify(): State { |
|
56
|
2 |
|
return new State( |
|
57
|
2 |
|
$this->user, |
|
58
|
2 |
|
StateStorage::STATE_ENABLED, |
|
59
|
2 |
|
$this->gatewayName, |
|
60
|
2 |
|
$this->identifier, |
|
61
|
2 |
|
$this->verificationCode |
|
62
|
2 |
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
2 |
|
public function getUser(): IUser { |
|
66
|
2 |
|
return $this->user; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
8 |
|
public function getState(): int { |
|
70
|
8 |
|
return $this->state; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
5 |
|
public function getGatewayName(): string { |
|
74
|
5 |
|
return $this->gatewayName; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
5 |
|
public function getIdentifier(): ?string { |
|
78
|
5 |
|
return $this->identifier; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
6 |
|
public function getVerificationCode(): ?string { |
|
82
|
6 |
|
return $this->verificationCode; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
#[\Override] |
|
86
|
|
|
public function jsonSerialize(): mixed { |
|
87
|
|
|
return [ |
|
88
|
|
|
'gatewayName' => $this->gatewayName, |
|
89
|
|
|
'state' => $this->state, |
|
90
|
|
|
'phoneNumber' => $this->identifier, |
|
91
|
|
|
]; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|