|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LmcUser\Form; |
|
4
|
|
|
|
|
5
|
|
|
use Laminas\Form\Element; |
|
6
|
|
|
use LmcUser\Options\AuthenticationOptionsInterface; |
|
7
|
|
|
|
|
8
|
|
|
class Login extends ProvidesEventsForm |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var AuthenticationOptionsInterface |
|
12
|
|
|
*/ |
|
13
|
|
|
protected $authOptions; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct($name, AuthenticationOptionsInterface $options) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->setAuthenticationOptions($options); |
|
18
|
|
|
|
|
19
|
|
|
parent::__construct($name); |
|
20
|
|
|
|
|
21
|
|
|
$this->add( |
|
22
|
|
|
array( |
|
23
|
|
|
'name' => 'identity', |
|
24
|
|
|
'options' => array( |
|
25
|
|
|
'label' => '', |
|
26
|
|
|
), |
|
27
|
|
|
'attributes' => array( |
|
28
|
|
|
'type' => 'text' |
|
29
|
|
|
), |
|
30
|
|
|
) |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
$emailElement = $this->get('identity'); |
|
34
|
|
|
$label = $emailElement->getLabel('label'); |
|
|
|
|
|
|
35
|
|
|
// @TODO: make translation-friendly |
|
36
|
|
|
foreach ($this->getAuthenticationOptions()->getAuthIdentityFields() as $mode) { |
|
37
|
|
|
$label = (!empty($label) ? $label . ' or ' : '') . ucfirst($mode); |
|
38
|
|
|
} |
|
39
|
|
|
$emailElement->setLabel($label); |
|
40
|
|
|
// |
|
41
|
|
|
$this->add( |
|
42
|
|
|
array( |
|
43
|
|
|
'name' => 'credential', |
|
44
|
|
|
'type' => 'password', |
|
45
|
|
|
'options' => array( |
|
46
|
|
|
'label' => 'Password', |
|
47
|
|
|
), |
|
48
|
|
|
'attributes' => array( |
|
49
|
|
|
'type' => 'password', |
|
50
|
|
|
), |
|
51
|
|
|
) |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
if ($this->getAuthenticationOptions()->getUseLoginFormCsrf()) { |
|
55
|
|
|
$this->add([ |
|
56
|
|
|
'type' => '\Laminas\Form\Element\Csrf', |
|
57
|
|
|
'name' => 'security', |
|
58
|
|
|
'options' => [ |
|
59
|
|
|
'csrf_options' => [ |
|
60
|
|
|
'timeout' => $this->getAuthenticationOptions()->getLoginFormTimeout() |
|
61
|
|
|
] |
|
62
|
|
|
] |
|
63
|
|
|
]); |
|
64
|
|
|
} |
|
65
|
|
|
if ($this->getAuthenticationOptions()->getUseLoginFormCaptcha()) { |
|
66
|
|
|
$this->add([ |
|
67
|
|
|
'name' => 'captcha', |
|
68
|
|
|
'type' => 'Laminas\Form\Element\Captcha', |
|
69
|
|
|
'options' => [ |
|
70
|
|
|
'label' => 'Human check', |
|
71
|
|
|
'captcha' => $this->getAuthenticationOptions()->getFormCaptchaOptions(), |
|
72
|
|
|
] |
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$submitElement = new Element\Button('submit'); |
|
77
|
|
|
$submitElement |
|
78
|
|
|
->setLabel('Sign In') |
|
79
|
|
|
->setAttributes( |
|
80
|
|
|
array( |
|
81
|
|
|
'type' => 'submit', |
|
82
|
|
|
) |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
$this->add( |
|
86
|
|
|
$submitElement, |
|
87
|
|
|
array( |
|
88
|
|
|
'priority' => -100, |
|
89
|
|
|
) |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Set Authentication-related Options |
|
95
|
|
|
* |
|
96
|
|
|
* @param AuthenticationOptionsInterface $authOptions |
|
97
|
|
|
* @return Login |
|
98
|
|
|
*/ |
|
99
|
|
|
public function setAuthenticationOptions(AuthenticationOptionsInterface $authOptions) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->authOptions = $authOptions; |
|
102
|
|
|
|
|
103
|
|
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get Authentication-related Options |
|
108
|
|
|
* |
|
109
|
|
|
* @return AuthenticationOptionsInterface |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getAuthenticationOptions() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->authOptions; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.