1
|
|
|
<?php |
2
|
|
|
/****************************************************************************** |
3
|
|
|
* Wikipedia Account Creation Assistance tool * |
4
|
|
|
* * |
5
|
|
|
* All code in this file is released into the public domain by the ACC * |
6
|
|
|
* Development Team. Please see team.json for a list of contributors. * |
7
|
|
|
******************************************************************************/ |
8
|
|
|
|
9
|
|
|
namespace Waca\Security\CredentialProviders; |
10
|
|
|
|
11
|
|
|
use Waca\DataObjects\Credential; |
12
|
|
|
use Waca\DataObjects\User; |
13
|
|
|
use Waca\PdoDatabase; |
14
|
|
|
use Waca\SiteConfiguration; |
15
|
|
|
|
16
|
|
|
abstract class CredentialProviderBase implements ICredentialProvider |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var PdoDatabase |
20
|
|
|
*/ |
21
|
|
|
private $database; |
22
|
|
|
/** |
23
|
|
|
* @var SiteConfiguration |
24
|
|
|
*/ |
25
|
|
|
private $configuration; |
26
|
|
|
/** @var string */ |
27
|
|
|
private $type; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* CredentialProviderBase constructor. |
31
|
|
|
* |
32
|
|
|
* @param PdoDatabase $database |
33
|
|
|
* @param SiteConfiguration $configuration |
34
|
|
|
* @param string $type |
35
|
|
|
*/ |
36
|
|
|
public function __construct(PdoDatabase $database, SiteConfiguration $configuration, $type) |
37
|
|
|
{ |
38
|
|
|
$this->database = $database; |
39
|
|
|
$this->configuration = $configuration; |
40
|
|
|
$this->type = $type; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param int $userId |
45
|
|
|
* |
46
|
|
|
* @return Credential |
|
|
|
|
47
|
|
|
*/ |
48
|
|
|
protected function getCredentialData($userId) |
49
|
|
|
{ |
50
|
|
|
$sql = 'SELECT * FROM credential WHERE type = :t AND user = :u AND disabled = 0'; |
51
|
|
|
|
52
|
|
|
$statement = $this->database->prepare($sql); |
53
|
|
|
$statement->execute(array(':u' => $userId, ':t' => $this->type)); |
54
|
|
|
|
55
|
|
|
/** @var Credential $obj */ |
56
|
|
|
$obj = $statement->fetchObject(Credential::class); |
57
|
|
|
|
58
|
|
|
if ($obj === false) { |
59
|
|
|
return null; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$obj->setDatabase($this->database); |
63
|
|
|
|
64
|
|
|
$statement->closeCursor(); |
65
|
|
|
|
66
|
|
|
return $obj; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return PdoDatabase |
71
|
|
|
*/ |
72
|
|
|
public function getDatabase() |
73
|
|
|
{ |
74
|
|
|
return $this->database; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return SiteConfiguration |
79
|
|
|
*/ |
80
|
|
|
public function getConfiguration() |
81
|
|
|
{ |
82
|
|
|
return $this->configuration; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param User $user |
87
|
|
|
* |
88
|
|
|
* @return Credential |
89
|
|
|
*/ |
90
|
|
|
protected function createNewCredential(User $user) |
91
|
|
|
{ |
92
|
|
|
$credential = new Credential(); |
93
|
|
|
$credential->setDatabase($this->getDatabase()); |
94
|
|
|
$credential->setUserId($user->getId()); |
95
|
|
|
$credential->setType($this->type); |
96
|
|
|
|
97
|
|
|
return $credential; |
98
|
|
|
} |
99
|
|
|
} |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.