1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ubiquity\controllers\auth; |
4
|
|
|
|
5
|
|
|
use Ubiquity\utils\flash\FlashMessage; |
6
|
|
|
|
7
|
|
|
trait AuthControllerVariablesTrait { |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Override for modifying the noAccess message |
11
|
|
|
* |
12
|
|
|
* @param FlashMessage $fMessage |
13
|
|
|
*/ |
14
|
1 |
|
protected function noAccessMessage(FlashMessage $fMessage) { |
15
|
1 |
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Override for modifying attempts message |
19
|
|
|
* You can use {_timer} and {_attemptsCount} variables in message content |
20
|
|
|
* |
21
|
|
|
* @param FlashMessage $fMessage |
22
|
|
|
* @param int $attempsCount |
23
|
|
|
*/ |
24
|
|
|
protected function attemptsNumberMessage(FlashMessage $fMessage, $attempsCount) { |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* To override for modifying the bad login message |
29
|
|
|
* |
30
|
|
|
* @param FlashMessage $fMessage |
31
|
|
|
*/ |
32
|
1 |
|
protected function badLoginMessage(FlashMessage $fMessage) { |
33
|
1 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* To override for modifying the logout message |
37
|
|
|
* |
38
|
|
|
* @param FlashMessage $fMessage |
39
|
|
|
*/ |
40
|
1 |
|
protected function terminateMessage(FlashMessage $fMessage) { |
41
|
1 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* To override for modifying the disconnect message |
45
|
|
|
* |
46
|
|
|
* @param FlashMessage $fMessage |
47
|
|
|
*/ |
48
|
|
|
protected function disconnectedMessage(FlashMessage $fMessage) { |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* To override for modifying the account creation message. |
53
|
|
|
* |
54
|
|
|
* @param FlashMessage $fMessage |
55
|
|
|
*/ |
56
|
|
|
protected function createAccountMessage(FlashMessage $fMessage) { |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* To override for modifying the account creation message information. |
61
|
|
|
* |
62
|
|
|
* @param FlashMessage $fMessage |
63
|
|
|
*/ |
64
|
|
|
protected function canCreateAccountMessage(FlashMessage $fMessage) { |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* To override for modifying the error for account creation. |
69
|
|
|
* |
70
|
|
|
* @param FlashMessage $fMessage |
71
|
|
|
*/ |
72
|
|
|
protected function createAccountErrorMessage(FlashMessage $fMessage) { |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* To override for modifying the 2FA panel message. |
77
|
|
|
* @param FlashMessage $fMessage |
78
|
|
|
*/ |
79
|
|
|
protected function twoFAMessage(FlashMessage $fMessage){ |
|
|
|
|
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
/** |
83
|
|
|
* To override |
84
|
|
|
* @param FlashMessage $fMessage |
85
|
|
|
*/ |
86
|
|
|
protected function newTwoFACodeMessage(FlashMessage $fMessage){ |
|
|
|
|
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* To override for modifying the message displayed if the 2FA code is bad. |
92
|
|
|
* @param FlashMessage $fMessage |
93
|
|
|
*/ |
94
|
|
|
protected function twoFABadCodeMessage(FlashMessage $fMessage){ |
|
|
|
|
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* To override |
100
|
|
|
* Displayed when email is valid. |
101
|
|
|
* @param FlashMessage $fMessage |
102
|
|
|
*/ |
103
|
|
|
protected function emailValidationSuccess(FlashMessage $fMessage){ |
|
|
|
|
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* To override |
109
|
|
|
* Displayed when email is invalid or if an error occurs. |
110
|
|
|
* @param FlashMessage $fMessage |
111
|
|
|
*/ |
112
|
|
|
protected function emailValidationError(FlashMessage $fMessage){ |
|
|
|
|
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* To override |
118
|
|
|
* Returns the maximum number of allowed login attempts. |
119
|
|
|
*/ |
120
|
1 |
|
protected function attemptsNumber() { |
121
|
1 |
|
return; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* To override |
126
|
|
|
* Returns the time before trying to connect again |
127
|
|
|
* Effective only if attemptsNumber return a number. |
128
|
|
|
* |
129
|
|
|
* @return number |
130
|
|
|
*/ |
131
|
|
|
protected function attemptsTimeout() { |
132
|
|
|
return 3 * 60; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Override to define if info is displayed as string |
137
|
|
|
* if set to true, use _infoUser var in views to display user info |
138
|
|
|
*/ |
139
|
1 |
|
public function _displayInfoAsString() { |
140
|
1 |
|
return false; |
141
|
|
|
} |
142
|
|
|
|
143
|
1 |
|
public function _checkConnectionTimeout() { |
144
|
1 |
|
return; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function _getLoginInputName() { |
148
|
|
|
return 'email'; |
149
|
|
|
} |
150
|
|
|
|
151
|
1 |
|
protected function loginLabel() { |
152
|
1 |
|
return \ucfirst ( $this->_getLoginInputName () ); |
153
|
|
|
} |
154
|
|
|
|
155
|
1 |
|
public function _getPasswordInputName() { |
156
|
1 |
|
return 'password'; |
157
|
|
|
} |
158
|
|
|
|
159
|
1 |
|
protected function passwordLabel() { |
160
|
1 |
|
return \ucfirst ( $this->_getPasswordInputName () ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
protected function passwordConfLabel() { |
164
|
|
|
return \ucfirst ( $this->_getPasswordInputName () ).' confirmation'; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Returns the body selector (jquery selector used for replacing the content of the page). |
169
|
|
|
* default: body |
170
|
|
|
* |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
1 |
|
public function _getBodySelector() { |
174
|
1 |
|
return 'body'; |
175
|
|
|
} |
176
|
|
|
|
177
|
1 |
|
protected function rememberCaption() { |
178
|
1 |
|
return 'Remember me'; |
179
|
|
|
} |
180
|
|
|
/** |
181
|
|
|
* Returns true for account creation. |
182
|
|
|
* @return boolean |
183
|
|
|
*/ |
184
|
1 |
|
protected function hasAccountCreation():bool{ |
185
|
1 |
|
return false; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* |
190
|
|
|
* @return bool |
191
|
|
|
*/ |
192
|
|
|
protected function hasEmailValidation():bool{ |
193
|
|
|
return false; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* To override |
198
|
|
|
* Returns true for a two factor authentification for this account. |
199
|
|
|
* @param mixed $accountValue |
200
|
|
|
* @return bool |
201
|
|
|
*/ |
202
|
1 |
|
protected function has2FA($accountValue=null):bool{ |
|
|
|
|
203
|
1 |
|
return false; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* |
208
|
|
|
* @return string |
209
|
|
|
*/ |
210
|
|
|
protected function generate2FACode():string{ |
211
|
|
|
return \substr(\md5(\uniqid(\rand(), true)), 6, 6); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
protected function towFACodePrefix():string{ |
215
|
|
|
return 'U-'; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
protected function emailValidationDuration():\DateInterval{ |
219
|
|
|
return new \DateInterval('PT24H'); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.