Test Failed
Push — master ( f03535...b6ab79 )
by Jean-Christophe
21:01
created

AuthControllerVariablesTrait::passwordConfLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Ubiquity\controllers\auth;
4
5
use Ubiquity\utils\flash\FlashMessage;
6
7
/**
8
 * 
9
 * Ubiquity\controllers\auth$AuthControllerVariablesTrait
10
 * This class is part of Ubiquity
11
 * @author jc
12
 * @version 1.0.0
13
 *
14 1
 */
15 1
trait AuthControllerVariablesTrait {
16
17
	/**
18
	 * Override for modifying the noAccess message
19
	 *
20
	 * @param FlashMessage $fMessage
21
	 */
22
	protected function noAccessMessage(FlashMessage $fMessage) {
23
	}
24
25
	/**
26
	 * Override for modifying attempts message
27
	 * You can use {_timer} and {_attemptsCount} variables in message content
28
	 *
29
	 * @param FlashMessage $fMessage
30
	 * @param int $attempsCount
31
	 */
32 1
	protected function attemptsNumberMessage(FlashMessage $fMessage, $attempsCount) {
33 1
	}
34
35
	/**
36
	 * To override for modifying the bad login message
37
	 *
38
	 * @param FlashMessage $fMessage
39
	 */
40 1
	protected function badLoginMessage(FlashMessage $fMessage) {
41 1
	}
42
43
	/**
44
	 * To override for modifying the logout message
45
	 *
46
	 * @param FlashMessage $fMessage
47
	 */
48
	protected function terminateMessage(FlashMessage $fMessage) {
49
	}
50
51
	/**
52
	 * To override for modifying the disconnect message
53
	 *
54
	 * @param FlashMessage $fMessage
55
	 */
56
	protected function disconnectedMessage(FlashMessage $fMessage) {
57
	}
58
	
59
	/**
60
	 * To override for modifying the account creation message.
61
	 *
62
	 * @param FlashMessage $fMessage
63
	 */
64
	protected function createAccountMessage(FlashMessage $fMessage) {
65
	}
66
	
67
	/**
68
	 * To override for modifying the account creation message information.
69
	 *
70
	 * @param FlashMessage $fMessage
71
	 */
72
	protected function canCreateAccountMessage(FlashMessage $fMessage) {
73
	}
74
	
75
	/**
76
	 * To override for modifying the error for account creation.
77
	 *
78
	 * @param FlashMessage $fMessage
79
	 */
80
	protected function createAccountErrorMessage(FlashMessage $fMessage) {
81
	}
82
	
83
	/**
84
	 * To override for modifying the 2FA panel message.
85
	 * @param FlashMessage $fMessage
86
	 */
87
	protected function twoFAMessage(FlashMessage $fMessage){
88
		
89
	}
90
	/**
91
	 * To override
92
	 * @param FlashMessage $fMessage
93
	 */
94
	protected function newTwoFACodeMessage(FlashMessage $fMessage){
95
		
96
	}
97
	
98
	/**
99
	 * To override for modifying the message displayed if the 2FA code is bad.
100
	 * @param FlashMessage $fMessage
101
	 */
102
	protected function twoFABadCodeMessage(FlashMessage $fMessage){
103
		
104
	}
105
	
106
	/**
107
	 * To override 
108
	 * Displayed when email is valid.
109
	 * @param FlashMessage $fMessage
110
	 */
111
	protected function emailValidationSuccess(FlashMessage $fMessage){
112
		
113
	}
114
	
115
	/**
116
	 * To override
117
	 * Displayed when email is invalid or if an error occurs.
118
	 * @param FlashMessage $fMessage
119
	 */
120 1
	protected function emailValidationError(FlashMessage $fMessage){
121 1
		
122
	}
123
124
	/**
125
	 * To override
126
	 * Displayed when an account recovery operation is initiated.
127
	 * @param FlashMessage $fMessage
128
	 */
129
	protected function recoveryInitMessage(FlashMessage $fMessage){
130
131
	}
132
133
	/**
134
	 * To override
135
	 * Displayed when email is sent for a recovery account operation.
136
	 * @param FlashMessage $fMessage
137
	 */
138
	protected function recoveryEmailSendMessage(FlashMessage $fMessage){
139 1
140 1
	}
141
142
	/**
143 1
	 * To override
144 1
	 * Displayed when email is not associated with an existing account.
145
	 * @param FlashMessage $fMessage
146
	 */
147
	protected function recoveryEmailErrorMessage(FlashMessage $fMessage){
148
149
	}
150
151 1
	/**
152 1
	 * To override
153
	 * Displayed when a new password is set with recovery account.
154
	 * @param FlashMessage $fMessage
155 1
	 */
156 1
	protected function resetPasswordSuccessMessage(FlashMessage $fMessage){
157
158
	}
159 1
160 1
	/**
161
	 * To override
162
	 * Displayed when an error occurs when a new password is set with recovery account.
163
	 * @param FlashMessage $fMessage
164
	 */
165
	protected function resetPasswordErrorMessage(FlashMessage $fMessage){
166
167
	}
168
169
	/**
170
	 * To override
171
	 * Displayed when the account recovery link is valid.
172
	 * @param FlashMessage $fMessage
173 1
	 */
174 1
	protected function emailAccountRecoverySuccess(FlashMessage $fMessage){
175
176
	}
177 1
178 1
	/**
179
	 * To override
180
	 * Displayed when the account recovery link is not valid.
181
	 * @param FlashMessage $fMessage
182
	 */
183
	protected function emailAccountRecoveryError(FlashMessage $fMessage){
184 1
185 1
	}
186
187
	/**
188
	 * To override
189
	 * Returns the maximum number of allowed login attempts.
190
	 */
191
	protected function attemptsNumber() {
192
		return;
193
	}
194
195
	/**
196
	 * To override
197
	 * Returns the time before trying to connect again
198
	 * Effective only if attemptsNumber return a number.
199
	 *
200
	 * @return number
201
	 */
202 1
	protected function attemptsTimeout() {
203 1
		return 3 * 60;
204
	}
205
206
	/**
207
	 * Override to define if user info is displayed as string.
208
	 * If set to true, use {{ _infoUser| raw }} in views to display user info.
209
	 * Remember to use $this->jquery->renderView instead of $this->loadView for the javascript generation.
210
	 */
211
	public function _displayInfoAsString() {
212
		return false;
213
	}
214
215
	public function _checkConnectionTimeout() {
216
		return;
217
	}
218
219
	public function _getLoginInputName() {
220
		return 'email';
221
	}
222
223
	protected function loginLabel() {
224
		return \ucfirst ( $this->_getLoginInputName () );
225
	}
226
227
	public function _getPasswordInputName() {
228
		return 'password';
229
	}
230
231
	protected function passwordLabel() {
232
		return \ucfirst ( $this->_getPasswordInputName () );
233
	}
234
	
235
	protected function passwordConfLabel() {
236
		return \ucfirst ( $this->_getPasswordInputName () ).' confirmation';
237
	}
238
239
	/**
240
	 * Returns the recovery account link caption.
241
	 * Default : Forgot your password?
242
	 * @return string
243
	 */
244
	protected function recoveryAccountCaption():string{
245
		return 'Forgot your password?';
246
	}
247
248
	/**
249
	 * Returns the body selector (jquery selector used for replacing the content of the page).
250
	 * default: main .container
251
	 *
252
	 * @return string
253
	 */
254
	public function _getBodySelector():string {
255
		return 'main .container';
256
	}
257
258
	protected function rememberCaption():string {
259
		return 'Remember me';
260
	}
261
	/**
262
	 * Returns true for account creation.
263
	 * @return boolean
264
	 */
265
	protected function hasAccountCreation():bool{
266
		return false;
267
	}
268
	
269
	/**
270
	 * 
271
	 * @return bool
272
	 */
273
	protected function hasEmailValidation():bool{
274
		return false;
275
	}
276
277
	/**
278
	 * @return bool
279
	 */
280
	protected function hasAccountRecovery():bool{
281
		return false;
282
	}
283
	
284
	/**
285
	 * To override
286
	 * Returns true for a two factor authentification for this account.
287
	 * @param mixed $accountValue
288
	 * @return bool
289
	 */
290
	protected function has2FA($accountValue=null):bool{
291
		return false;
292
	}
293
294
	/**
295
	 * To override
296
	 * Returns the default size for generated tokens.
297
	 * @return int
298
	 */
299
	protected function getTokenSize():int{
300
		return 6;
301
	}
302
303
	/**
304
	 * Generates a new random 2FA code.
305
	 * You have to override this basic implementation.
306
	 * @return string
307
	 * @throws \Exception
308
	 */
309
	protected function generate2FACode():string{
310
		return \bin2hex ( \random_bytes ($this->getTokenSize()));
311
	}
312
313
	/**
314
	 * Returns the code prefix (which should not be entered by the user). 
315
	 * @return string
316
	 */
317
	protected function towFACodePrefix():string{
318
		return 'U-';
319
	}
320
321
	/**
322
	 * Returns the default validity duration of a mail validation link.
323
	 * @return \DateInterval
324
	 */
325
	protected function emailValidationDuration():\DateInterval{
326
		return new \DateInterval('PT24H');
327
	}
328
329
	/**
330
	 * Returns the default validity duration of a generated 2FA code.
331
	 * @return \DateInterval
332
	 */
333
	protected function twoFACodeDuration():\DateInterval{
334
		return new \DateInterval('PT5M');
335
	}
336
337
	/**
338
	 * @return bool
339
	 */
340
	public function hasRecoveryAccount():bool{
341
		return false;
342
	}
343
	/**
344
	 * Returns the default validity duration for an email account recovery.
345
	 * @return \DateInterval
346
	 */
347
	protected function accountRecoveryDuration():\DateInterval{
348
		return new \DateInterval('PT30M');
349
	}
350
	
351
}
352
353